]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
bd82bb0e6a0aaa71d021f3861a282fe4924c544d
[ceph-ci.git] /
1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { HttpClientTestingModule } from '@angular/common/http/testing';
3 import { RgwBucketNotificationListComponent } from './rgw-bucket-notification-list.component';
4 import { configureTestBed } from '~/testing/unit-test-helper';
5 import { ComponentsModule } from '~/app/shared/components/components.module';
6 import { RgwBucketService } from '~/app/shared/api/rgw-bucket.service';
7 import { of } from 'rxjs';
8
9 class MockRgwBucketService {
10   listNotification = jest.fn((bucket: string) => of([{ bucket, notifications: [] }]));
11 }
12 describe('RgwBucketNotificationListComponent', () => {
13   let component: RgwBucketNotificationListComponent;
14   let fixture: ComponentFixture<RgwBucketNotificationListComponent>;
15   let rgwtbucketService: RgwBucketService;
16   let rgwnotificationListSpy: jasmine.Spy;
17
18   configureTestBed({
19     declarations: [RgwBucketNotificationListComponent],
20     imports: [ComponentsModule, HttpClientTestingModule],
21     providers: [
22       { provide: 'bucket', useValue: { bucket: 'bucket1', owner: 'dashboard' } },
23       { provide: RgwBucketService, useClass: MockRgwBucketService }
24     ]
25   });
26
27   beforeEach(() => {
28     fixture = TestBed.createComponent(RgwBucketNotificationListComponent);
29     component = fixture.componentInstance;
30     rgwtbucketService = TestBed.inject(RgwBucketService);
31     rgwnotificationListSpy = spyOn(rgwtbucketService, 'listNotification').and.callThrough();
32
33     fixture = TestBed.createComponent(RgwBucketNotificationListComponent);
34     component = fixture.componentInstance;
35     fixture.detectChanges();
36   });
37
38   it('should create', () => {
39     expect(component).toBeTruthy();
40   });
41   it('should call list', () => {
42     rgwtbucketService.listNotification('testbucket').subscribe((response) => {
43       expect(response).toEqual([{ bucket: 'testbucket', notifications: [] }]);
44     });
45     expect(rgwnotificationListSpy).toHaveBeenCalledWith('testbucket');
46   });
47 });