[Cases] Fix case view sort order flaky test (#162613)

## Summary

Fixes https://github.com/elastic/kibana/issues/152202



Old Test | Where is it covered
-- | --
should render by desc sort order | covered by [e2e test `sorts by newest
first successfully`
](https://github.com/elastic/kibana/blob/main/x-pack/test/functional_with_es_ssl/apps/cases/group1/view_case.ts)
should show all filter as active | Moved to e2e test `filters by all by
default`
should show comment filter as active | Added check in e2e test `filters
by comment successfully`
should show history as active filter correctly | Added check in e2e test
`filters by history successfully`

<br class="Apple-interchange-newline">

**Flaky test runner:**
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2735

## Checklist
Delete any items that are not applicable to this PR.

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

## For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Janki Salvi 2023-07-28 10:02:15 +02:00 committed by GitHub
parent 633a466336
commit ec16896ec9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 70 deletions

View file

@ -7,7 +7,7 @@
import React from 'react';
import userEvent from '@testing-library/user-event';
import { screen, waitFor, within, fireEvent } from '@testing-library/react';
import { screen, waitFor, within } from '@testing-library/react';
import { licensingMock } from '@kbn/licensing-plugin/public/mocks';
import {
alertComment,
@ -313,8 +313,7 @@ describe('Case View Page activity tab', () => {
expect(await screen.findByTestId('case-view-edit-connector')).toBeInTheDocument();
});
// FLAKY: https://github.com/elastic/kibana/issues/152202
describe.skip('filter activity', () => {
describe('filter activity', () => {
beforeEach(() => {
jest.clearAllMocks();
useFindCaseUserActionsMock.mockReturnValue(defaultUseFindCaseUserActions);
@ -325,13 +324,12 @@ describe('Case View Page activity tab', () => {
});
});
it('should show all filter as active', async () => {
it('should call user action hooks correctly when filtering for all', async () => {
appMockRender.render(<CaseViewActivity {...caseProps} />);
const lastPageForAll = Math.ceil(userActionsStats.total / userActivityQueryParams.perPage);
expect(await screen.findByTestId('user-actions-activity-bar'));
userEvent.click(screen.getByTestId('user-actions-filter-activity-button-all'));
userEvent.click(await screen.findByTestId('user-actions-filter-activity-button-all'));
expect(useInfiniteFindCaseUserActionsMock).toHaveBeenCalledWith(
caseData.id,
@ -348,25 +346,14 @@ describe('Case View Page activity tab', () => {
expect(useGetCaseUserActionsStatsMock).toHaveBeenCalledWith(caseData.id);
});
it('should call user action hooks correctly when filtering for all', async () => {
appMockRender.render(<CaseViewActivity {...caseProps} />);
userEvent.click(await screen.findByTestId('user-actions-filter-activity-button-all'));
expect(screen.getByLabelText(`${userActionsStats.total} active filters`));
expect(screen.getByLabelText(`${userActionsStats.totalComments} available filters`));
expect(screen.getByLabelText(`${userActionsStats.totalOtherActions} available filters`));
});
it('should show comment filter as active', async () => {
it('should call user action hooks correctly when filtering for comments', async () => {
appMockRender.render(<CaseViewActivity {...caseProps} />);
const lastPageForComment = Math.ceil(
userActionsStats.totalComments / userActivityQueryParams.perPage
);
expect(await screen.findByTestId('user-actions-activity-bar'));
userEvent.click(screen.getByTestId('user-actions-filter-activity-button-comments'));
userEvent.click(await screen.findByTestId('user-actions-filter-activity-button-comments'));
expect(useGetCaseUserActionsStatsMock).toHaveBeenCalledWith(caseData.id);
expect(useInfiniteFindCaseUserActionsMock).toHaveBeenCalledWith(
@ -381,28 +368,6 @@ describe('Case View Page activity tab', () => {
);
});
it('should call user action hooks correctly when filtering for comments', async () => {
appMockRender.render(<CaseViewActivity {...caseProps} />);
expect(await screen.findByTestId('user-actions-activity-bar'));
userEvent.click(screen.getByTestId('user-actions-filter-activity-button-comments'));
expect(screen.getByLabelText(`${userActionsStats.totalComments} active filters`));
expect(screen.getByLabelText(`${userActionsStats.total} available filters`));
expect(screen.getByLabelText(`${userActionsStats.totalOtherActions} available filters`));
});
it('should show history as active filter correctly', async () => {
appMockRender.render(<CaseViewActivity {...caseProps} />);
expect(await screen.findByTestId('user-actions-activity-bar'));
userEvent.click(screen.getByTestId('user-actions-filter-activity-button-history'));
expect(screen.getByLabelText(`${userActionsStats.totalOtherActions} active filters`));
expect(screen.getByLabelText(`${userActionsStats.totalComments} available filters`));
expect(screen.getByLabelText(`${userActionsStats.total} available filters`));
});
it('should call user action hooks correctly when filtering for history', async () => {
appMockRender.render(<CaseViewActivity {...caseProps} />);
@ -410,8 +375,7 @@ describe('Case View Page activity tab', () => {
userActionsStats.totalOtherActions / userActivityQueryParams.perPage
);
expect(await screen.findByTestId('user-actions-activity-bar'));
userEvent.click(screen.getByTestId('user-actions-filter-activity-button-history'));
userEvent.click(await screen.findByTestId('user-actions-filter-activity-button-history'));
expect(useGetCaseUserActionsStatsMock).toHaveBeenCalledWith(caseData.id);
expect(useInfiniteFindCaseUserActionsMock).toHaveBeenCalledWith(
@ -425,29 +389,6 @@ describe('Case View Page activity tab', () => {
true
);
});
it('should render by desc sort order', async () => {
appMockRender.render(<CaseViewActivity {...caseProps} />);
const sortSelect = await screen.findByTestId('user-actions-sort-select');
fireEvent.change(sortSelect, { target: { value: 'desc' } });
await waitFor(() => {
expect(useGetCaseUserActionsStatsMock).toHaveBeenCalledWith(caseData.id);
expect(useFindCaseUserActionsMock).toHaveBeenCalledWith(
caseData.id,
{ type: 'all', sortOrder: 'desc', page: 3, perPage: 10 },
true
);
expect(useInfiniteFindCaseUserActionsMock).toHaveBeenCalledWith(
caseData.id,
{ type: 'all', sortOrder: 'desc', page: 1, perPage: 10 },
true
);
});
});
});
describe('Case users', () => {

View file

@ -635,12 +635,20 @@ export default ({ getPageObject, getService }: FtrProviderContext) => {
describe('filter activity', () => {
createOneCaseBeforeDeleteAllAfter(getPageObject, getService);
it('filters by all by default', async () => {
const allBadge = await find.byCssSelector(
'[data-test-subj="user-actions-filter-activity-button-all"] span.euiNotificationBadge'
);
expect(await allBadge.getAttribute('aria-label')).equal('1 active filters');
});
it('filters by comment successfully', async () => {
const commentBadge = await find.byCssSelector(
'[data-test-subj="user-actions-filter-activity-button-comments"] span.euiNotificationBadge'
);
expect(await commentBadge.getVisibleText()).equal('0');
expect(await commentBadge.getAttribute('aria-label')).equal('0 available filters');
const commentArea = await find.byCssSelector(
'[data-test-subj="add-comment"] textarea.euiMarkdownEditorTextArea'
@ -651,7 +659,9 @@ export default ({ getPageObject, getService }: FtrProviderContext) => {
await header.waitUntilLoadingHasFinished();
expect(await commentBadge.getVisibleText()).equal('1');
await testSubjects.click('user-actions-filter-activity-button-comments');
expect(await commentBadge.getAttribute('aria-label')).equal('1 active filters');
});
it('filters by history successfully', async () => {
@ -659,7 +669,7 @@ export default ({ getPageObject, getService }: FtrProviderContext) => {
'[data-test-subj="user-actions-filter-activity-button-history"] span.euiNotificationBadge'
);
expect(await historyBadge.getVisibleText()).equal('1');
expect(await historyBadge.getAttribute('aria-label')).equal('1 available filters');
await cases.common.selectSeverity(CaseSeverity.MEDIUM);
@ -669,7 +679,7 @@ export default ({ getPageObject, getService }: FtrProviderContext) => {
await testSubjects.click('user-actions-filter-activity-button-history');
expect(await historyBadge.getVisibleText()).equal('3');
expect(await historyBadge.getAttribute('aria-label')).equal('3 active filters');
});
it('sorts by newest first successfully', async () => {