]>
Commit | Line | Data |
---|---|---|
e306af50 TL |
1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; |
2 | import { FormsModule } from '@angular/forms'; | |
3 | ||
4 | import { listLocales } from 'ngx-bootstrap/chronos'; | |
5 | import { BsLocaleService } from 'ngx-bootstrap/datepicker'; | |
6 | ||
7 | import { HttpClientTestingModule } from '@angular/common/http/testing'; | |
8 | import { configureTestBed } from '../../../../testing/unit-test-helper'; | |
9 | import { LanguageSelectorComponent } from './language-selector.component'; | |
10 | ||
11 | describe('LanguageSelectorComponent', () => { | |
12 | let component: LanguageSelectorComponent; | |
13 | let fixture: ComponentFixture<LanguageSelectorComponent>; | |
14 | ||
15 | configureTestBed({ | |
16 | declarations: [LanguageSelectorComponent], | |
17 | providers: [BsLocaleService], | |
18 | imports: [FormsModule, HttpClientTestingModule] | |
19 | }); | |
20 | ||
21 | beforeEach(() => { | |
22 | fixture = TestBed.createComponent(LanguageSelectorComponent); | |
23 | component = fixture.componentInstance; | |
24 | fixture.detectChanges(); | |
25 | spyOn(component, 'reloadWindow').and.callFake(() => component.ngOnInit()); | |
26 | }); | |
27 | ||
28 | it('should create', () => { | |
29 | expect(component).toBeTruthy(); | |
30 | }); | |
31 | ||
32 | it('should read current language', () => { | |
33 | expect(component.selectedLanguage).toBe('en-US'); | |
34 | expect(listLocales()).toEqual([]); | |
35 | }); | |
36 | ||
37 | const expectLanguageChange = (lang: string) => { | |
38 | component.changeLanguage(lang); | |
39 | const cookie = document.cookie.split(';').filter((item) => item.includes(`cd-lang=${lang}`)); | |
40 | expect(cookie.length).toBe(1); | |
41 | }; | |
42 | ||
43 | it('should change to cs', () => { | |
44 | expectLanguageChange('cs'); | |
45 | }); | |
46 | ||
47 | it('should change to de-DE', () => { | |
48 | expectLanguageChange('de-DE'); | |
49 | }); | |
50 | ||
51 | it('should change to es-ES', () => { | |
52 | expectLanguageChange('es-ES'); | |
53 | }); | |
54 | ||
55 | it('should change to fr-FR', () => { | |
56 | expectLanguageChange('fr-FR'); | |
57 | }); | |
58 | ||
59 | it('should change to id-ID', () => { | |
60 | expectLanguageChange('id-ID'); | |
61 | }); | |
62 | ||
63 | it('should change to it-IT', () => { | |
64 | expectLanguageChange('it-IT'); | |
65 | }); | |
66 | ||
67 | it('should change to ja-JP', () => { | |
68 | expectLanguageChange('ja-JP'); | |
69 | }); | |
70 | ||
71 | it('should change to ko-KR', () => { | |
72 | expectLanguageChange('ko-KR'); | |
73 | }); | |
74 | ||
75 | it('should change to pl-PL', () => { | |
76 | expectLanguageChange('pl-PL'); | |
77 | }); | |
78 | ||
79 | it('should change to pt-BR', () => { | |
80 | expectLanguageChange('pt-BR'); | |
81 | }); | |
82 | ||
83 | it('should change to zh-CN', () => { | |
84 | expectLanguageChange('zh-CN'); | |
85 | }); | |
86 | ||
87 | it('should change to zh-TW', () => { | |
88 | expectLanguageChange('zh-TW'); | |
89 | }); | |
90 | }); |