juice-shop
84 строки · 2.8 Кб
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 { MatInputModule } from '@angular/material/input'
8import { MatExpansionModule } from '@angular/material/expansion'
9import { MatDialogModule } from '@angular/material/dialog'
10import { type ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'
11
12import { BasketComponent } from './basket.component'
13import { MatCardModule } from '@angular/material/card'
14import { MatTableModule } from '@angular/material/table'
15import { MatButtonModule } from '@angular/material/button'
16import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
17import { HttpClientTestingModule } from '@angular/common/http/testing'
18import { ReactiveFormsModule } from '@angular/forms'
19import { MatFormFieldModule } from '@angular/material/form-field'
20import { MatButtonToggleModule } from '@angular/material/button-toggle'
21import { RouterTestingModule } from '@angular/router/testing'
22import { PurchaseBasketComponent } from '../purchase-basket/purchase-basket.component'
23import { DeluxeGuard } from '../app.guard'
24import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'
25
26describe('BasketComponent', () => {
27let component: BasketComponent
28let fixture: ComponentFixture<BasketComponent>
29let deluxeGuard
30let snackBar: any
31
32beforeEach(waitForAsync(() => {
33TestBed.configureTestingModule({
34declarations: [BasketComponent, PurchaseBasketComponent],
35imports: [
36RouterTestingModule,
37HttpClientTestingModule,
38TranslateModule.forRoot(),
39BrowserAnimationsModule,
40ReactiveFormsModule,
41MatFormFieldModule,
42MatInputModule,
43MatCardModule,
44MatTableModule,
45MatButtonModule,
46MatExpansionModule,
47MatDialogModule,
48MatButtonToggleModule,
49MatSnackBarModule
50],
51providers: [
52{ provide: DeluxeGuard, useValue: deluxeGuard },
53{ provide: MatSnackBar, useValue: snackBar }
54]
55})
56.compileComponents()
57}))
58
59beforeEach(() => {
60fixture = TestBed.createComponent(BasketComponent)
61component = fixture.componentInstance
62fixture.detectChanges()
63})
64
65it('should create', () => {
66expect(component).toBeTruthy()
67})
68
69it('should store product count on calling getProductCount', () => {
70component.getProductCount(1)
71expect(component.productCount).toBe(1)
72})
73
74it('should store bonus points on calling getBonusPoints', () => {
75component.getBonusPoints([1, 10])
76expect(component.bonus).toBe(10)
77})
78
79it('should store itemTotal in session storage', () => {
80spyOn(sessionStorage, 'setItem')
81component.getBonusPoints([1, 10])
82expect(sessionStorage.setItem).toHaveBeenCalledWith('itemTotal', 1 as any)
83})
84})
85