juice-shop
77 строк · 2.7 Кб
1/*
2* Copyright (c) 2014-2024 Bjoern Kimminich & the OWASP Juice Shop contributors.
3* SPDX-License-Identifier: MIT
4*/
5
6import { TranslateModule } from '@ngx-translate/core'
7import { HttpClientTestingModule } from '@angular/common/http/testing'
8import { MatDialog, MatDialogModule } from '@angular/material/dialog'
9import { CookieModule, CookieService } from 'ngx-cookie'
10
11import { type ComponentFixture, TestBed } from '@angular/core/testing'
12
13import { WelcomeComponent } from './welcome.component'
14import { of } from 'rxjs'
15import { ConfigurationService } from '../Services/configuration.service'
16
17describe('WelcomeComponent', () => {
18let component: WelcomeComponent
19let configurationService: any
20let cookieService: any
21let fixture: ComponentFixture<WelcomeComponent>
22let dialog: any
23
24beforeEach(() => {
25configurationService = jasmine.createSpyObj('ConfigurationService', ['getApplicationConfiguration'])
26configurationService.getApplicationConfiguration.and.returnValue(of({ application: {} }))
27dialog = jasmine.createSpyObj('MatDialog', ['open'])
28dialog.open.and.returnValue(null)
29
30TestBed.configureTestingModule({
31imports: [
32TranslateModule.forRoot(),
33CookieModule.forRoot(),
34HttpClientTestingModule,
35MatDialogModule
36],
37declarations: [WelcomeComponent],
38providers: [
39{ provide: ConfigurationService, useValue: configurationService },
40{ provide: MatDialog, useValue: dialog },
41CookieService
42]
43})
44.compileComponents()
45
46cookieService = TestBed.inject(CookieService)
47})
48
49beforeEach(() => {
50fixture = TestBed.createComponent(WelcomeComponent)
51component = fixture.componentInstance
52cookieService.remove('welcomebanner_status')
53})
54
55it('should create', () => {
56expect(component).toBeTruthy()
57})
58
59it('should open the welcome banner dialog if configured to show on start', () => {
60configurationService.getApplicationConfiguration.and.returnValue(of({ application: { welcomeBanner: { showOnFirstStart: true } } }))
61component.ngOnInit()
62expect(dialog.open).toHaveBeenCalled()
63})
64
65it('should not open the welcome banner dialog if configured to not show on start', () => {
66configurationService.getApplicationConfiguration.and.returnValue(of({ application: { welcomeBanner: { showOnFirstStart: false } } }))
67component.ngOnInit()
68expect(dialog.open).not.toHaveBeenCalled()
69})
70
71it('should not open the welcome banner dialog if previously dismissed', () => {
72configurationService.getApplicationConfiguration.and.returnValue(of({ application: { welcomeBanner: { showOnFirstStart: true } } }))
73cookieService.put('welcomebanner_status', 'dismiss')
74component.ngOnInit()
75expect(dialog.open).not.toHaveBeenCalled()
76})
77})
78