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 { NgbActiveModal, NgbPopoverModule } from '@ng-bootstrap/ng-bootstrap';
7 import moment from 'moment';
8 import { ToastrModule } from 'ngx-toastr';
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';
15 describe('RbdTrashMoveModalComponent', () => {
16 let component: RbdTrashMoveModalComponent;
17 let fixture: ComponentFixture<RbdTrashMoveModalComponent>;
18 let httpTesting: HttpTestingController;
23 HttpClientTestingModule,
26 ToastrModule.forRoot(),
29 declarations: [RbdTrashMoveModalComponent],
30 providers: [NgbActiveModal]
34 fixture = TestBed.createComponent(RbdTrashMoveModalComponent);
35 component = fixture.componentInstance;
36 httpTesting = TestBed.inject(HttpTestingController);
38 component.poolName = 'foo';
39 component.imageName = 'bar';
41 fixture.detectChanges();
44 it('should create', () => {
45 expect(component).toBeTruthy();
46 expect(component.moveForm).toBeDefined();
49 it('should finish running ngOnInit', () => {
50 expect(component.pattern).toEqual('foo/bar');
53 describe('should call moveImage', () => {
54 let notificationService: NotificationService;
57 notificationService = TestBed.inject(NotificationService);
58 spyOn(notificationService, 'show').and.stub();
59 spyOn(component.activeModal, 'close').and.callThrough();
63 expect(notificationService.show).toHaveBeenCalledTimes(1);
64 expect(component.activeModal.close).toHaveBeenCalledTimes(1);
67 it('with normal delay', () => {
68 component.moveImage();
69 const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
71 expect(req.request.body).toEqual({ delay: 0 });
74 it('with delay < 0', () => {
75 const oldDate = moment().subtract(24, 'hour').toDate();
76 component.moveForm.patchValue({ expiresAt: oldDate });
78 component.moveImage();
79 const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
81 expect(req.request.body).toEqual({ delay: 0 });
84 it('with delay < 0', () => {
85 const oldDate = moment().add(24, 'hour').toISOString();
86 component.moveForm.patchValue({ expiresAt: oldDate });
88 component.moveImage();
89 const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
91 expect(req.request.body.delay).toBeGreaterThan(76390);