]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
769dde5832441e82eaeae215bb5050d6d79c73eb
[ceph-ci.git] /
1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3
4 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
5 import { AppModule } from '../../../app.module';
6 import { CdTableFetchDataContext } from '../../../shared/models/cd-table-fetch-data-context';
7 import { TablePerformanceCounterComponent } from './table-performance-counter.component';
8
9 describe('TablePerformanceCounterComponent', () => {
10   let component: TablePerformanceCounterComponent;
11   let fixture: ComponentFixture<TablePerformanceCounterComponent>;
12   let httpTesting: HttpTestingController;
13
14   configureTestBed({
15     imports: [AppModule, HttpClientTestingModule],
16     providers: i18nProviders
17   });
18
19   beforeEach(() => {
20     fixture = TestBed.createComponent(TablePerformanceCounterComponent);
21     component = fixture.componentInstance;
22     httpTesting = TestBed.get(HttpTestingController);
23     fixture.detectChanges();
24   });
25
26   it('should create', () => {
27     expect(component).toBeTruthy();
28     expect(component.counters).toEqual([]);
29   });
30
31   it('should have columns that are sortable', () => {
32     expect(component.columns.every((column) => Boolean(column.prop))).toBeTruthy();
33   });
34
35   describe('Error handling', () => {
36     const context = new CdTableFetchDataContext(() => {});
37
38     beforeEach(() => {
39       spyOn(context, 'error');
40       component.serviceType = 'osd';
41       component.serviceId = '3';
42       component.getCounters(context);
43     });
44
45     it('should display 404 warning', () => {
46       httpTesting
47         .expectOne('api/perf_counters/osd/3')
48         .error(new ErrorEvent('osd.3 not found'), { status: 404 });
49       httpTesting.verify();
50       expect(component.counters).toBeNull();
51       expect(context.error).not.toHaveBeenCalled();
52     });
53
54     it('should call error function of context', () => {
55       httpTesting
56         .expectOne('api/perf_counters/osd/3')
57         .error(new ErrorEvent('Unknown error'), { status: 500 });
58       httpTesting.verify();
59       expect(component.counters).toEqual([]);
60       expect(context.error).toHaveBeenCalled();
61     });
62   });
63 });