github.com/thanos-io/thanos@v0.32.5/pkg/ui/react-app/src/pages/tsdbStatus/TSDBStatus.test.tsx (about) 1 import * as React from 'react'; 2 import { mount, ReactWrapper } from 'enzyme'; 3 import { act } from 'react-dom/test-utils'; 4 import { Table } from 'reactstrap'; 5 6 import TSDBStatus from './TSDBStatus'; 7 import { TSDBMap } from './TSDBStatus'; 8 9 const fakeTSDBStatusResponse: { 10 status: string; 11 data: TSDBMap; 12 } = { 13 status: 'success', 14 data: { 15 labelValueCountByLabelName: [ 16 { 17 name: '__name__', 18 value: 5, 19 }, 20 ], 21 seriesCountByMetricName: [ 22 { 23 name: 'scrape_duration_seconds', 24 value: 1, 25 }, 26 { 27 name: 'scrape_samples_scraped', 28 value: 1, 29 }, 30 ], 31 memoryInBytesByLabelName: [ 32 { 33 name: '__name__', 34 value: 103, 35 }, 36 ], 37 seriesCountByLabelValuePair: [ 38 { 39 name: 'instance=localhost:9100', 40 value: 5, 41 }, 42 ], 43 }, 44 }; 45 46 describe('TSDB Stats', () => { 47 beforeEach(() => { 48 fetchMock.resetMocks(); 49 }); 50 51 describe('Table Data Validation', () => { 52 it('Table Test', async () => { 53 const tables = [ 54 { 55 data: fakeTSDBStatusResponse.data.labelValueCountByLabelName, 56 table_index: 0, 57 }, 58 { 59 data: fakeTSDBStatusResponse.data.seriesCountByMetricName, 60 table_index: 1, 61 }, 62 { 63 data: fakeTSDBStatusResponse.data.memoryInBytesByLabelName, 64 table_index: 2, 65 }, 66 { 67 data: fakeTSDBStatusResponse.data.seriesCountByLabelValuePair, 68 table_index: 3, 69 }, 70 ]; 71 72 const mock = fetchMock.mockResponse(JSON.stringify(fakeTSDBStatusResponse)); 73 let page: any; 74 await act(async () => { 75 page = mount(<TSDBStatus pathPrefix="/path/prefix" />); 76 }); 77 page.update(); 78 79 expect(mock).toHaveBeenCalledWith('/path/prefix/api/v1/status/tsdb', { 80 cache: 'no-store', 81 credentials: 'same-origin', 82 }); 83 84 for (let i = 0; i < tables.length; i++) { 85 const data = tables[i].data; 86 const table = page.find(Table).at(tables[i].table_index).find('tbody'); 87 const rows = table.find('tr'); 88 for (let i = 0; i < data.length; i++) { 89 const firstRowColumns = rows 90 .at(i) 91 .find('td') 92 .map((column: ReactWrapper) => column.text()); 93 expect(rows.length).toBe(data.length); 94 expect(firstRowColumns[0]).toBe(data[i].name); 95 expect(firstRowColumns[1]).toBe(data[i].value.toString()); 96 } 97 } 98 }); 99 }); 100 });