-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: prepared theme ui tests * fix: theme module import order
- Loading branch information
Showing
17 changed files
with
1,867 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { BehaviorSubject, Observable, of } from 'rxjs' | ||
import { CanActivateGuard } from './can-active-guard.service' | ||
|
||
let canActivateGuard: CanActivateGuard | ||
|
||
describe('CanActivateGuard', () => { | ||
const translateServiceSpy = jasmine.createSpyObj('TranslateService', ['setDefaultLang', 'use']) | ||
|
||
const configSpy = jasmine.createSpyObj('ConfigurationService', [], { | ||
lang$: new BehaviorSubject(undefined), | ||
lang: 'en' | ||
}) | ||
|
||
const activatedRouteSpy = jasmine.createSpyObj('ActivatedRouteSnapshot', [], { | ||
routeConfig: { | ||
path: 'path' | ||
} | ||
}) | ||
|
||
const routerStateSnapshotSpy = jasmine.createSpyObj('RouterStateSnapshot', ['']) | ||
|
||
beforeEach(async () => { | ||
canActivateGuard = new CanActivateGuard(translateServiceSpy, configSpy) | ||
translateServiceSpy.setDefaultLang.calls.reset() | ||
translateServiceSpy.use.calls.reset() | ||
}) | ||
|
||
it('should return default lang if provided is not supported', () => { | ||
const result = canActivateGuard.getBestMatchLanguage('pl') | ||
expect(result).toBe('en') | ||
}) | ||
|
||
it('should use default language if current not supported and return true', (doneFn: DoneFn) => { | ||
const langSpy = Object.getOwnPropertyDescriptor(configSpy, 'lang$')?.get as jasmine.Spy< | ||
() => BehaviorSubject<string> | ||
> | ||
langSpy.and.returnValue(new BehaviorSubject('pl')) | ||
spyOn(console, 'log') | ||
translateServiceSpy.use.and.returnValue(of({})) | ||
|
||
const resultObs = canActivateGuard.canActivate(activatedRouteSpy, routerStateSnapshotSpy) as Observable<boolean> | ||
resultObs.subscribe({ | ||
next: (result) => { | ||
expect(result).toBe(true) | ||
doneFn() | ||
}, | ||
error: () => { | ||
doneFn.fail | ||
} | ||
}) | ||
|
||
expect(translateServiceSpy.setDefaultLang).toHaveBeenCalledOnceWith('en') | ||
expect(console.log).toHaveBeenCalledWith('Start Translation guard - default language en') | ||
expect(console.log).toHaveBeenCalledWith(`Translations guard done en`) | ||
expect(console.log).toHaveBeenCalledWith(`Configuration language: pl`) | ||
expect(translateServiceSpy.use).toHaveBeenCalledTimes(2) | ||
expect(translateServiceSpy.use).toHaveBeenCalledWith('en') | ||
}) | ||
|
||
it('should use provided language if current supported and return true', (doneFn: DoneFn) => { | ||
const langSpy = Object.getOwnPropertyDescriptor(configSpy, 'lang$')?.get as jasmine.Spy< | ||
() => BehaviorSubject<string> | ||
> | ||
langSpy.and.returnValue(new BehaviorSubject('de')) | ||
spyOn(console, 'log') | ||
translateServiceSpy.use.and.returnValue(of({})) | ||
|
||
const resultObs = canActivateGuard.canActivate(activatedRouteSpy, routerStateSnapshotSpy) as Observable<boolean> | ||
resultObs.subscribe({ | ||
next: (result) => { | ||
expect(result).toBe(true) | ||
doneFn() | ||
}, | ||
error: () => { | ||
doneFn.fail | ||
} | ||
}) | ||
|
||
expect(console.log).toHaveBeenCalledWith('Start Translation guard - default language en') | ||
expect(console.log).toHaveBeenCalledWith(`Translations guard done en`) | ||
expect(console.log).toHaveBeenCalledWith(`Configuration language: de`) | ||
expect(translateServiceSpy.use).toHaveBeenCalledTimes(2) | ||
expect(translateServiceSpy.use).toHaveBeenCalledWith('en') | ||
expect(translateServiceSpy.use).toHaveBeenCalledWith('de') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/app/shared/image-container/image-container.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing' | ||
import { NO_ERRORS_SCHEMA, SimpleChange } from '@angular/core' | ||
import { ImageContainerComponent } from './image-container.component' | ||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core' | ||
import { HttpLoaderFactory } from '../shared.module' | ||
import { HttpClient } from '@angular/common/http' | ||
import { HttpClientTestingModule } from '@angular/common/http/testing' | ||
import { environment } from 'src/environments/environment' | ||
|
||
describe('ThemeColorBoxComponent', () => { | ||
let component: ImageContainerComponent | ||
let fixture: ComponentFixture<ImageContainerComponent> | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ImageContainerComponent], | ||
imports: [ | ||
HttpClientTestingModule, | ||
TranslateModule.forRoot({ | ||
loader: { | ||
provide: TranslateLoader, | ||
useFactory: HttpLoaderFactory, | ||
deps: [HttpClient] | ||
} | ||
}) | ||
], | ||
providers: [], | ||
schemas: [NO_ERRORS_SCHEMA] | ||
}).compileComponents() | ||
})) | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ImageContainerComponent) | ||
component = fixture.componentInstance | ||
fixture.detectChanges() | ||
}) | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy() | ||
}) | ||
|
||
it('should display placeholder on image error', () => { | ||
component.onImageError() | ||
|
||
expect(component.displayPlaceHolder).toBeTrue() | ||
}) | ||
|
||
it('should use imageUrl on backend after change', () => { | ||
const changes = { | ||
imageUrl: new SimpleChange('', 'imageUrl', false) | ||
} | ||
|
||
component.imageUrl = 'imageUrl' | ||
|
||
component.ngOnChanges(changes) | ||
|
||
expect(component.imageUrl).toBe(environment.apiPrefix + 'imageUrl') | ||
}) | ||
|
||
it('should use image from external resource after change', () => { | ||
const changes = { | ||
imageUrl: new SimpleChange('', 'http://web.com/imageUrl', false) | ||
} | ||
|
||
component.imageUrl = 'http://web.com/imageUrl' | ||
component.ngOnChanges(changes) | ||
|
||
expect(component.imageUrl).toBe('http://web.com/imageUrl') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { LabelResolver } from './label.resolver' | ||
|
||
let labelResolver: LabelResolver | ||
|
||
describe('LabelResolver', () => { | ||
const translateServiceSpy = jasmine.createSpyObj('TranslateService', ['instant']) | ||
|
||
const activatedRouteSpy = jasmine.createSpyObj('ActivatedRouteSnapshot', [], { | ||
routeConfig: { | ||
path: 'path' | ||
}, | ||
data: {} | ||
}) | ||
|
||
const routerStateSpy = jasmine.createSpyObj('RouterStateSnapshot', ['']) | ||
|
||
beforeEach(async () => { | ||
labelResolver = new LabelResolver(translateServiceSpy) | ||
translateServiceSpy.instant.calls.reset() | ||
const dataSpy = Object.getOwnPropertyDescriptor(activatedRouteSpy, 'data')?.get as jasmine.Spy<() => {}> | ||
dataSpy.and.returnValue({}) | ||
}) | ||
|
||
it('should translate if breadcrumb is present', () => { | ||
const dataSpy = Object.getOwnPropertyDescriptor(activatedRouteSpy, 'data')?.get as jasmine.Spy<() => {}> | ||
dataSpy.and.returnValue({ | ||
breadcrumb: 'defined' | ||
}) | ||
translateServiceSpy.instant.and.returnValue('translation') | ||
|
||
const result = labelResolver.resolve(activatedRouteSpy, routerStateSpy) | ||
|
||
expect(result).toBe('translation') | ||
expect(translateServiceSpy.instant).toHaveBeenCalledOnceWith('defined') | ||
}) | ||
|
||
it('should use route path if breadcrumb is not present', () => { | ||
const result = labelResolver.resolve(activatedRouteSpy, routerStateSpy) | ||
|
||
expect(result).toBe('path') | ||
expect(translateServiceSpy.instant).toHaveBeenCalledTimes(0) | ||
}) | ||
}) |
40 changes: 40 additions & 0 deletions
40
src/app/shared/theme-color-box/theme-color-box.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing' | ||
import { ThemeColorBoxComponent } from './theme-color-box.component' | ||
import { NO_ERRORS_SCHEMA } from '@angular/core' | ||
import { HttpClientTestingModule } from '@angular/common/http/testing' | ||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core' | ||
import { HttpLoaderFactory } from '../shared.module' | ||
import { HttpClient } from '@angular/common/http' | ||
|
||
describe('ThemeColorBoxComponent', () => { | ||
let component: ThemeColorBoxComponent | ||
let fixture: ComponentFixture<ThemeColorBoxComponent> | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ThemeColorBoxComponent], | ||
imports: [ | ||
HttpClientTestingModule, | ||
TranslateModule.forRoot({ | ||
loader: { | ||
provide: TranslateLoader, | ||
useFactory: HttpLoaderFactory, | ||
deps: [HttpClient] | ||
} | ||
}) | ||
], | ||
providers: [], | ||
schemas: [NO_ERRORS_SCHEMA] | ||
}).compileComponents() | ||
})) | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ThemeColorBoxComponent) | ||
component = fixture.componentInstance | ||
fixture.detectChanges() | ||
}) | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { limitText } from './utils' | ||
|
||
describe('utils', () => { | ||
it('should limit text if text too long', () => { | ||
const result = limitText('textData', 4) | ||
expect(result).toBe('text...') | ||
}) | ||
}) |
Oops, something went wrong.