-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ResponseOps][Cases] Add assignee user actions #139392
Merged
jonathan-buttner
merged 13 commits into
elastic:cases-user-assignment
from
jonathan-buttner:cases-assignee-user-actions-v2
Aug 31, 2022
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6db3d1c
Adding user actions for assignees
jonathan-buttner 0198583
Fixing merge issues
jonathan-buttner f4061a0
Fixing test mock errors
jonathan-buttner 75168d2
Merge branch 'cases-user-assignment' into cases-assignee-user-actions-v2
kibanamachine 0a0d0e0
Fixing display name errors and themselves
jonathan-buttner 22cd14e
Fixing test for time being
jonathan-buttner 039447c
Merge branch 'cases-user-assignment' into cases-assignee-user-actions-v2
kibanamachine 9ca5a6a
Addressing feedback
jonathan-buttner a5c37d7
Addressing comma and uniq feedback
jonathan-buttner 77491ff
Using core getUserDisplayName
jonathan-buttner ae3f44b
Fixing import and removing flickering
jonathan-buttner 356a966
Fixing tests
jonathan-buttner d4252a6
Merge branch 'cases-user-assignment' into cases-assignee-user-actions-v2
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
x-pack/plugins/cases/public/components/user_actions/assignees.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiCommentList } from '@elastic/eui'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { Actions } from '../../../common/api'; | ||
import { elasticUser, getUserAction } from '../../containers/mock'; | ||
import { TestProviders } from '../../common/mock'; | ||
import { createAssigneesUserActionBuilder } from './assignees'; | ||
import { getMockBuilderArgs } from './mock'; | ||
|
||
jest.mock('../../common/lib/kibana'); | ||
jest.mock('../../common/navigation/hooks'); | ||
|
||
describe('createAssigneesUserActionBuilder', () => { | ||
const builderArgs = getMockBuilderArgs(); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('renders assigned users', () => { | ||
const userAction = getUserAction('assignees', Actions.add, { | ||
createdBy: { | ||
// damaged_raccoon uid | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😄 |
||
profileUid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0', | ||
}, | ||
}); | ||
const builder = createAssigneesUserActionBuilder({ | ||
...builderArgs, | ||
userAction, | ||
}); | ||
|
||
const createdUserAction = builder.build(); | ||
render( | ||
<TestProviders> | ||
<EuiCommentList comments={createdUserAction} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(screen.getByText('assigned')).toBeInTheDocument(); | ||
expect(screen.getByText('themselves,')).toBeInTheDocument(); | ||
expect(screen.getByText('Physical Dinosaur')).toBeInTheDocument(); | ||
|
||
expect(screen.getByTestId('ua-assignee-physical_dinosaur')).toContainElement( | ||
screen.getByText('and') | ||
); | ||
}); | ||
|
||
it('renders unassigned users', () => { | ||
const userAction = getUserAction('assignees', Actions.delete, { | ||
createdBy: { | ||
// damaged_raccoon uid | ||
profileUid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0', | ||
}, | ||
}); | ||
const builder = createAssigneesUserActionBuilder({ | ||
...builderArgs, | ||
userAction, | ||
}); | ||
|
||
const createdUserAction = builder.build(); | ||
render( | ||
<TestProviders> | ||
<EuiCommentList comments={createdUserAction} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(screen.getByText('unassigned')).toBeInTheDocument(); | ||
expect(screen.getByText('themselves,')).toBeInTheDocument(); | ||
expect(screen.getByText('Physical Dinosaur')).toBeInTheDocument(); | ||
|
||
expect(screen.getByTestId('ua-assignee-physical_dinosaur')).toContainElement( | ||
screen.getByText('and') | ||
); | ||
}); | ||
|
||
it('renders a single assigned user', () => { | ||
const userAction = getUserAction('assignees', Actions.add, { | ||
payload: { | ||
assignees: [ | ||
// only render the physical dinosaur | ||
{ uid: 'u_A_tM4n0wPkdiQ9smmd8o0Hr_h61XQfu8aRPh9GMoRoc_0' }, | ||
], | ||
}, | ||
}); | ||
const builder = createAssigneesUserActionBuilder({ | ||
...builderArgs, | ||
userAction, | ||
}); | ||
|
||
const createdUserAction = builder.build(); | ||
render( | ||
<TestProviders> | ||
<EuiCommentList comments={createdUserAction} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(screen.getByText('Physical Dinosaur')).toBeInTheDocument(); | ||
expect(screen.queryByText('themselves,')).not.toBeInTheDocument(); | ||
expect(screen.queryByText('and')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('renders a single assigned user that is themselves using matching profile uids', () => { | ||
const userAction = getUserAction('assignees', Actions.add, { | ||
createdBy: { | ||
...elasticUser, | ||
profileUid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0', | ||
}, | ||
payload: { | ||
assignees: [ | ||
// only render the damaged raccoon which is the current user | ||
{ uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0' }, | ||
], | ||
}, | ||
}); | ||
const builder = createAssigneesUserActionBuilder({ | ||
...builderArgs, | ||
userAction, | ||
}); | ||
|
||
const createdUserAction = builder.build(); | ||
render( | ||
<TestProviders> | ||
<EuiCommentList comments={createdUserAction} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(screen.getByText('themselves')).toBeInTheDocument(); | ||
expect(screen.queryByText('Physical Dinosaur')).not.toBeInTheDocument(); | ||
expect(screen.queryByText('and')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('renders a single assigned user that is themselves using matching usernames', () => { | ||
const userAction = getUserAction('assignees', Actions.add, { | ||
createdBy: { | ||
...elasticUser, | ||
username: 'damaged_raccoon', | ||
}, | ||
payload: { | ||
assignees: [ | ||
// only render the damaged raccoon which is the current user | ||
{ uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0' }, | ||
], | ||
}, | ||
}); | ||
const builder = createAssigneesUserActionBuilder({ | ||
...builderArgs, | ||
userAction, | ||
}); | ||
|
||
const createdUserAction = builder.build(); | ||
render( | ||
<TestProviders> | ||
<EuiCommentList comments={createdUserAction} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(screen.getByText('themselves')).toBeInTheDocument(); | ||
expect(screen.queryByText('Physical Dinosaur')).not.toBeInTheDocument(); | ||
expect(screen.queryByText('and')).not.toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between
rt.partial({ profile_uid: rt.string })
andprofile_uid: rt.union([rt.undefined, rt.null, rt.string])
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By using a
partial
we don't have to set theprofile_uid
wherever a user object is defined. That way we can avoid updating all the locations in the code where we create a user object. I believe we can also avoid writing a migration.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense. Thanks!