]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
b895bc3c2a0c2b2565100400dd6ee9e1db0f0079
[ceph.git] /
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { FormsModule } from '@angular/forms';
4
5 import { listLocales } from 'ngx-bootstrap/chronos';
6 import { BsLocaleService } from 'ngx-bootstrap/datepicker';
7
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', () => {
48     expectLanguageChange('de');
49   });
50
51   it('should change to es', () => {
52     expectLanguageChange('es');
53   });
54
55   it('should change to fr', () => {
56     expectLanguageChange('fr');
57   });
58
59   it('should change to id', () => {
60     expectLanguageChange('id');
61   });
62
63   it('should change to it', () => {
64     expectLanguageChange('it');
65   });
66
67   it('should change to ja', () => {
68     expectLanguageChange('ja');
69   });
70
71   it('should change to ko', () => {
72     expectLanguageChange('ko');
73   });
74
75   it('should change to pl', () => {
76     expectLanguageChange('pl');
77   });
78
79   it('should change to pt', () => {
80     expectLanguageChange('pt');
81   });
82
83   it('should change to zh-Hans', () => {
84     expectLanguageChange('zh-Hans');
85   });
86
87   it('should change to zh-Hant', () => {
88     expectLanguageChange('zh-Hant');
89   });
90 });