diff --git a/projects/aca-shared/rules/src/app.rules.spec.ts b/projects/aca-shared/rules/src/app.rules.spec.ts
index 3306e147e..fc307bacd 100644
--- a/projects/aca-shared/rules/src/app.rules.spec.ts
+++ b/projects/aca-shared/rules/src/app.rules.spec.ts
@@ -439,4 +439,40 @@ describe('app.evaluators', () => {
expect(app.isShared(context)).toBe(true);
});
});
+
+ describe('canShowLanguagePicker', () => {
+ it('should return true when property is true', () => {
+ const context: any = {
+ languagePicker: true
+ };
+
+ expect(app.canShowLanguagePicker(context)).toBe(true);
+ });
+
+ it('should return false when property is false', () => {
+ const context: any = {
+ languagePicker: false
+ };
+
+ expect(app.canShowLanguagePicker(context)).toBe(false);
+ });
+ });
+
+ describe('canShowLogout', () => {
+ it('should return false when `withCredentials` property is true', () => {
+ const context: any = {
+ withCredentials: true
+ };
+
+ expect(app.canShowLogout(context)).toBe(false);
+ });
+
+ it('should return true when `withCredentials` property is false', () => {
+ const context: any = {
+ withCredentials: false
+ };
+
+ expect(app.canShowLanguagePicker(context)).toBe(true);
+ });
+ });
});
diff --git a/src/app/components/common/logout/logout.component.spec.ts b/src/app/components/common/logout/logout.component.spec.ts
new file mode 100644
index 000000000..f5bbb839c
--- /dev/null
+++ b/src/app/components/common/logout/logout.component.spec.ts
@@ -0,0 +1,70 @@
+/*!
+ * @license
+ * Alfresco Example Content Application
+ *
+ * Copyright (C) 2005 - 2019 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 .
+ */
+
+import { TestBed, ComponentFixture } from '@angular/core/testing';
+import {
+ TranslateModule,
+ TranslateLoader,
+ TranslateFakeLoader
+} from '@ngx-translate/core';
+import { LogoutComponent } from './logout.component';
+import { Store } from '@ngrx/store';
+import { SetSelectedNodesAction } from '@alfresco/aca-shared/store';
+
+describe('LogoutComponent', () => {
+ let fixture: ComponentFixture;
+ let component: LogoutComponent;
+ let store;
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({
+ imports: [
+ TranslateModule.forRoot({
+ loader: { provide: TranslateLoader, useClass: TranslateFakeLoader }
+ })
+ ],
+ declarations: [LogoutComponent],
+ providers: [
+ {
+ provide: Store,
+ useValue: {
+ dispatch: jasmine.createSpy('dispatch')
+ }
+ }
+ ]
+ });
+
+ store = TestBed.get(Store);
+ fixture = TestBed.createComponent(LogoutComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should reset selected nodes from store', () => {
+ component.onLogoutEvent();
+
+ expect(store.dispatch).toHaveBeenCalledWith(new SetSelectedNodesAction([]));
+ });
+});
diff --git a/src/app/components/current-user/current-user.component.spec.ts b/src/app/components/current-user/current-user.component.spec.ts
index cfb33145b..baef2170d 100644
--- a/src/app/components/current-user/current-user.component.spec.ts
+++ b/src/app/components/current-user/current-user.component.spec.ts
@@ -24,9 +24,91 @@
*/
import { CurrentUserComponent } from './current-user.component';
+import { TestBed, ComponentFixture } from '@angular/core/testing';
+import { AppTestingModule } from '../../testing/app-testing.module';
+import { AppExtensionService } from '../../extensions/extension.service';
+import { NO_ERRORS_SCHEMA } from '@angular/core';
+import { Store } from '@ngrx/store';
+import {
+ AppState,
+ SetUserProfileAction,
+ SetLanguagePickerAction
+} from '@alfresco/aca-shared/store';
describe('CurrentUserComponent', () => {
- it('should be defined', () => {
- expect(CurrentUserComponent).toBeDefined();
+ let fixture: ComponentFixture;
+ let component: CurrentUserComponent;
+ let appExtensionService;
+ let store: Store;
+ const person = {
+ entry: {
+ id: 'user-id',
+ firstName: 'Test',
+ lastName: 'User',
+ email: 'user@email.com',
+ enabled: true,
+ isAdmin: false,
+ userName: 'user-name'
+ }
+ };
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({
+ imports: [AppTestingModule],
+ declarations: [CurrentUserComponent],
+ providers: [AppExtensionService],
+ schemas: [NO_ERRORS_SCHEMA]
+ });
+
+ fixture = TestBed.createComponent(CurrentUserComponent);
+ appExtensionService = TestBed.get(AppExtensionService);
+ store = TestBed.get(Store);
+ component = fixture.componentInstance;
+ });
+
+ it('should get profile data', done => {
+ const expectedProfile = {
+ firstName: 'Test',
+ lastName: 'User',
+ userName: 'Test User',
+ isAdmin: true,
+ id: 'user-id',
+ groups: []
+ };
+
+ fixture.detectChanges();
+
+ store.dispatch(
+ new SetUserProfileAction({ person: person.entry, groups: [] })
+ );
+
+ component.profile$.subscribe((profile: any) => {
+ expect(profile).toEqual(jasmine.objectContaining(expectedProfile));
+ done();
+ });
+ });
+
+ it('should set language picker state', done => {
+ fixture.detectChanges();
+
+ store.dispatch(new SetLanguagePickerAction(true));
+
+ component.languagePicker$.subscribe((languagePicker: boolean) => {
+ expect(languagePicker).toBe(true);
+ done();
+ });
+ });
+
+ it('should set menu actions', () => {
+ const actions = [
+ {
+ id: 'action-id'
+ }
+ ];
+ spyOn(appExtensionService, 'getUserActions').and.returnValue(actions);
+
+ fixture.detectChanges();
+
+ expect(component.actions).toBe(actions);
});
});
diff --git a/src/app/components/current-user/user-menu-item.component.spec.ts b/src/app/components/current-user/user-menu-item.component.spec.ts
new file mode 100644
index 000000000..7605d3c71
--- /dev/null
+++ b/src/app/components/current-user/user-menu-item.component.spec.ts
@@ -0,0 +1,126 @@
+/*!
+ * @license
+ * Alfresco Example Content Application
+ *
+ * Copyright (C) 2005 - 2019 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 .
+ */
+
+import { TestBed, ComponentFixture } from '@angular/core/testing';
+import { AppTestingModule } from '../../testing/app-testing.module';
+import { AppExtensionService } from '../../extensions/extension.service';
+import { UserMenuItemComponent } from './user-menu-item.component';
+import {
+ TranslateModule,
+ TranslateLoader,
+ TranslateFakeLoader
+} from '@ngx-translate/core';
+import { NO_ERRORS_SCHEMA } from '@angular/core';
+import { ContentActionRef } from '@alfresco/adf-extensions';
+
+describe('UserMenuItemComponent', () => {
+ let fixture: ComponentFixture;
+ let component: UserMenuItemComponent;
+ let appExtensionService;
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({
+ imports: [
+ AppTestingModule,
+ TranslateModule.forRoot({
+ loader: { provide: TranslateLoader, useClass: TranslateFakeLoader }
+ })
+ ],
+ declarations: [UserMenuItemComponent],
+ providers: [AppExtensionService],
+ schemas: [NO_ERRORS_SCHEMA]
+ });
+
+ fixture = TestBed.createComponent(UserMenuItemComponent);
+ appExtensionService = TestBed.get(AppExtensionService);
+ component = fixture.componentInstance;
+ });
+
+ afterEach(() => {
+ fixture.destroy();
+ });
+
+ it('should render button action', () => {
+ component.actionRef = {
+ id: 'action-button',
+ title: 'Test Button',
+ actions: {
+ click: 'TEST_EVENT'
+ }
+ } as ContentActionRef;
+ fixture.detectChanges();
+
+ const buttonElement = fixture.nativeElement.querySelector('#action-button');
+ expect(buttonElement).not.toBe(null);
+ });
+
+ it('should render menu action', () => {
+ component.actionRef = {
+ type: 'menu',
+ id: 'action-menu',
+ title: 'Test Button',
+ actions: {
+ click: 'TEST_EVENT'
+ }
+ } as ContentActionRef;
+ fixture.detectChanges();
+
+ const menuElement = fixture.nativeElement.querySelector('#action-menu');
+ expect(menuElement).not.toBe(null);
+ });
+
+ it('should render custom action', () => {
+ component.actionRef = {
+ type: 'custom',
+ id: 'action-custom',
+ component: 'custom-component'
+ } as ContentActionRef;
+ fixture.detectChanges();
+
+ const componentElement = fixture.nativeElement.querySelector(
+ '#custom-component'
+ );
+ expect(componentElement).not.toBe(null);
+ });
+
+ it('should run defined action', () => {
+ spyOn(appExtensionService, 'runActionById');
+
+ component.actionRef = {
+ id: 'action-button',
+ title: 'Test Button',
+ actions: {
+ click: 'TEST_EVENT'
+ }
+ } as ContentActionRef;
+ fixture.detectChanges();
+
+ const buttonElement = fixture.nativeElement.querySelector('#action-button');
+ buttonElement.dispatchEvent(new MouseEvent('click'));
+ expect(appExtensionService.runActionById).toHaveBeenCalledWith(
+ 'TEST_EVENT'
+ );
+ });
+});
diff --git a/src/app/extensions/extension.service.spec.ts b/src/app/extensions/extension.service.spec.ts
index 33748a2dc..fabafb767 100644
--- a/src/app/extensions/extension.service.spec.ts
+++ b/src/app/extensions/extension.service.spec.ts
@@ -39,18 +39,21 @@ import {
ExtensionConfig,
ComponentRegisterService
} from '@alfresco/adf-extensions';
+import { AppConfigService } from '@alfresco/adf-core';
describe('AppExtensionService', () => {
let service: AppExtensionService;
let store: Store;
let extensions: ExtensionService;
let components: ComponentRegisterService;
+ let appConfigService: AppConfigService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule]
});
+ appConfigService = TestBed.get(AppConfigService);
store = TestBed.get(Store);
service = TestBed.get(AppExtensionService);
extensions = TestBed.get(ExtensionService);
@@ -784,4 +787,114 @@ describe('AppExtensionService', () => {
expect(service.getSharedLinkViewerToolbarActions()).toEqual(actions);
});
});
+
+ describe('withCredentials', () => {
+ it('should set `withCredentials` to true from app configuration', () => {
+ appConfigService.config = {
+ auth: { withCredentials: true }
+ };
+ applyConfig({
+ $id: 'test',
+ $name: 'test',
+ $version: '1.0.0',
+ $license: 'MIT',
+ $vendor: 'Good company',
+ $runtime: '1.5.0'
+ });
+
+ expect(service.withCredentials).toBe(true);
+ });
+
+ it('should set `withCredentials` to false from app configuration', () => {
+ appConfigService.config = {
+ auth: { withCredentials: false }
+ };
+ applyConfig({
+ $id: 'test',
+ $name: 'test',
+ $version: '1.0.0',
+ $license: 'MIT',
+ $vendor: 'Good company',
+ $runtime: '1.5.0'
+ });
+
+ expect(service.withCredentials).toBe(false);
+ });
+
+ it('should set `withCredentials` to false as default value if no app configuration', () => {
+ appConfigService.config = {};
+ applyConfig({
+ $id: 'test',
+ $name: 'test',
+ $version: '1.0.0',
+ $license: 'MIT',
+ $vendor: 'Good company',
+ $runtime: '1.5.0'
+ });
+
+ expect(service.withCredentials).toBe(false);
+ });
+ });
+
+ describe('userActions', () => {
+ it('should load user actions from the config', () => {
+ applyConfig({
+ $id: 'test',
+ $name: 'test',
+ $version: '1.0.0',
+ $license: 'MIT',
+ $vendor: 'Good company',
+ $runtime: '1.5.0',
+ features: {
+ userActions: [
+ {
+ id: 'aca:toolbar/separator-1',
+ order: 1,
+ type: ContentActionType.separator,
+ title: 'action1'
+ },
+ {
+ id: 'aca:toolbar/separator-2',
+ order: 2,
+ type: ContentActionType.separator,
+ title: 'action2'
+ }
+ ]
+ }
+ });
+
+ expect(service.userActions.length).toBe(2);
+ });
+
+ it('should sort user actions by order', () => {
+ applyConfig({
+ $id: 'test',
+ $name: 'test',
+ $version: '1.0.0',
+ $license: 'MIT',
+ $vendor: 'Good company',
+ $runtime: '1.5.0',
+ features: {
+ userActions: [
+ {
+ id: 'aca:toolbar/separator-2',
+ order: 2,
+ type: ContentActionType.separator,
+ title: 'action2'
+ },
+ {
+ id: 'aca:toolbar/separator-1',
+ order: 1,
+ type: ContentActionType.separator,
+ title: 'action1'
+ }
+ ]
+ }
+ });
+
+ expect(service.userActions.length).toBe(2);
+ expect(service.userActions[0].id).toBe('aca:toolbar/separator-1');
+ expect(service.userActions[1].id).toBe('aca:toolbar/separator-2');
+ });
+ });
});