Skip to content

Commit

Permalink
Merge branch 'main' into private-run-once
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Jul 28, 2023
2 parents fe697c2 + ec16896 commit 8a1a0d1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -381,37 +368,14 @@ 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} />);

const lastPageForHistory = Math.ceil(
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(
Expand All @@ -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', () => {
Expand Down
18 changes: 14 additions & 4 deletions x-pack/test/functional_with_es_ssl/apps/cases/group1/view_case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -651,15 +659,17 @@ 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 () => {
const historyBadge = await find.byCssSelector(
'[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);

Expand All @@ -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 () => {
Expand Down

0 comments on commit 8a1a0d1

Please sign in to comment.