juice-shop

Форк
0
/
welcome.component.spec.ts 
77 строк · 2.7 Кб
1
/*
2
 * Copyright (c) 2014-2024 Bjoern Kimminich & the OWASP Juice Shop contributors.
3
 * SPDX-License-Identifier: MIT
4
 */
5

6
import { TranslateModule } from '@ngx-translate/core'
7
import { HttpClientTestingModule } from '@angular/common/http/testing'
8
import { MatDialog, MatDialogModule } from '@angular/material/dialog'
9
import { CookieModule, CookieService } from 'ngx-cookie'
10

11
import { type ComponentFixture, TestBed } from '@angular/core/testing'
12

13
import { WelcomeComponent } from './welcome.component'
14
import { of } from 'rxjs'
15
import { ConfigurationService } from '../Services/configuration.service'
16

17
describe('WelcomeComponent', () => {
18
  let component: WelcomeComponent
19
  let configurationService: any
20
  let cookieService: any
21
  let fixture: ComponentFixture<WelcomeComponent>
22
  let dialog: any
23

24
  beforeEach(() => {
25
    configurationService = jasmine.createSpyObj('ConfigurationService', ['getApplicationConfiguration'])
26
    configurationService.getApplicationConfiguration.and.returnValue(of({ application: {} }))
27
    dialog = jasmine.createSpyObj('MatDialog', ['open'])
28
    dialog.open.and.returnValue(null)
29

30
    TestBed.configureTestingModule({
31
      imports: [
32
        TranslateModule.forRoot(),
33
        CookieModule.forRoot(),
34
        HttpClientTestingModule,
35
        MatDialogModule
36
      ],
37
      declarations: [WelcomeComponent],
38
      providers: [
39
        { provide: ConfigurationService, useValue: configurationService },
40
        { provide: MatDialog, useValue: dialog },
41
        CookieService
42
      ]
43
    })
44
      .compileComponents()
45

46
    cookieService = TestBed.inject(CookieService)
47
  })
48

49
  beforeEach(() => {
50
    fixture = TestBed.createComponent(WelcomeComponent)
51
    component = fixture.componentInstance
52
    cookieService.remove('welcomebanner_status')
53
  })
54

55
  it('should create', () => {
56
    expect(component).toBeTruthy()
57
  })
58

59
  it('should open the welcome banner dialog if configured to show on start', () => {
60
    configurationService.getApplicationConfiguration.and.returnValue(of({ application: { welcomeBanner: { showOnFirstStart: true } } }))
61
    component.ngOnInit()
62
    expect(dialog.open).toHaveBeenCalled()
63
  })
64

65
  it('should not open the welcome banner dialog if configured to not show on start', () => {
66
    configurationService.getApplicationConfiguration.and.returnValue(of({ application: { welcomeBanner: { showOnFirstStart: false } } }))
67
    component.ngOnInit()
68
    expect(dialog.open).not.toHaveBeenCalled()
69
  })
70

71
  it('should not open the welcome banner dialog if previously dismissed', () => {
72
    configurationService.getApplicationConfiguration.and.returnValue(of({ application: { welcomeBanner: { showOnFirstStart: true } } }))
73
    cookieService.put('welcomebanner_status', 'dismiss')
74
    component.ngOnInit()
75
    expect(dialog.open).not.toHaveBeenCalled()
76
  })
77
})
78

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

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

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

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