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';
6 import * as moment from 'moment';
7 import { ToastModule } from 'ng2-toastr';
8 import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
9 import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
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';
16 describe('RbdTrashMoveModalComponent', () => {
17 let component: RbdTrashMoveModalComponent;
18 let fixture: ComponentFixture<RbdTrashMoveModalComponent>;
19 let httpTesting: HttpTestingController;
24 HttpClientTestingModule,
27 ToastModule.forRoot(),
28 BsDatepickerModule.forRoot()
30 declarations: [RbdTrashMoveModalComponent],
31 providers: [BsModalRef, BsModalService, i18nProviders]
35 fixture = TestBed.createComponent(RbdTrashMoveModalComponent);
36 component = fixture.componentInstance;
37 httpTesting = TestBed.get(HttpTestingController);
39 component.metaType = 'RBD';
40 component.poolName = 'foo';
41 component.imageName = 'bar';
44 it('should create', () => {
45 expect(component).toBeTruthy();
46 expect(component.moveForm).toBeDefined();
49 it('should finish running ngOnInit', () => {
50 fixture.detectChanges();
51 expect(component.pattern).toEqual('foo/bar');
54 describe('should call moveImage', () => {
55 let notificationService;
58 notificationService = TestBed.get(NotificationService);
59 spyOn(notificationService, 'show').and.stub();
60 spyOn(component.modalRef, 'hide').and.callThrough();
64 expect(notificationService.show).toHaveBeenCalledTimes(1);
65 expect(component.modalRef.hide).toHaveBeenCalledTimes(1);
68 it('with normal delay', () => {
69 component.moveImage();
70 const req = httpTesting.expectOne('api/block/image/foo/bar/move_trash');
72 expect(req.request.body).toEqual({ delay: 0 });
75 it('with delay < 0', () => {
76 const oldDate = moment()
79 component.moveForm.patchValue({ expiresAt: oldDate });
81 component.moveImage();
82 const req = httpTesting.expectOne('api/block/image/foo/bar/move_trash');
84 expect(req.request.body).toEqual({ delay: 0 });
87 it('with delay < 0', () => {
88 const oldDate = moment()
91 fixture.detectChanges();
92 component.moveForm.patchValue({ expiresAt: oldDate });
94 component.moveImage();
95 const req = httpTesting.expectOne('api/block/image/foo/bar/move_trash');
97 expect(req.request.body.delay).toBeGreaterThan(86390);