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