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';
9 class MockRgwBucketService {
10 listNotification = jest.fn((bucket: string) => of([{ bucket, notifications: [] }]));
12 describe('RgwBucketNotificationListComponent', () => {
13 let component: RgwBucketNotificationListComponent;
14 let fixture: ComponentFixture<RgwBucketNotificationListComponent>;
15 let rgwtbucketService: RgwBucketService;
16 let rgwnotificationListSpy: jasmine.Spy;
19 declarations: [RgwBucketNotificationListComponent],
20 imports: [ComponentsModule, HttpClientTestingModule],
22 { provide: 'bucket', useValue: { bucket: 'bucket1', owner: 'dashboard' } },
23 { provide: RgwBucketService, useClass: MockRgwBucketService }
28 fixture = TestBed.createComponent(RgwBucketNotificationListComponent);
29 component = fixture.componentInstance;
30 rgwtbucketService = TestBed.inject(RgwBucketService);
31 rgwnotificationListSpy = spyOn(rgwtbucketService, 'listNotification').and.callThrough();
33 fixture = TestBed.createComponent(RgwBucketNotificationListComponent);
34 component = fixture.componentInstance;
35 fixture.detectChanges();
38 it('should create', () => {
39 expect(component).toBeTruthy();
41 it('should call list', () => {
42 rgwtbucketService.listNotification('testbucket').subscribe((response) => {
43 expect(response).toEqual([{ bucket: 'testbucket', notifications: [] }]);
45 expect(rgwnotificationListSpy).toHaveBeenCalledWith('testbucket');