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 } from '@ng-bootstrap/ng-bootstrap';
 
   7 import * as moment from 'moment';
 
   8 import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
 
   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: [NgbActiveModal, i18nProviders]
 
  35     fixture = TestBed.createComponent(RbdTrashMoveModalComponent);
 
  36     component = fixture.componentInstance;
 
  37     httpTesting = TestBed.inject(HttpTestingController);
 
  39     component.poolName = 'foo';
 
  40     component.imageName = 'bar';
 
  42     fixture.detectChanges();
 
  45   it('should create', () => {
 
  46     expect(component).toBeTruthy();
 
  47     expect(component.moveForm).toBeDefined();
 
  50   it('should finish running ngOnInit', () => {
 
  51     expect(component.pattern).toEqual('foo/bar');
 
  54   describe('should call moveImage', () => {
 
  55     let notificationService: NotificationService;
 
  58       notificationService = TestBed.inject(NotificationService);
 
  59       spyOn(notificationService, 'show').and.stub();
 
  60       spyOn(component.activeModal, 'close').and.callThrough();
 
  64       expect(notificationService.show).toHaveBeenCalledTimes(1);
 
  65       expect(component.activeModal.close).toHaveBeenCalledTimes(1);
 
  68     it('with normal delay', () => {
 
  69       component.moveImage();
 
  70       const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
 
  72       expect(req.request.body).toEqual({ delay: 0 });
 
  75     it('with delay < 0', () => {
 
  76       const oldDate = moment().subtract(24, 'hour').toDate();
 
  77       component.moveForm.patchValue({ expiresAt: oldDate });
 
  79       component.moveImage();
 
  80       const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
 
  82       expect(req.request.body).toEqual({ delay: 0 });
 
  85     it('with delay < 0', () => {
 
  86       const oldDate = moment().add(24, 'hour').toISOString();
 
  87       component.moveForm.patchValue({ expiresAt: oldDate });
 
  89       component.moveImage();
 
  90       const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
 
  92       expect(req.request.body.delay).toBeGreaterThan(86390);