From ec16896ec98daf84d0f2a40e18a8741cac44498e Mon Sep 17 00:00:00 2001
From: Janki Salvi <117571355+js-jankisalvi@users.noreply.github.com>
Date: Fri, 28 Jul 2023 10:02:15 +0200
Subject: [PATCH] [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`
**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>
---
.../components/case_view_activity.test.tsx | 73 ++-----------------
.../apps/cases/group1/view_case.ts | 18 ++++-
2 files changed, 21 insertions(+), 70 deletions(-)
diff --git a/x-pack/plugins/cases/public/components/case_view/components/case_view_activity.test.tsx b/x-pack/plugins/cases/public/components/case_view/components/case_view_activity.test.tsx
index 130fdcf0bc1d16..d39656e9d500ec 100644
--- a/x-pack/plugins/cases/public/components/case_view/components/case_view_activity.test.tsx
+++ b/x-pack/plugins/cases/public/components/case_view/components/case_view_activity.test.tsx
@@ -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();
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();
-
- 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();
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();
-
- 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();
-
- 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();
@@ -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();
-
- 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', () => {
diff --git a/x-pack/test/functional_with_es_ssl/apps/cases/group1/view_case.ts b/x-pack/test/functional_with_es_ssl/apps/cases/group1/view_case.ts
index cc8a8a751bcb04..4acb5cb73fb04b 100644
--- a/x-pack/test/functional_with_es_ssl/apps/cases/group1/view_case.ts
+++ b/x-pack/test/functional_with_es_ssl/apps/cases/group1/view_case.ts
@@ -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 () => {