]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
6f6a2ced65117729aab775bd0c94b7140694a4f9
[ceph-ci.git] /
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.metaType = 'RBD';
40     component.poolName = 'foo';
41     component.imageName = 'bar';
42
43     fixture.detectChanges();
44   });
45
46   it('should create', () => {
47     expect(component).toBeTruthy();
48     expect(component.moveForm).toBeDefined();
49   });
50
51   it('should finish running ngOnInit', () => {
52     expect(component.pattern).toEqual('foo/bar');
53   });
54
55   describe('should call moveImage', () => {
56     let notificationService;
57
58     beforeEach(() => {
59       notificationService = TestBed.get(NotificationService);
60       spyOn(notificationService, 'show').and.stub();
61       spyOn(component.modalRef, 'hide').and.callThrough();
62     });
63
64     afterEach(() => {
65       expect(notificationService.show).toHaveBeenCalledTimes(1);
66       expect(component.modalRef.hide).toHaveBeenCalledTimes(1);
67     });
68
69     it('with normal delay', () => {
70       component.moveImage();
71       const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
72       req.flush(null);
73       expect(req.request.body).toEqual({ delay: 0 });
74     });
75
76     it('with delay < 0', () => {
77       const oldDate = moment()
78         .subtract(24, 'hour')
79         .toDate();
80       component.moveForm.patchValue({ expiresAt: oldDate });
81
82       component.moveImage();
83       const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
84       req.flush(null);
85       expect(req.request.body).toEqual({ delay: 0 });
86     });
87
88     it('with delay < 0', () => {
89       const oldDate = moment()
90         .add(24, 'hour')
91         .toISOString();
92       component.moveForm.patchValue({ expiresAt: oldDate });
93
94       component.moveImage();
95       const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
96       req.flush(null);
97       expect(req.request.body.delay).toBeGreaterThan(86390);
98     });
99   });
100 });