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 { 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';
19 } from 'carbon-components-angular';
20 import { DateTimePickerComponent } from '~/app/shared/components/date-time-picker/date-time-picker.component';
22 describe('RbdTrashMoveModalComponent', () => {
23 let component: RbdTrashMoveModalComponent;
24 let fixture: ComponentFixture<RbdTrashMoveModalComponent>;
25 let httpTesting: HttpTestingController;
30 HttpClientTestingModule,
33 ToastrModule.forRoot(),
40 declarations: [RbdTrashMoveModalComponent, DateTimePickerComponent],
42 { provide: 'poolName', useValue: 'foo' },
43 { provide: 'imageName', useValue: 'bar' },
44 { provide: 'namespace', useValue: '' },
45 { provide: 'hasSnapshots', useValue: false }
50 fixture = TestBed.createComponent(RbdTrashMoveModalComponent);
51 component = fixture.componentInstance;
52 httpTesting = TestBed.inject(HttpTestingController);
54 component.poolName = 'foo';
55 component.imageName = 'bar';
57 fixture.detectChanges();
60 it('should create', () => {
61 expect(component).toBeTruthy();
62 expect(component.moveForm).toBeDefined();
65 it('should finish running ngOnInit', () => {
66 expect(component.pattern).toEqual('foo/bar');
69 describe('should call moveImage', () => {
70 let notificationService: NotificationService;
73 notificationService = TestBed.inject(NotificationService);
74 spyOn(notificationService, 'show').and.stub();
75 spyOn(component, 'closeModal').and.callThrough();
79 expect(notificationService.show).toHaveBeenCalledTimes(1);
80 expect(component.closeModal).toHaveBeenCalledTimes(1);
83 it('with normal delay', () => {
84 component.moveImage();
85 const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
87 expect(req.request.body).toEqual({ delay: 0 });
90 it('with delay < 0', () => {
91 const oldDate = moment().subtract(24, 'hour').toDate();
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).toEqual({ delay: 0 });
100 it('with delay < 0', () => {
101 const oldDate = moment().add(24, 'hour').toISOString();
102 component.moveForm.patchValue({ expiresAt: oldDate });
104 component.moveImage();
105 const req = httpTesting.expectOne('api/block/image/foo%2Fbar/move_trash');
107 expect(req.request.body.delay).toBeGreaterThan(76390);