themed.component.spec.ts (dspace-angular-dspace-7.0) | : | themed.component.spec.ts (dspace-angular-dspace-7.1) | ||
---|---|---|---|---|
import { ThemedComponent } from './themed.component'; | import { ThemedComponent } from './themed.component'; | |||
import { Component, NO_ERRORS_SCHEMA } from '@angular/core'; | import { Component, NO_ERRORS_SCHEMA } from '@angular/core'; | |||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | |||
import { VarDirective } from '../utils/var.directive'; | import { VarDirective } from '../utils/var.directive'; | |||
import { ThemeService } from './theme.service'; | import { ThemeService } from './theme.service'; | |||
import { getMockThemeService } from '../mocks/theme-service.mock'; | import { getMockThemeService } from '../mocks/theme-service.mock'; | |||
import { TestComponent } from './test/test.component.spec'; | import { TestComponent } from './test/test.component.spec'; | |||
import { ThemeConfig } from '../../../config/theme.model'; | ||||
/* tslint:disable:max-classes-per-file */ | /* tslint:disable:max-classes-per-file */ | |||
@Component({ | @Component({ | |||
selector: 'ds-test-themed-component', | selector: 'ds-test-themed-component', | |||
templateUrl: './themed.component.html' | templateUrl: './themed.component.html' | |||
}) | }) | |||
class TestThemedComponent extends ThemedComponent<TestComponent> { | class TestThemedComponent extends ThemedComponent<TestComponent> { | |||
protected inAndOutputNames: (keyof TestComponent & keyof this)[] = ['testInput ']; | protected inAndOutputNames: (keyof TestComponent & keyof this)[] = ['testInput ']; | |||
testInput = 'unset'; | testInput = 'unset'; | |||
skipping to change at line 35 | skipping to change at line 36 | |||
protected importUnthemedComponent(): Promise<any> { | protected importUnthemedComponent(): Promise<any> { | |||
return import('./test/test.component.spec'); | return import('./test/test.component.spec'); | |||
} | } | |||
} | } | |||
describe('ThemedComponent', () => { | describe('ThemedComponent', () => { | |||
let component: TestThemedComponent; | let component: TestThemedComponent; | |||
let fixture: ComponentFixture<TestThemedComponent>; | let fixture: ComponentFixture<TestThemedComponent>; | |||
let themeService: ThemeService; | let themeService: ThemeService; | |||
function setupTestingModuleForTheme(theme: string) { | function setupTestingModuleForTheme(theme: string, themes?: ThemeConfig[]) { | |||
themeService = getMockThemeService(theme); | themeService = getMockThemeService(theme, themes); | |||
TestBed.configureTestingModule({ | TestBed.configureTestingModule({ | |||
imports: [], | imports: [], | |||
declarations: [TestThemedComponent, VarDirective], | declarations: [TestThemedComponent, VarDirective], | |||
providers: [ | providers: [ | |||
{ provide: ThemeService, useValue: themeService }, | { provide: ThemeService, useValue: themeService }, | |||
], | ], | |||
schemas: [NO_ERRORS_SCHEMA] | schemas: [NO_ERRORS_SCHEMA] | |||
}).compileComponents(); | }).compileComponents(); | |||
} | } | |||
function initComponent() { | ||||
fixture = TestBed.createComponent(TestThemedComponent); | ||||
component = fixture.componentInstance; | ||||
spyOn(component as any, 'importThemedComponent').and.callThrough(); | ||||
component.testInput = 'changed'; | ||||
fixture.detectChanges(); | ||||
} | ||||
describe('when the current theme matches a themed component', () => { | describe('when the current theme matches a themed component', () => { | |||
beforeEach(waitForAsync(() => { | beforeEach(waitForAsync(() => { | |||
setupTestingModuleForTheme('custom'); | setupTestingModuleForTheme('custom'); | |||
})); | })); | |||
beforeEach(() => { | beforeEach(initComponent); | |||
fixture = TestBed.createComponent(TestThemedComponent); | ||||
component = fixture.componentInstance; | ||||
component.testInput = 'changed'; | ||||
fixture.detectChanges(); | ||||
}); | ||||
it('should set compRef to the themed component', waitForAsync(() => { | it('should set compRef to the themed component', waitForAsync(() => { | |||
fixture.whenStable().then(() => { | fixture.whenStable().then(() => { | |||
expect((component as any).compRef.instance.type).toEqual('themed'); | expect((component as any).compRef.instance.type).toEqual('themed'); | |||
}); | }); | |||
})); | })); | |||
it('should sync up this component\'s input with the themed component', waitF orAsync(() => { | it('should sync up this component\'s input with the themed component', waitF orAsync(() => { | |||
fixture.whenStable().then(() => { | fixture.whenStable().then(() => { | |||
expect((component as any).compRef.instance.testInput).toEqual('changed') ; | expect((component as any).compRef.instance.testInput).toEqual('changed') ; | |||
}); | }); | |||
})); | })); | |||
}); | }); | |||
describe('when the current theme doesn\'t match a themed component', () => { | describe('when the current theme doesn\'t match a themed component', () => { | |||
beforeEach(waitForAsync(() => { | describe('and it doesn\'t extend another theme', () => { | |||
setupTestingModuleForTheme('non-existing-theme'); | beforeEach(waitForAsync(() => { | |||
})); | setupTestingModuleForTheme('non-existing-theme'); | |||
})); | ||||
beforeEach(() => { | ||||
fixture = TestBed.createComponent(TestThemedComponent); | beforeEach(initComponent); | |||
component = fixture.componentInstance; | ||||
component.testInput = 'changed'; | it('should set compRef to the default component', waitForAsync(() => { | |||
fixture.detectChanges(); | fixture.whenStable().then(() => { | |||
expect((component as any).compRef.instance.type).toEqual('default'); | ||||
}); | ||||
})); | ||||
it('should sync up this component\'s input with the default component', wa | ||||
itForAsync(() => { | ||||
fixture.whenStable().then(() => { | ||||
expect((component as any).compRef.instance.testInput).toEqual('changed | ||||
'); | ||||
}); | ||||
})); | ||||
}); | }); | |||
it('should set compRef to the default component', waitForAsync(() => { | describe('and it extends another theme', () => { | |||
fixture.whenStable().then(() => { | describe('that doesn\'t match it either', () => { | |||
expect((component as any).compRef.instance.type).toEqual('default'); | beforeEach(waitForAsync(() => { | |||
setupTestingModuleForTheme('current-theme', [ | ||||
{ name: 'current-theme', extends: 'non-existing-theme' }, | ||||
]); | ||||
})); | ||||
beforeEach(initComponent); | ||||
it('should set compRef to the default component', waitForAsync(() => { | ||||
fixture.whenStable().then(() => { | ||||
expect((component as any).importThemedComponent).toHaveBeenCalledWit | ||||
h('current-theme'); | ||||
expect((component as any).importThemedComponent).toHaveBeenCalledWit | ||||
h('non-existing-theme'); | ||||
expect((component as any).compRef.instance.type).toEqual('default'); | ||||
}); | ||||
})); | ||||
it('should sync up this component\'s input with the default component', | ||||
waitForAsync(() => { | ||||
fixture.whenStable().then(() => { | ||||
expect((component as any).compRef.instance.testInput).toEqual('chang | ||||
ed'); | ||||
}); | ||||
})); | ||||
}); | }); | |||
})); | ||||
it('should sync up this component\'s input with the default component', wait | describe('that does match it', () => { | |||
ForAsync(() => { | beforeEach(waitForAsync(() => { | |||
fixture.whenStable().then(() => { | setupTestingModuleForTheme('current-theme', [ | |||
expect((component as any).compRef.instance.testInput).toEqual('changed') | { name: 'current-theme', extends: 'custom' }, | |||
; | ]); | |||
})); | ||||
beforeEach(initComponent); | ||||
it('should set compRef to the themed component', waitForAsync(() => { | ||||
fixture.whenStable().then(() => { | ||||
expect((component as any).importThemedComponent).toHaveBeenCalledWit | ||||
h('current-theme'); | ||||
expect((component as any).importThemedComponent).toHaveBeenCalledWit | ||||
h('custom'); | ||||
expect((component as any).compRef.instance.type).toEqual('themed'); | ||||
}); | ||||
})); | ||||
it('should sync up this component\'s input with the themed component', w | ||||
aitForAsync(() => { | ||||
fixture.whenStable().then(() => { | ||||
expect((component as any).compRef.instance.testInput).toEqual('chang | ||||
ed'); | ||||
}); | ||||
})); | ||||
}); | }); | |||
})); | ||||
describe('that extends another theme that doesn\'t match it either', () => | ||||
{ | ||||
beforeEach(waitForAsync(() => { | ||||
setupTestingModuleForTheme('current-theme', [ | ||||
{ name: 'current-theme', extends: 'parent-theme' }, | ||||
{ name: 'parent-theme', extends: 'non-existing-theme' }, | ||||
]); | ||||
})); | ||||
beforeEach(initComponent); | ||||
it('should set compRef to the default component', waitForAsync(() => { | ||||
fixture.whenStable().then(() => { | ||||
expect((component as any).importThemedComponent).toHaveBeenCalledWit | ||||
h('current-theme'); | ||||
expect((component as any).importThemedComponent).toHaveBeenCalledWit | ||||
h('parent-theme'); | ||||
expect((component as any).importThemedComponent).toHaveBeenCalledWit | ||||
h('non-existing-theme'); | ||||
expect((component as any).compRef.instance.type).toEqual('default'); | ||||
}); | ||||
})); | ||||
it('should sync up this component\'s input with the default component', | ||||
waitForAsync(() => { | ||||
fixture.whenStable().then(() => { | ||||
expect((component as any).compRef.instance.testInput).toEqual('chang | ||||
ed'); | ||||
}); | ||||
})); | ||||
}); | ||||
describe('that extends another theme that does match it', () => { | ||||
beforeEach(waitForAsync(() => { | ||||
setupTestingModuleForTheme('current-theme', [ | ||||
{ name: 'current-theme', extends: 'parent-theme' }, | ||||
{ name: 'parent-theme', extends: 'custom' }, | ||||
]); | ||||
})); | ||||
beforeEach(initComponent); | ||||
it('should set compRef to the themed component', waitForAsync(() => { | ||||
fixture.whenStable().then(() => { | ||||
expect((component as any).importThemedComponent).toHaveBeenCalledWit | ||||
h('current-theme'); | ||||
expect((component as any).importThemedComponent).toHaveBeenCalledWit | ||||
h('parent-theme'); | ||||
expect((component as any).importThemedComponent).toHaveBeenCalledWit | ||||
h('custom'); | ||||
expect((component as any).compRef.instance.type).toEqual('themed'); | ||||
}); | ||||
})); | ||||
it('should sync up this component\'s input with the themed component', w | ||||
aitForAsync(() => { | ||||
fixture.whenStable().then(() => { | ||||
expect((component as any).compRef.instance.testInput).toEqual('chang | ||||
ed'); | ||||
}); | ||||
})); | ||||
}); | ||||
}); | ||||
}); | }); | |||
}); | }); | |||
/* tslint:enable:max-classes-per-file */ | /* tslint:enable:max-classes-per-file */ | |||
End of changes. 9 change blocks. | ||||
27 lines changed or deleted | 149 lines changed or added |