]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
4a219d8b10390a5d40f7e5e77fbd3213c221ab0e
[ceph.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   describe('Error handling', () => {
32     const context = new CdTableFetchDataContext(() => {});
33
34     beforeEach(() => {
35       spyOn(context, 'error');
36       component.serviceType = 'osd';
37       component.serviceId = '3';
38       component.getCounters(context);
39     });
40
41     it('should display 404 warning', () => {
42       httpTesting
43         .expectOne('api/perf_counters/osd/3')
44         .error(new ErrorEvent('osd.3 not found'), { status: 404 });
45       httpTesting.verify();
46       expect(component.counters).toBeNull();
47       expect(context.error).not.toHaveBeenCalled();
48     });
49
50     it('should call error function of context', () => {
51       httpTesting
52         .expectOne('api/perf_counters/osd/3')
53         .error(new ErrorEvent('Unknown error'), { status: 500 });
54       httpTesting.verify();
55       expect(component.counters).toEqual([]);
56       expect(context.error).toHaveBeenCalled();
57     });
58   });
59 });