[Cases] Fix case view participants tests (#162612)

## Summary

I removed the participants' tests from
`x-pack/plugins/cases/public/components/case_view/components/case_view_activity.test.tsx`

There were a few things being tested:

| Old Test  | Where is it covered |
| ------------- | ------------- |
| should render the participants correctly  | Moved to an e2e test |
| should render Unknown users correctly  | Moved to  `UserList` |
| should render assignees in the participants section | Moved to an e2e
test |

I also added a small test for reporters.

Fixes #152204
Flaky test runner:
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2734

### 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: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Christos Nasikas 2023-07-28 11:40:14 +03:00 committed by GitHub
parent ec16896ec9
commit 08db8eeece
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 229 additions and 69 deletions

View file

@ -392,51 +392,6 @@ describe('Case View Page activity tab', () => {
});
describe('Case users', () => {
// FLAKY: https://github.com/elastic/kibana/issues/152204
describe.skip('Participants', () => {
it('should render the participants correctly', async () => {
appMockRender = createAppMockRenderer();
appMockRender.render(<CaseViewActivity {...caseProps} />);
const participantsSection = within(
await screen.findByTestId('case-view-user-list-participants')
);
expect(await participantsSection.findByText('Participant 1')).toBeInTheDocument();
expect(
await participantsSection.findByText('participant_2@elastic.co')
).toBeInTheDocument();
expect(await participantsSection.findByText('participant_3')).toBeInTheDocument();
expect(await participantsSection.findByText('P4')).toBeInTheDocument();
expect(await participantsSection.findByText('Participant 5')).toBeInTheDocument();
});
it('should render Unknown users correctly', async () => {
appMockRender = createAppMockRenderer();
appMockRender.render(<CaseViewActivity {...caseProps} />);
const participantsSection = within(
await screen.findByTestId('case-view-user-list-participants')
);
expect(await participantsSection.findByText('Unknown')).toBeInTheDocument();
});
it('should render assignees in the participants section', async () => {
appMockRender = createAppMockRenderer();
appMockRender.render(<CaseViewActivity {...caseProps} />);
const participantsSection = within(
await screen.findByTestId('case-view-user-list-participants')
);
expect(await participantsSection.findByText('Unknown')).toBeInTheDocument();
expect(await participantsSection.findByText('Fuzzy Marten')).toBeInTheDocument();
expect(await participantsSection.findByText('elastic')).toBeInTheDocument();
expect(await participantsSection.findByText('Misty Mackerel')).toBeInTheDocument();
});
});
describe('Assignees', () => {
it('should render assignees in the participants section', async () => {
appMockRender = createAppMockRenderer({ license: platinumLicense });

View file

@ -6,6 +6,7 @@
*/
import React from 'react';
import { screen } from '@testing-library/react';
import { UserList } from './user_list';
import * as i18n from '../translations';
import { basicCase } from '../../../containers/mock';
@ -13,6 +14,7 @@ import { useCaseViewNavigation } from '../../../common/navigation/hooks';
import type { AppMockRenderer } from '../../../common/mock';
import { createAppMockRenderer } from '../../../common/mock';
import userEvent from '@testing-library/user-event';
import { userProfilesMap } from '../../../containers/user_profiles/api.mock';
jest.mock('../../../common/navigation/hooks');
@ -39,7 +41,7 @@ describe('UserList ', () => {
});
it('triggers mailto when email icon clicked', () => {
const result = appMockRender.render(
appMockRender.render(
<UserList
theCase={basicCase}
headline={i18n.REPORTER}
@ -51,7 +53,7 @@ describe('UserList ', () => {
/>
);
userEvent.click(result.getByTestId('user-list-email-button'));
userEvent.click(screen.getByTestId('user-list-email-button'));
expect(open).toBeCalledWith(
`mailto:${user.email}?subject=${i18n.EMAIL_SUBJECT(title)}&body=${i18n.EMAIL_BODY(caseLink)}`,
@ -60,28 +62,131 @@ describe('UserList ', () => {
});
it('sort the users correctly', () => {
const result = appMockRender.render(
appMockRender.render(
<UserList
theCase={basicCase}
headline={i18n.REPORTER}
users={[
{
user: { ...user, username: 'test', full_name: null, email: null },
},
{
user: { ...user, full_name: 'Cases' },
},
{
user: { ...user, username: 'elastic', email: 'elastic@elastic.co', full_name: null },
},
]}
/>
);
const users = screen.getAllByTestId('user-profile-username');
expect(users[0].textContent).toBe('Cases');
expect(users[1].textContent).toBe('elastic@elastic.co');
expect(users[2].textContent).toBe('test');
});
it('return null if no users', () => {
const result = appMockRender.render(
<UserList theCase={basicCase} headline={i18n.REPORTER} users={[]} />
);
expect(result.container).toBeEmptyDOMElement();
});
it('shows the loading spinner if loading', () => {
appMockRender.render(
<UserList
theCase={basicCase}
headline={i18n.REPORTER}
users={[
{
user: { ...user, username: 'test', full_name: null, email: null },
user: { ...user, full_name: user.fullName },
},
]}
loading={true}
/>
);
expect(screen.getByTestId('users-list-loading-spinner')).toBeEmptyDOMElement();
});
it('should render users with user profiles correctly', () => {
appMockRender.render(
<UserList
theCase={basicCase}
headline={i18n.REPORTER}
userProfiles={userProfilesMap}
users={[
{
user: {
username: null,
email: null,
full_name: null,
},
uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0',
},
]}
/>
);
const userProfiles = result.getAllByTestId('user-profile-username');
const userElement = screen.getByTestId('user-profile-username');
expect(userElement.textContent).toBe('Damaged Raccoon');
});
expect(userProfiles[0].textContent).toBe('Cases');
expect(userProfiles[1].textContent).toBe('elastic@elastic.co');
expect(userProfiles[2].textContent).toBe('test');
it('should not render invalid users', () => {
appMockRender.render(
<UserList
theCase={basicCase}
headline={i18n.REPORTER}
userProfiles={userProfilesMap}
users={[
{
user: {
username: null,
email: null,
full_name: null,
uid: null,
},
},
{
user: {
username: 'damaged_raccoon',
email: 'damaged_raccoon@elastic.co',
full_name: 'Damaged Raccoon',
},
uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0',
},
]}
/>
);
const users = screen.getAllByTestId('user-profile-username');
expect(users.length).toBe(1);
expect(users[0].textContent).toBe('Damaged Raccoon');
});
it('should render Unknown users correctly', () => {
appMockRender.render(
<UserList
theCase={basicCase}
headline={i18n.REPORTER}
userProfiles={userProfilesMap}
users={[
{
user: {
username: null,
email: null,
full_name: null,
},
uid: 'not-exist',
},
]}
/>
);
expect(screen.getByTestId('user-profile-username').textContent).toBe('Unknown');
});
});

View file

@ -106,7 +106,7 @@ export const UserList: React.FC<UserListProps> = React.memo(
{loading && (
<EuiFlexGroup>
<EuiFlexItem>
<EuiLoadingSpinner />
<EuiLoadingSpinner data-test-subj="users-list-loading-spinner" />
</EuiFlexItem>
</EuiFlexGroup>
)}

View file

@ -25,7 +25,7 @@ export const convertToUserInfo = (
// we couldn't find a valid profile so let's try the username
return createWithUsername(username, user);
} else {
// didn't the username wasn't valid so we'll show an unknown user
// the username wasn't valid so we'll show an unknown user
return { key: user.profileUid, userInfo: {} };
}
} else if (isValidString(username)) {

View file

@ -24,13 +24,22 @@ import { User } from '../../../cases_api_integration/common/lib/authentication/t
import { FtrProviderContext } from '../../ftr_provider_context';
import { generateRandomCaseWithoutConnector } from './helpers';
type OmitSupertest<T> = Omit<T, 'supertest'>;
type GetParams<T extends (...args: any) => any> = Omit<Parameters<T>[0], 'supertest'>;
export function CasesAPIServiceProvider({ getService }: FtrProviderContext) {
const kbnSupertest = getService('supertest');
const es = getService('es');
const supertestWithoutAuth = getService('supertestWithoutAuth');
const getSuperTest = (hasAuth: boolean) => (hasAuth ? supertestWithoutAuth : kbnSupertest);
const createApiFunction =
<T extends (...args: any) => any>(apiFunc: T) =>
(params: GetParams<typeof apiFunc>): ReturnType<typeof apiFunc> => {
const supertest = getSuperTest(Boolean(params.auth));
return apiFunc({ supertest, ...params });
};
return {
async createCase(overwrites: Partial<CasePostRequest> = {}): Promise<Case> {
const caseData = {
@ -56,15 +65,7 @@ export function CasesAPIServiceProvider({ getService }: FtrProviderContext) {
await deleteAllCaseItems(es);
},
async createAttachment({
caseId,
params,
}: {
caseId: Parameters<typeof createComment>[0]['caseId'];
params: Parameters<typeof createComment>[0]['params'];
}): Promise<Case> {
return createComment({ supertest: kbnSupertest, params, caseId });
},
createAttachment: createApiFunction(createComment),
async setStatus(
caseId: string,
@ -96,9 +97,7 @@ export function CasesAPIServiceProvider({ getService }: FtrProviderContext) {
return suggestUserProfiles({ supertest: kbnSupertest, req: options });
},
async getCase({ caseId }: OmitSupertest<Parameters<typeof getCase>[0]>): Promise<Case> {
return getCase({ supertest: kbnSupertest, caseId });
},
getCase: createApiFunction(getCase),
async generateUserActions({
caseId,

View file

@ -143,5 +143,31 @@ export function CasesSingleViewServiceProvider({ getService, getPageObject }: Ft
await testSubjects.missingOrFail('euiSelectableList');
});
},
async refresh() {
await testSubjects.click('case-refresh');
},
async getReporter() {
await testSubjects.existOrFail('case-view-user-list-reporter');
const reporter = await testSubjects.findAllDescendant(
'user-profile-username',
await testSubjects.find('case-view-user-list-reporter')
);
return reporter[0];
},
async getParticipants() {
await testSubjects.existOrFail('case-view-user-list-participants');
const participants = await testSubjects.findAllDescendant(
'user-profile-username',
await testSubjects.find('case-view-user-list-participants')
);
return participants;
},
};
}

View file

@ -7,7 +7,7 @@
import expect from '@kbn/expect';
import { v4 as uuidv4 } from 'uuid';
import { CaseSeverity, CaseStatuses } from '@kbn/cases-plugin/common/types/domain';
import { AttachmentType, CaseSeverity, CaseStatuses } from '@kbn/cases-plugin/common/types/domain';
import { setTimeout as setTimeoutAsync } from 'timers/promises';
import { FtrProviderContext } from '../../../ftr_provider_context';
@ -981,6 +981,81 @@ export default ({ getPageObject, getService }: FtrProviderContext) => {
expect(lastBreadcrumb).to.be(theCase.title);
});
});
describe('reporter', () => {
createOneCaseBeforeDeleteAllAfter(getPageObject, getService);
it('should render the reporter correctly', async () => {
const reporter = await cases.singleCase.getReporter();
const reporterText = await reporter.getVisibleText();
expect(reporterText).to.be('elastic');
});
});
describe('participants', () => {
before(async () => {
await createUsersAndRoles(getService, users, roles);
await cases.api.activateUserProfiles([casesAllUser, casesAllUser2]);
});
afterEach(async () => {
await cases.api.deleteAllCases();
});
after(async () => {
await deleteUsersAndRoles(getService, users, roles);
});
it('should render the participants correctly', async () => {
const theCase = await createAndNavigateToCase(getPageObject, getService);
await cases.api.createAttachment({
caseId: theCase.id,
params: {
type: AttachmentType.user,
comment: 'test',
owner: 'cases',
},
auth: { user: casesAllUser, space: 'default' },
});
await cases.singleCase.refresh();
await header.waitUntilLoadingHasFinished();
const participants = await cases.singleCase.getParticipants();
const casesAllUserText = await participants[0].getVisibleText();
const elasticUserText = await participants[1].getVisibleText();
expect(casesAllUserText).to.be('cases all_user');
expect(elasticUserText).to.be('elastic');
});
it('should render assignees in the participants section', async () => {
await createAndNavigateToCase(getPageObject, getService);
await cases.singleCase.openAssigneesPopover();
await cases.common.setSearchTextInAssigneesPopover('case');
await cases.common.selectFirstRowInAssigneesPopover();
await cases.singleCase.closeAssigneesPopover();
await header.waitUntilLoadingHasFinished();
await testSubjects.existOrFail('user-profile-assigned-user-cases_all_user-remove-group');
const participants = await cases.singleCase.getParticipants();
expect(participants.length).to.be(3);
// The assignee
const casesAllUserText = await participants[0].getVisibleText();
const elasticUserText = await participants[1].getVisibleText();
const testUserText = await participants[2].getVisibleText();
expect(casesAllUserText).to.be('cases all_user');
expect(elasticUserText).to.be('elastic');
expect(testUserText).to.be('test user');
});
});
});
};