]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
0381046b7d31baf5e4e557e7da6171b0cf7b178f
[ceph.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 { NgbActiveModal, NgbPopoverModule } from '@ng-bootstrap/ng-bootstrap';
7 import moment from 'moment';
8 import { ToastrModule } from 'ngx-toastr';
9
10 import { NotificationService } from '~/app/shared/services/notification.service';
11 import { SharedModule } from '~/app/shared/shared.module';
12 import { configureTestBed } from '~/testing/unit-test-helper';
13 import { RbdTrashMoveModalComponent } from './rbd-trash-move-modal.component';
14
15 describe('RbdTrashMoveModalComponent', () => {
16   let component: RbdTrashMoveModalComponent;
17   let fixture: ComponentFixture<RbdTrashMoveModalComponent>;
18   let httpTesting: HttpTestingController;
19
20   configureTestBed({
21     imports: [
22       ReactiveFormsModule,
23       HttpClientTestingModule,
24       RouterTestingModule,
25       SharedModule,
26       ToastrModule.forRoot(),
27       NgbPopoverModule
28     ],
29     declarations: [RbdTrashMoveModalComponent],
30     providers: [NgbActiveModal]
31   });
32
33   beforeEach(() => {
34     fixture = TestBed.createComponent(RbdTrashMoveModalComponent);
35     component = fixture.componentInstance;
36     httpTesting = TestBed.inject(HttpTestingController);
37
38     component.poolName = 'foo';
39     component.imageName = 'bar';
40
41     fixture.detectChanges();
42   });
43
44   it('should create', () => {
45     expect(component).toBeTruthy();
46     expect(component.moveForm).toBeDefined();
47   });
48
49   it('should finish running ngOnInit', () => {
50     expect(component.pattern).toEqual('foo/bar');
51   });
52
53   describe('should call moveImage', () => {
54     let notificationService: NotificationService;
55
56     beforeEach(() => {
57       notificationService = TestBed.inject(NotificationService);
58       spyOn(notificationService, 'show').and.stub();
59       spyOn(component.activeModal, 'close').and.callThrough();
60     });
61
62     afterEach(() => {
63       expect(notificationService.show).toHaveBeenCalledTimes(1);
64       expect(component.activeModal.close).toHaveBeenCalledTimes(1);
65     });
66
67     it('with normal delay', () => {
68       component.moveImage();
69       const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
70       req.flush(null);
71       expect(req.request.body).toEqual({ delay: 0 });
72     });
73
74     it('with delay < 0', () => {
75       const oldDate = moment().subtract(24, 'hour').toDate();
76       component.moveForm.patchValue({ expiresAt: oldDate });
77
78       component.moveImage();
79       const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
80       req.flush(null);
81       expect(req.request.body).toEqual({ delay: 0 });
82     });
83
84     it('with delay < 0', () => {
85       const oldDate = moment().add(24, 'hour').toISOString();
86       component.moveForm.patchValue({ expiresAt: oldDate });
87
88       component.moveImage();
89       const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
90       req.flush(null);
91       expect(req.request.body.delay).toBeGreaterThan(76390);
92     });
93   });
94 });