Skip to content

Commit

Permalink
tests: update cypress + jest test timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
logeekal committed Mar 27, 2024
1 parent d01ba94 commit a4b1e9c
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -553,117 +553,149 @@ describe('query tab with unified timeline', () => {
});

describe('unified fields list', () => {
it('should add the column when clicked on X sign', async () => {
const field = {
name: 'event.severity',
};
it(
'should add the column when clicked on X sign',
async () => {
const field = {
name: 'event.severity',
};

renderTestComponents();
expect(await screen.findByTestId('timeline-sidebar')).toBeVisible();
renderTestComponents();
expect(await screen.findByTestId('timeline-sidebar')).toBeVisible();

await waitFor(() => {
expect(screen.getByTestId('fieldListGroupedSelectedFields-count')).toHaveTextContent('11');
});
await waitFor(() => {
expect(screen.getByTestId('fieldListGroupedSelectedFields-count')).toHaveTextContent(
'11'
);
});

// column exists in the table
expect(screen.getByTestId(`dataGridHeaderCell-${field.name}`)).toBeVisible();
// column exists in the table
expect(screen.getByTestId(`dataGridHeaderCell-${field.name}`)).toBeVisible();

fireEvent.click(screen.getAllByTestId(`fieldToggle-${field.name}`)[0]);
fireEvent.click(screen.getAllByTestId(`fieldToggle-${field.name}`)[0]);

// column not longer exists in the table
await waitFor(() => {
expect(screen.getByTestId('fieldListGroupedSelectedFields-count')).toHaveTextContent('10');
});
expect(screen.queryAllByTestId(`dataGridHeaderCell-${field.name}`)).toHaveLength(0);
});
// column not longer exists in the table
await waitFor(() => {
expect(screen.getByTestId('fieldListGroupedSelectedFields-count')).toHaveTextContent(
'10'
);
});
expect(screen.queryAllByTestId(`dataGridHeaderCell-${field.name}`)).toHaveLength(0);
},
SPECIAL_TEST_TIMEOUT
);

it('should remove the column when clicked on ⊕ sign', async () => {
const field = {
name: 'agent.id',
};
it(
'should remove the column when clicked on ⊕ sign',
async () => {
const field = {
name: 'agent.id',
};

renderTestComponents();
expect(await screen.findByTestId('timeline-sidebar')).toBeVisible();
renderTestComponents();
expect(await screen.findByTestId('timeline-sidebar')).toBeVisible();

await waitFor(() => {
expect(screen.getByTestId('fieldListGroupedSelectedFields-count')).toHaveTextContent('11');
});
await waitFor(() => {
expect(screen.getByTestId('fieldListGroupedSelectedFields-count')).toHaveTextContent(
'11'
);
});

expect(screen.queryAllByTestId(`dataGridHeaderCell-${field.name}`)).toHaveLength(0);
expect(screen.queryAllByTestId(`dataGridHeaderCell-${field.name}`)).toHaveLength(0);

// column exists in the table
const availableFields = screen.getByTestId('fieldListGroupedAvailableFields');
// column exists in the table
const availableFields = screen.getByTestId('fieldListGroupedAvailableFields');

fireEvent.click(within(availableFields).getByTestId(`fieldToggle-${field.name}`));
fireEvent.click(within(availableFields).getByTestId(`fieldToggle-${field.name}`));

await waitFor(() => {
expect(screen.getByTestId('fieldListGroupedSelectedFields-count')).toHaveTextContent('12');
});
expect(screen.queryAllByTestId(`dataGridHeaderCell-${field.name}`)).toHaveLength(1);
});
await waitFor(() => {
expect(screen.getByTestId('fieldListGroupedSelectedFields-count')).toHaveTextContent(
'12'
);
});
expect(screen.queryAllByTestId(`dataGridHeaderCell-${field.name}`)).toHaveLength(1);
},
SPECIAL_TEST_TIMEOUT
);

it('should should show callout when field search does not matches any field', async () => {
renderTestComponents();
expect(await screen.findByTestId('timeline-sidebar')).toBeVisible();
it(
'should should show callout when field search does not matches any field',
async () => {
renderTestComponents();
expect(await screen.findByTestId('timeline-sidebar')).toBeVisible();

await waitFor(() => {
expect(screen.getByTestId('fieldListGroupedAvailableFields-count')).toHaveTextContent('36');
});
await waitFor(() => {
expect(screen.getByTestId('fieldListGroupedAvailableFields-count')).toHaveTextContent(
'36'
);
});

fireEvent.change(screen.getByTestId('fieldListFiltersFieldSearch'), {
target: { value: 'fake_field' },
});
fireEvent.change(screen.getByTestId('fieldListFiltersFieldSearch'), {
target: { value: 'fake_field' },
});

await waitFor(() => {
expect(
screen.getByTestId('fieldListGroupedAvailableFieldsNoFieldsCallout-noFieldsMatch')
).toBeVisible();
});

expect(screen.getByTestId('fieldListGroupedAvailableFields-count')).toHaveTextContent('0');
}, 10000);

it('should toggle side bar correctly', async () => {
renderTestComponents();
expect(await screen.findByTestId('timeline-sidebar')).toBeVisible();
await waitFor(() => {
expect(screen.getByTestId('fieldListGroupedAvailableFields-count')).toHaveTextContent('36');
});

fireEvent.click(screen.getByTitle('Hide sidebar'));

await waitFor(() => {
expect(screen.queryAllByTestId('fieldListGroupedAvailableFields-count')).toHaveLength(0);
});
}, 10000);

it('should have all populated fields in Available fields section', async () => {
const listOfPopulatedFields = new Set(
flatten(
mockTimelineData.map((dataItem) =>
dataItem.data.map((item) =>
item.value && item.value.length > 0 ? item.field : undefined
await waitFor(() => {
expect(
screen.getByTestId('fieldListGroupedAvailableFieldsNoFieldsCallout-noFieldsMatch')
).toBeVisible();
});

expect(screen.getByTestId('fieldListGroupedAvailableFields-count')).toHaveTextContent('0');
},
SPECIAL_TEST_TIMEOUT
);

it(
'should toggle side bar correctly',
async () => {
renderTestComponents();
expect(await screen.findByTestId('timeline-sidebar')).toBeVisible();
await waitFor(() => {
expect(screen.getByTestId('fieldListGroupedAvailableFields-count')).toHaveTextContent(
'36'
);
});

fireEvent.click(screen.getByTitle('Hide sidebar'));

await waitFor(() => {
expect(screen.queryAllByTestId('fieldListGroupedAvailableFields-count')).toHaveLength(0);
});
},
SPECIAL_TEST_TIMEOUT
);

it(
'should have all populated fields in Available fields section',
async () => {
const listOfPopulatedFields = new Set(
flatten(
mockTimelineData.map((dataItem) =>
dataItem.data.map((item) =>
item.value && item.value.length > 0 ? item.field : undefined
)
)
)
).filter((item) => typeof item !== 'undefined')
);
).filter((item) => typeof item !== 'undefined')
);

renderTestComponents();
renderTestComponents();

expect(await screen.findByTestId('timeline-sidebar')).toBeVisible();
expect(await screen.findByTestId('discoverDocTable')).toBeVisible();
expect(await screen.findByTestId('timeline-sidebar')).toBeVisible();
expect(await screen.findByTestId('discoverDocTable')).toBeVisible();

changeItemsPerPageTo(100);
changeItemsPerPageTo(100);

const availableFields = screen.getByTestId('fieldListGroupedAvailableFields');
const availableFields = screen.getByTestId('fieldListGroupedAvailableFields');

for (const field of listOfPopulatedFields) {
fireEvent.change(screen.getByTestId('fieldListFiltersFieldSearch'), {
target: { value: field },
});
for (const field of listOfPopulatedFields) {
fireEvent.change(screen.getByTestId('fieldListFiltersFieldSearch'), {
target: { value: field },
});

expect(within(availableFields).getByTestId(`field-${field}`));
}
});
expect(within(availableFields).getByTestId(`field-${field}`));
}
},
SPECIAL_TEST_TIMEOUT
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ import { getDataTestSubjectSelector } from '../helpers/common';

export const TIMELINE_DETAILS_FLYOUT_BTN = getDataTestSubjectSelector('docTableExpandToggleColumn');

export const HOST_DETAILS_FLYOUT = getDataTestSubjectSelector('host-details-button');
export const HOST_DETAILS_LINK = getDataTestSubjectSelector('host-details-button');

export const USER_DETAILS_FLYOUT = getDataTestSubjectSelector('users-link-anchor');
export const USER_DETAILS_LINK = getDataTestSubjectSelector('users-link-anchor');

export const TIMELINE_DETAILS_FLYOUT = getDataTestSubjectSelector('timeline:details-panel:flyout');

export const HOST_DETAILS_FLYOUT = getDataTestSubjectSelector('host-panel-header');

export const USER_DETAILS_FLYOUT = getDataTestSubjectSelector('user-panel-header');

export const TIMELINE_DETAILS_FLYOUT_CLOSE_BTN = getDataTestSubjectSelector('euiFlyoutCloseButton');

export const TIMELINE_UNIFIED_DATA_GRID = `${getDataTestSubjectSelector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import {
GET_UNIFIED_DATA_GRID_CELL,
GET_UNIFIED_DATA_GRID_CELL_HEADER,
HOST_DETAILS_FLYOUT,
HOST_DETAILS_LINK,
TIMELINE_DETAILS_FLYOUT,
TIMELINE_DETAILS_FLYOUT_BTN,
TIMELINE_DETAILS_FLYOUT_CLOSE_BTN,
USER_DETAILS_FLYOUT,
USER_DETAILS_LINK,
} from '../screens/unified_timeline';

export const openEventDetailsFlyout = (rowIndex: number) => {
Expand All @@ -21,13 +23,13 @@ export const openEventDetailsFlyout = (rowIndex: number) => {
};

export const openHostDetailsFlyout = (rowIndex: number) => {
cy.get(HOST_DETAILS_FLYOUT).eq(rowIndex).click();
cy.get(TIMELINE_DETAILS_FLYOUT).should('be.visible');
cy.get(HOST_DETAILS_LINK).eq(rowIndex).click();
cy.get(HOST_DETAILS_FLYOUT).should('be.visible');
};

export const openUserDetailsFlyout = (rowIndex: number) => {
cy.get(USER_DETAILS_FLYOUT).eq(rowIndex).click();
cy.get(TIMELINE_DETAILS_FLYOUT).should('be.visible');
cy.get(USER_DETAILS_LINK).eq(rowIndex).click();
cy.get(USER_DETAILS_FLYOUT).should('be.visible');
};

export const getUnifiedTableHeaderColumn = (columnName: string) => {
Expand Down

0 comments on commit a4b1e9c

Please sign in to comment.