Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Tackett <[email protected]>
  • Loading branch information
Adam Tackett committed Dec 5, 2024
1 parent 456e9fd commit 7b5a9a2
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,33 @@ const httpClientMock = jest.requireMock('../../../../../../test/__mocks__/httpCl

configure({ adapter: new Adapter() });

describe.only('SpanDetailTable with Mocked Data', () => {

Check failure on line 29 in public/components/trace_analytics/components/traces/__tests__/span_detail_table.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

No exclusive suites

Check failure on line 29 in public/components/trace_analytics/components/traces/__tests__/span_detail_table.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected focused test
it('renders the table with mocked data', async () => {
// Mock the HTTP response
httpClientMock.post.mockResolvedValue((TEST_SPAN_RESPONSE as unknown) as HttpResponse);

const wrapper = mount(
<SpanDetailTable
http={httpClientMock}
hiddenColumns={['traceId', 'traceGroup']}
DSL={{}}
openFlyout={() => {}}
mode="data_prepper"
dataSourceMDSId="testDataSource"
/>
);

// Wait for the table to render
await waitFor(() => {
wrapper.update();
expect(wrapper.find('EuiDataGrid')).toHaveLength(1); // Ensure the table is rendered
});
// Check that the table has rows

Check failure on line 50 in public/components/trace_analytics/components/traces/__tests__/span_detail_table.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
const tableRows = wrapper.find('[data-test-subj="dataGridRowCell"]').hostNodes();
expect(tableRows).toHaveLength(3); // Replace 10 with the expected number of rows
});
});

describe('SpanDetailTable', () => {
it('renders the empty component', async () => {
httpClientMock.post.mockResolvedValue(({
Expand Down Expand Up @@ -309,4 +336,102 @@ describe('SpanDetailTableHierarchy', () => {
});
expect(container).toMatchSnapshot();
});

it.only('should expand all rows when "Expand All" is clicked', async () => {

Check failure on line 340 in public/components/trace_analytics/components/traces/__tests__/span_detail_table.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

No exclusive tests

Check failure on line 340 in public/components/trace_analytics/components/traces/__tests__/span_detail_table.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected focused test
// Mock HTTP response with data
httpClientMock.post.mockResolvedValue((TEST_SPAN_RESPONSE as unknown) as HttpResponse);

const wrapper = mount(
<SpanDetailTableHierarchy
http={httpClientMock}
hiddenColumns={[]}
openFlyout={jest.fn()}
mode="data_prepper"
dataSourceMDSId="testDataSource"
/>
);

// Wait for the component to render
await waitFor(() => {
wrapper.update();
expect(wrapper.find('EuiDataGrid')).toHaveLength(1);
});

const densitybuttonz = wrapper.find('[data-test-subj="dataGridStyleSelectorPopover"]').hostNodes();

Check failure on line 360 in public/components/trace_analytics/components/traces/__tests__/span_detail_table.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `.find('[data-test-subj="dataGridStyleSelectorPopover"]')` with `⏎······.find('[data-test-subj="dataGridStyleSelectorPopover"]')⏎······`
console.log("Density button", densitybuttonz.length);

Check failure on line 361 in public/components/trace_analytics/components/traces/__tests__/span_detail_table.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `"Density·button"` with `'Density·button'`
const expandAllButton1 = wrapper.find('[data-test-subj="treeExpandAll"]').hostNodes();

Check failure on line 362 in public/components/trace_analytics/components/traces/__tests__/span_detail_table.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

'expandAllButton1' is assigned a value but never used. Allowed unused vars must match /^_/u
const collapseAllButton1 = wrapper.find('[data-test-subj="treeCollapseAll"]').hostNodes();

Check failure on line 363 in public/components/trace_analytics/components/traces/__tests__/span_detail_table.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

'collapseAllButton1' is assigned a value but never used. Allowed unused vars must match /^_/u
wrapper.update();
await waitFor(() => {

Check failure on line 366 in public/components/trace_analytics/components/traces/__tests__/span_detail_table.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `⏎······`
expect(wrapper.find('EuiDataGrid')).toHaveLength(1); // Ensure the table is rendered
});

// Simulate clicking the "Expand All" button
const expandAllButton = wrapper
.find('[data-test-subj="treeExpandAll"]')
.hostNodes();
expect(expandAllButton).toHaveLength(1);

act(() => {
expandAllButton.simulate('click');
});

wrapper.update();

// Check that all rows are expanded
const expandedRows = wrapper.find('EuiIcon[type="arrowDown"]').length;
expect(expandedRows).toBeGreaterThan(0);
});

it.only('should collapse all rows when "Collapse All" is clicked', async () => {
// Mock HTTP response with data
httpClientMock.post.mockResolvedValue((TEST_SPAN_RESPONSE as unknown) as HttpResponse);

const wrapper = mount(
<SpanDetailTableHierarchy
http={httpClientMock}
hiddenColumns={[]}
openFlyout={jest.fn()}
mode="data_prepper"
dataSourceMDSId="testDataSource"
/>
);

// Wait for the component to render
await waitFor(() => {
wrapper.update();
expect(wrapper.find('EuiDataGrid')).toHaveLength(1);
});

// Check that the table has rows
const tableRows = wrapper.find('[data-test-subj="dataGridRowCell"]').hostNodes();
expect(tableRows).toHaveLength(10); // Replace 10 with the expected number of rows

// Simulate clicking the "Expand All" button first to expand all rows
const expandAllButton = wrapper
.find('[data-test-subj="treeExpandAll"]')
.hostNodes();
act(() => {
expandAllButton.simulate('click');
});

wrapper.update();

// Simulate clicking the "Collapse All" button
const collapseAllButton = wrapper
.find('[data-test-subj="treeCollapseAll"]')
.hostNodes();
expect(collapseAllButton).toHaveLength(1);

act(() => {
collapseAllButton.simulate('click');
});

wrapper.update();

// Check that all rows are collapsed
const expandedRows = wrapper.find('EuiIcon[type="arrowDown"]').length;
expect(expandedRows).toBe(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export function SpanDetailPanel(props: {
plotTraces: Plotly.Data[],
_maxX: number
): Partial<Plotly.Layout> => {
const dynamicWidthAdjustment = isLocked ? 400 : 200;
const dynamicWidthAdjustment = isLocked ? 410 : 200;
// get unique labels from traces
const yLabels = plotTraces
.map((d) => d.y[0])
Expand Down

0 comments on commit 7b5a9a2

Please sign in to comment.