juice-shop
45 строк · 1.5 Кб
1import { type ComponentFixture, TestBed } from '@angular/core/testing'
2import { CookieModule, CookieService } from 'ngx-cookie'
3
4import { CodeFixesComponent } from './code-fixes.component'
5
6describe('CodeFixesComponent', () => {
7let component: CodeFixesComponent
8let fixture: ComponentFixture<CodeFixesComponent>
9let cookieService: any
10
11beforeEach(async () => {
12await TestBed.configureTestingModule({
13imports: [CookieModule.forRoot()],
14declarations: [CodeFixesComponent],
15providers: [CookieService]
16})
17.compileComponents()
18cookieService = TestBed.inject(CookieService)
19})
20
21beforeEach(() => {
22fixture = TestBed.createComponent(CodeFixesComponent)
23component = fixture.componentInstance
24fixture.detectChanges()
25})
26
27it('should create', () => {
28expect(component).toBeTruthy()
29})
30
31it('should set the format from cookie if the cookie key exists', () => {
32spyOn(cookieService, 'hasKey').and.returnValue(true)
33spyOn(cookieService, 'get').and.returnValue('LineByLine')
34component.ngOnInit()
35expect(component.format).toBe('LineByLine')
36})
37
38it('should set the format to "LineByLine" and save it in the cookie if the cookie key does not exist', () => {
39spyOn(cookieService, 'hasKey').and.returnValue(false)
40spyOn(cookieService, 'put')
41component.ngOnInit()
42expect(component.format).toBe('LineByLine')
43expect(cookieService.put).toHaveBeenCalledWith('code-fixes-component-format', 'LineByLine')
44})
45})
46