mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-09-17 14:21:14 +00:00
[ACA-19] Toggle join request - library action (#800)
* [ACA-19] join/cancel join library actions * [ACA-19] show the info drawer * [ACA-19] custom icon for join library * [ACA-19] css to 'see' custom icon for extension * [ACA-19] reformat with prettier * [ACA-19] better role display * [ACA-19] simplify cancel request rule * [ACA-19] refactor and use toggle join/cancel join component & directive * [ACA-19] reformat with Prettier * [ACA-19] fix title for svgIcon * [ACA-19] fix translation * [ACA-19] unit test
This commit is contained in:
committed by
Denys Vuika
parent
7734844893
commit
49e80ddce1
@@ -0,0 +1,131 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { ToggleJoinLibraryComponent } from './toggle-join-library.component';
|
||||
import { of } from 'rxjs';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-core';
|
||||
import { LibraryMembershipDirective } from '../../../directives/library-membership.directive';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import {
|
||||
SnackbarErrorAction,
|
||||
SnackbarInfoAction
|
||||
} from '../../../store/actions/snackbar.actions';
|
||||
import { AppTestingModule } from '../../../testing/app-testing.module';
|
||||
import { ContentManagementService } from '../../../services/content-management.service';
|
||||
|
||||
describe('ToggleJoinLibraryComponent', () => {
|
||||
let component: ToggleJoinLibraryComponent;
|
||||
let fixture: ComponentFixture<ToggleJoinLibraryComponent>;
|
||||
let alfrescoApi: AlfrescoApiService;
|
||||
let contentManagementService: ContentManagementService;
|
||||
let entry;
|
||||
|
||||
const storeMock = {
|
||||
select: () => of({ library: { entry, isLibrary: true } }),
|
||||
dispatch: jasmine.createSpy('dispatch')
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
entry = {
|
||||
id: 'lib-id',
|
||||
joinRequested: true,
|
||||
title: 'test',
|
||||
visibility: 'MODERATED'
|
||||
};
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [AppTestingModule],
|
||||
declarations: [ToggleJoinLibraryComponent, LibraryMembershipDirective],
|
||||
providers: [
|
||||
{ provide: Store, useValue: storeMock },
|
||||
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(ToggleJoinLibraryComponent);
|
||||
component = fixture.componentInstance;
|
||||
alfrescoApi = TestBed.get(AlfrescoApiService);
|
||||
contentManagementService = TestBed.get(ContentManagementService);
|
||||
|
||||
spyOn(alfrescoApi.peopleApi, 'getSiteMembershipRequest').and.stub();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
storeMock.dispatch.calls.reset();
|
||||
});
|
||||
|
||||
it('should get Store selection entry on initialization', done => {
|
||||
component.selection$.subscribe(selection => {
|
||||
expect(selection.library.entry).toEqual(entry);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should dispatch `SnackbarErrorAction` action on error', () => {
|
||||
const event = { event: {}, i18nKey: 'ERROR_i18nKey' };
|
||||
component.onErrorEvent(event);
|
||||
|
||||
expect(storeMock.dispatch).toHaveBeenCalledWith(
|
||||
new SnackbarErrorAction(event.i18nKey)
|
||||
);
|
||||
});
|
||||
|
||||
it('should dispatch `SnackbarInfoAction` action on onToggleEvent', () => {
|
||||
const event = { shouldReload: true, i18nKey: 'SOME_i18nKey' };
|
||||
component.onToggleEvent(event);
|
||||
|
||||
expect(storeMock.dispatch).toHaveBeenCalledWith(
|
||||
new SnackbarInfoAction(event.i18nKey)
|
||||
);
|
||||
});
|
||||
|
||||
it('should call libraryJoined.next on contentManagementService onToggleEvent', done => {
|
||||
spyOn(contentManagementService.libraryJoined, 'next').and.callThrough();
|
||||
|
||||
contentManagementService.libraryJoined.subscribe(() => {
|
||||
expect(contentManagementService.libraryJoined.next).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
const event = { shouldReload: true };
|
||||
component.onToggleEvent(event);
|
||||
});
|
||||
|
||||
it('should call joinLibraryToggle.next on contentManagementService onToggleEvent', done => {
|
||||
spyOn(contentManagementService.joinLibraryToggle, 'next').and.callThrough();
|
||||
|
||||
contentManagementService.joinLibraryToggle.subscribe(() => {
|
||||
expect(
|
||||
contentManagementService.joinLibraryToggle.next
|
||||
).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
const event = { shouldReload: false };
|
||||
component.onToggleEvent(event);
|
||||
});
|
||||
});
|
@@ -0,0 +1,88 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Component, ViewEncapsulation } from '@angular/core';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { AppStore } from '../../../store/states';
|
||||
import { appSelection } from '../../../store/selectors/app.selectors';
|
||||
import { Observable } from 'rxjs';
|
||||
import { SelectionState } from '@alfresco/adf-extensions';
|
||||
import { ContentManagementService } from '../../../services/content-management.service';
|
||||
import {
|
||||
SnackbarErrorAction,
|
||||
SnackbarInfoAction
|
||||
} from '../../../store/actions/snackbar.actions';
|
||||
|
||||
@Component({
|
||||
selector: 'app-toggle-join-library',
|
||||
template: `
|
||||
<button
|
||||
mat-icon-button
|
||||
[color]="'primary'"
|
||||
#membership="libraryMembership"
|
||||
(toggle)="onToggleEvent($event)"
|
||||
(error)="onErrorEvent($event)"
|
||||
[acaLibraryMembership]="(selection$ | async).library"
|
||||
[attr.title]="
|
||||
(membership.isJoinRequested | async)
|
||||
? ('APP.ACTIONS.CANCEL_JOIN' | translate)
|
||||
: ('APP.ACTIONS.JOIN' | translate)
|
||||
"
|
||||
>
|
||||
<mat-icon *ngIf="(membership.isJoinRequested | async)">cancel</mat-icon>
|
||||
<mat-icon
|
||||
*ngIf="!(membership.isJoinRequested | async)"
|
||||
svgIcon="join_library"
|
||||
style="pointer-events: none;"
|
||||
></mat-icon>
|
||||
</button>
|
||||
`,
|
||||
encapsulation: ViewEncapsulation.None,
|
||||
host: { class: 'app-toggle-join-library' }
|
||||
})
|
||||
export class ToggleJoinLibraryComponent {
|
||||
selection$: Observable<SelectionState>;
|
||||
|
||||
constructor(
|
||||
private store: Store<AppStore>,
|
||||
private content: ContentManagementService
|
||||
) {
|
||||
this.selection$ = this.store.select(appSelection);
|
||||
}
|
||||
|
||||
onToggleEvent(event) {
|
||||
this.store.dispatch(new SnackbarInfoAction(event.i18nKey));
|
||||
|
||||
if (event.shouldReload) {
|
||||
this.content.libraryJoined.next();
|
||||
} else {
|
||||
this.content.joinLibraryToggle.next();
|
||||
}
|
||||
}
|
||||
|
||||
onErrorEvent(event) {
|
||||
this.store.dispatch(new SnackbarErrorAction(event.i18nKey));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user