summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/shared/components/language-selector/language-selector.component.spec.ts
blob: 5c8334e5a68296f9d6e3c30257a45a82a652d121 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';

import { configureTestBed } from '~/testing/unit-test-helper';
import { LanguageSelectorComponent } from './language-selector.component';

describe('LanguageSelectorComponent', () => {
  let component: LanguageSelectorComponent;
  let fixture: ComponentFixture<LanguageSelectorComponent>;

  configureTestBed({
    declarations: [LanguageSelectorComponent],
    imports: [FormsModule, HttpClientTestingModule]
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(LanguageSelectorComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
    spyOn(component, 'reloadWindow').and.callFake(() => component.ngOnInit());
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should read current language', () => {
    expect(component.selectedLanguage).toBe('en-US');
  });

  const expectLanguageChange = (lang: string) => {
    component.changeLanguage(lang);
    const cookie = document.cookie.split(';').filter((item) => item.includes(`cd-lang=${lang}`));
    expect(cookie.length).toBe(1);
  };

  it('should change to cs', () => {
    expectLanguageChange('cs');
  });

  it('should change to de', () => {
    expectLanguageChange('de');
  });

  it('should change to es', () => {
    expectLanguageChange('es');
  });

  it('should change to fr', () => {
    expectLanguageChange('fr');
  });

  it('should change to id', () => {
    expectLanguageChange('id');
  });

  it('should change to it', () => {
    expectLanguageChange('it');
  });

  it('should change to ja', () => {
    expectLanguageChange('ja');
  });

  it('should change to ko', () => {
    expectLanguageChange('ko');
  });

  it('should change to pl', () => {
    expectLanguageChange('pl');
  });

  it('should change to pt', () => {
    expectLanguageChange('pt');
  });

  it('should change to zh-Hans', () => {
    expectLanguageChange('zh-Hans');
  });

  it('should change to zh-Hant', () => {
    expectLanguageChange('zh-Hant');
  });
});