]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-trash-move-modal/rbd-trash-move-modal.component.spec.ts
import 15.2.0 Octopus source
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / block / rbd-trash-move-modal / rbd-trash-move-modal.component.spec.ts
1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { ReactiveFormsModule } from '@angular/forms';
4 import { RouterTestingModule } from '@angular/router/testing';
5
6 import * as moment from 'moment';
7 import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
8 import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
9 import { ToastrModule } from 'ngx-toastr';
10
11 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
12 import { NotificationService } from '../../../shared/services/notification.service';
13 import { SharedModule } from '../../../shared/shared.module';
14 import { RbdTrashMoveModalComponent } from './rbd-trash-move-modal.component';
15
16 describe('RbdTrashMoveModalComponent', () => {
17 let component: RbdTrashMoveModalComponent;
18 let fixture: ComponentFixture<RbdTrashMoveModalComponent>;
19 let httpTesting: HttpTestingController;
20
21 configureTestBed({
22 imports: [
23 ReactiveFormsModule,
24 HttpClientTestingModule,
25 RouterTestingModule,
26 SharedModule,
27 ToastrModule.forRoot(),
28 BsDatepickerModule.forRoot()
29 ],
30 declarations: [RbdTrashMoveModalComponent],
31 providers: [BsModalRef, BsModalService, i18nProviders]
32 });
33
34 beforeEach(() => {
35 fixture = TestBed.createComponent(RbdTrashMoveModalComponent);
36 component = fixture.componentInstance;
37 httpTesting = TestBed.get(HttpTestingController);
38
39 component.poolName = 'foo';
40 component.imageName = 'bar';
41
42 fixture.detectChanges();
43 });
44
45 it('should create', () => {
46 expect(component).toBeTruthy();
47 expect(component.moveForm).toBeDefined();
48 });
49
50 it('should finish running ngOnInit', () => {
51 expect(component.pattern).toEqual('foo/bar');
52 });
53
54 describe('should call moveImage', () => {
55 let notificationService: NotificationService;
56
57 beforeEach(() => {
58 notificationService = TestBed.get(NotificationService);
59 spyOn(notificationService, 'show').and.stub();
60 spyOn(component.modalRef, 'hide').and.callThrough();
61 });
62
63 afterEach(() => {
64 expect(notificationService.show).toHaveBeenCalledTimes(1);
65 expect(component.modalRef.hide).toHaveBeenCalledTimes(1);
66 });
67
68 it('with normal delay', () => {
69 component.moveImage();
70 const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
71 req.flush(null);
72 expect(req.request.body).toEqual({ delay: 0 });
73 });
74
75 it('with delay < 0', () => {
76 const oldDate = moment()
77 .subtract(24, 'hour')
78 .toDate();
79 component.moveForm.patchValue({ expiresAt: oldDate });
80
81 component.moveImage();
82 const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
83 req.flush(null);
84 expect(req.request.body).toEqual({ delay: 0 });
85 });
86
87 it('with delay < 0', () => {
88 const oldDate = moment()
89 .add(24, 'hour')
90 .toISOString();
91 component.moveForm.patchValue({ expiresAt: oldDate });
92
93 component.moveImage();
94 const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
95 req.flush(null);
96 expect(req.request.body.delay).toBeGreaterThan(86390);
97 });
98 });
99 });