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 { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
8 import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
9 import { ToastrModule } from 'ngx-toastr';
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 ToastrModule.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';
43 fixture.detectChanges();
46 it('should create', () => {
47 expect(component).toBeTruthy();
48 expect(component.moveForm).toBeDefined();
51 it('should finish running ngOnInit', () => {
52 expect(component.pattern).toEqual('foo/bar');
55 describe('should call moveImage', () => {
56 let notificationService;
59 notificationService = TestBed.get(NotificationService);
60 spyOn(notificationService, 'show').and.stub();
61 spyOn(component.modalRef, 'hide').and.callThrough();
65 expect(notificationService.show).toHaveBeenCalledTimes(1);
66 expect(component.modalRef.hide).toHaveBeenCalledTimes(1);
69 it('with normal delay', () => {
70 component.moveImage();
71 const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
73 expect(req.request.body).toEqual({ delay: 0 });
76 it('with delay < 0', () => {
77 const oldDate = moment()
80 component.moveForm.patchValue({ expiresAt: oldDate });
82 component.moveImage();
83 const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
85 expect(req.request.body).toEqual({ delay: 0 });
88 it('with delay < 0', () => {
89 const oldDate = moment()
92 component.moveForm.patchValue({ expiresAt: oldDate });
94 component.moveImage();
95 const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
97 expect(req.request.body.delay).toBeGreaterThan(86390);