1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { FormsModule } from '@angular/forms';
5 import { listLocales } from 'ngx-bootstrap/chronos';
6 import { BsLocaleService } from 'ngx-bootstrap/datepicker';
8 import { configureTestBed } from '../../../../testing/unit-test-helper';
9 import { LanguageSelectorComponent } from './language-selector.component';
11 describe('LanguageSelectorComponent', () => {
12 let component: LanguageSelectorComponent;
13 let fixture: ComponentFixture<LanguageSelectorComponent>;
16 declarations: [LanguageSelectorComponent],
17 providers: [BsLocaleService],
18 imports: [FormsModule, HttpClientTestingModule]
22 fixture = TestBed.createComponent(LanguageSelectorComponent);
23 component = fixture.componentInstance;
24 fixture.detectChanges();
25 spyOn(component, 'reloadWindow').and.callFake(() => component.ngOnInit());
28 it('should create', () => {
29 expect(component).toBeTruthy();
32 it('should read current language', () => {
33 expect(component.selectedLanguage).toBe('en-US');
34 expect(listLocales()).toEqual([]);
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);
43 it('should change to cs', () => {
44 expectLanguageChange('cs');
47 it('should change to de', () => {
48 expectLanguageChange('de');
51 it('should change to es', () => {
52 expectLanguageChange('es');
55 it('should change to fr', () => {
56 expectLanguageChange('fr');
59 it('should change to id', () => {
60 expectLanguageChange('id');
63 it('should change to it', () => {
64 expectLanguageChange('it');
67 it('should change to ja', () => {
68 expectLanguageChange('ja');
71 it('should change to ko', () => {
72 expectLanguageChange('ko');
75 it('should change to pl', () => {
76 expectLanguageChange('pl');
79 it('should change to pt', () => {
80 expectLanguageChange('pt');
83 it('should change to zh-Hans', () => {
84 expectLanguageChange('zh-Hans');
87 it('should change to zh-Hant', () => {
88 expectLanguageChange('zh-Hant');