juice-shop

Форк
0
/
basket.component.spec.ts 
84 строки · 2.8 Кб
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 { MatInputModule } from '@angular/material/input'
8
import { MatExpansionModule } from '@angular/material/expansion'
9
import { MatDialogModule } from '@angular/material/dialog'
10
import { type ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'
11

12
import { BasketComponent } from './basket.component'
13
import { MatCardModule } from '@angular/material/card'
14
import { MatTableModule } from '@angular/material/table'
15
import { MatButtonModule } from '@angular/material/button'
16
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
17
import { HttpClientTestingModule } from '@angular/common/http/testing'
18
import { ReactiveFormsModule } from '@angular/forms'
19
import { MatFormFieldModule } from '@angular/material/form-field'
20
import { MatButtonToggleModule } from '@angular/material/button-toggle'
21
import { RouterTestingModule } from '@angular/router/testing'
22
import { PurchaseBasketComponent } from '../purchase-basket/purchase-basket.component'
23
import { DeluxeGuard } from '../app.guard'
24
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'
25

26
describe('BasketComponent', () => {
27
  let component: BasketComponent
28
  let fixture: ComponentFixture<BasketComponent>
29
  let deluxeGuard
30
  let snackBar: any
31

32
  beforeEach(waitForAsync(() => {
33
    TestBed.configureTestingModule({
34
      declarations: [BasketComponent, PurchaseBasketComponent],
35
      imports: [
36
        RouterTestingModule,
37
        HttpClientTestingModule,
38
        TranslateModule.forRoot(),
39
        BrowserAnimationsModule,
40
        ReactiveFormsModule,
41
        MatFormFieldModule,
42
        MatInputModule,
43
        MatCardModule,
44
        MatTableModule,
45
        MatButtonModule,
46
        MatExpansionModule,
47
        MatDialogModule,
48
        MatButtonToggleModule,
49
        MatSnackBarModule
50
      ],
51
      providers: [
52
        { provide: DeluxeGuard, useValue: deluxeGuard },
53
        { provide: MatSnackBar, useValue: snackBar }
54
      ]
55
    })
56
      .compileComponents()
57
  }))
58

59
  beforeEach(() => {
60
    fixture = TestBed.createComponent(BasketComponent)
61
    component = fixture.componentInstance
62
    fixture.detectChanges()
63
  })
64

65
  it('should create', () => {
66
    expect(component).toBeTruthy()
67
  })
68

69
  it('should store product count on calling getProductCount', () => {
70
    component.getProductCount(1)
71
    expect(component.productCount).toBe(1)
72
  })
73

74
  it('should store bonus points on calling getBonusPoints', () => {
75
    component.getBonusPoints([1, 10])
76
    expect(component.bonus).toBe(10)
77
  })
78

79
  it('should store itemTotal in session storage', () => {
80
    spyOn(sessionStorage, 'setItem')
81
    component.getBonusPoints([1, 10])
82
    expect(sessionStorage.setItem).toHaveBeenCalledWith('itemTotal', 1 as any)
83
  })
84
})
85

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

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

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

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