juice-shop

Форк
0
/
code-fixes.component.spec.ts 
45 строк · 1.5 Кб
1
import { type ComponentFixture, TestBed } from '@angular/core/testing'
2
import { CookieModule, CookieService } from 'ngx-cookie'
3

4
import { CodeFixesComponent } from './code-fixes.component'
5

6
describe('CodeFixesComponent', () => {
7
  let component: CodeFixesComponent
8
  let fixture: ComponentFixture<CodeFixesComponent>
9
  let cookieService: any
10

11
  beforeEach(async () => {
12
    await TestBed.configureTestingModule({
13
      imports: [CookieModule.forRoot()],
14
      declarations: [CodeFixesComponent],
15
      providers: [CookieService]
16
    })
17
      .compileComponents()
18
    cookieService = TestBed.inject(CookieService)
19
  })
20

21
  beforeEach(() => {
22
    fixture = TestBed.createComponent(CodeFixesComponent)
23
    component = fixture.componentInstance
24
    fixture.detectChanges()
25
  })
26

27
  it('should create', () => {
28
    expect(component).toBeTruthy()
29
  })
30

31
  it('should set the format from cookie if the cookie key exists', () => {
32
    spyOn(cookieService, 'hasKey').and.returnValue(true)
33
    spyOn(cookieService, 'get').and.returnValue('LineByLine')
34
    component.ngOnInit()
35
    expect(component.format).toBe('LineByLine')
36
  })
37

38
  it('should set the format to "LineByLine" and save it in the cookie if the cookie key does not exist', () => {
39
    spyOn(cookieService, 'hasKey').and.returnValue(false)
40
    spyOn(cookieService, 'put')
41
    component.ngOnInit()
42
    expect(component.format).toBe('LineByLine')
43
    expect(cookieService.put).toHaveBeenCalledWith('code-fixes-component-format', 'LineByLine')
44
  })
45
})
46

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.