mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
tests
This commit is contained in:
@@ -439,4 +439,40 @@ describe('app.evaluators', () => {
|
|||||||
expect(app.isShared(context)).toBe(true);
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
70
src/app/components/common/logout/logout.component.spec.ts
Normal file
70
src/app/components/common/logout/logout.component.spec.ts
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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<LogoutComponent>;
|
||||||
|
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([]));
|
||||||
|
});
|
||||||
|
});
|
@@ -24,9 +24,91 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { CurrentUserComponent } from './current-user.component';
|
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', () => {
|
describe('CurrentUserComponent', () => {
|
||||||
it('should be defined', () => {
|
let fixture: ComponentFixture<CurrentUserComponent>;
|
||||||
expect(CurrentUserComponent).toBeDefined();
|
let component: CurrentUserComponent;
|
||||||
|
let appExtensionService;
|
||||||
|
let store: Store<AppState>;
|
||||||
|
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 = <any>[
|
||||||
|
{
|
||||||
|
id: 'action-id'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
spyOn(appExtensionService, 'getUserActions').and.returnValue(actions);
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(component.actions).toBe(actions);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
126
src/app/components/current-user/user-menu-item.component.spec.ts
Normal file
126
src/app/components/current-user/user-menu-item.component.spec.ts
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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<UserMenuItemComponent>;
|
||||||
|
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'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
@@ -39,18 +39,21 @@ import {
|
|||||||
ExtensionConfig,
|
ExtensionConfig,
|
||||||
ComponentRegisterService
|
ComponentRegisterService
|
||||||
} from '@alfresco/adf-extensions';
|
} from '@alfresco/adf-extensions';
|
||||||
|
import { AppConfigService } from '@alfresco/adf-core';
|
||||||
|
|
||||||
describe('AppExtensionService', () => {
|
describe('AppExtensionService', () => {
|
||||||
let service: AppExtensionService;
|
let service: AppExtensionService;
|
||||||
let store: Store<AppStore>;
|
let store: Store<AppStore>;
|
||||||
let extensions: ExtensionService;
|
let extensions: ExtensionService;
|
||||||
let components: ComponentRegisterService;
|
let components: ComponentRegisterService;
|
||||||
|
let appConfigService: AppConfigService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [AppTestingModule]
|
imports: [AppTestingModule]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
appConfigService = TestBed.get(AppConfigService);
|
||||||
store = TestBed.get(Store);
|
store = TestBed.get(Store);
|
||||||
service = TestBed.get(AppExtensionService);
|
service = TestBed.get(AppExtensionService);
|
||||||
extensions = TestBed.get(ExtensionService);
|
extensions = TestBed.get(ExtensionService);
|
||||||
@@ -784,4 +787,114 @@ describe('AppExtensionService', () => {
|
|||||||
expect(service.getSharedLinkViewerToolbarActions()).toEqual(<any>actions);
|
expect(service.getSharedLinkViewerToolbarActions()).toEqual(<any>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');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user