-
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
[Cases] Fix edit tags flaky tests #175763
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,7 +11,7 @@ import userEvent from '@testing-library/user-event'; | |||||
|
||||||
import type { EditTagsProps } from './edit_tags'; | ||||||
import { EditTags } from './edit_tags'; | ||||||
import { readCasesPermissions, TestProviders, createAppMockRenderer } from '../../../common/mock'; | ||||||
import { readCasesPermissions, createAppMockRenderer } from '../../../common/mock'; | ||||||
import type { AppMockRenderer } from '../../../common/mock'; | ||||||
import { useGetTags } from '../../../containers/use_get_tags'; | ||||||
import { MAX_LENGTH_PER_TAG } from '../../../../common/constants'; | ||||||
|
@@ -25,15 +25,7 @@ const defaultProps: EditTagsProps = { | |||||
tags: [], | ||||||
}; | ||||||
|
||||||
// The suite is skipped for having several flaky tests | ||||||
// See: | ||||||
// https://github.com/elastic/kibana/issues/175618 | ||||||
// https://github.com/elastic/kibana/issues/175619 | ||||||
// https://github.com/elastic/kibana/issues/175621 | ||||||
// https://github.com/elastic/kibana/issues/175622 | ||||||
// https://github.com/elastic/kibana/issues/175623 | ||||||
// https://github.com/elastic/kibana/issues/175655 | ||||||
describe.skip('EditTags ', () => { | ||||||
describe('EditTags ', () => { | ||||||
let appMockRender: AppMockRenderer; | ||||||
|
||||||
const sampleTags = ['coke', 'pepsi']; | ||||||
|
@@ -46,129 +38,121 @@ describe.skip('EditTags ', () => { | |||||
data: sampleTags, | ||||||
refetch: fetchTags, | ||||||
})); | ||||||
|
||||||
appMockRender = createAppMockRenderer(); | ||||||
}); | ||||||
|
||||||
it('renders no tags, and then edit', async () => { | ||||||
appMockRender.render(<EditTags {...defaultProps} />); | ||||||
for (let index = 0; index < 200; index++) { | ||||||
it('renders no tags, and then edit', async () => { | ||||||
appMockRender.render(<EditTags {...defaultProps} />); | ||||||
|
||||||
expect(await screen.findByTestId('no-tags')).toBeInTheDocument(); | ||||||
|
||||||
expect(screen.getByTestId('no-tags')).toBeInTheDocument(); | ||||||
userEvent.click(await screen.findByTestId('tag-list-edit-button')); | ||||||
|
||||||
userEvent.click(screen.getByTestId('tag-list-edit-button')); | ||||||
await waitFor(() => { | ||||||
expect(screen.queryByTestId('no-tags')).not.toBeInTheDocument(); | ||||||
}); | ||||||
|
||||||
await waitFor(() => { | ||||||
expect(screen.queryByTestId('no-tags')).not.toBeInTheDocument(); | ||||||
expect(screen.getByTestId('edit-tags')).toBeInTheDocument(); | ||||||
expect(await screen.findByTestId('edit-tags')).toBeInTheDocument(); | ||||||
}); | ||||||
}); | ||||||
|
||||||
it('edit tag from options on submit', async () => { | ||||||
appMockRender.render(<EditTags {...defaultProps} />); | ||||||
it('edit tag from options on submit', async () => { | ||||||
appMockRender.render(<EditTags {...defaultProps} />); | ||||||
|
||||||
userEvent.click(screen.getByTestId('tag-list-edit-button')); | ||||||
userEvent.click(await screen.findByTestId('tag-list-edit-button')); | ||||||
|
||||||
userEvent.type(screen.getByRole('combobox'), `${sampleTags[0]}{enter}`); | ||||||
userEvent.type(screen.getByRole('combobox'), `${sampleTags[0]}{enter}`); | ||||||
|
||||||
userEvent.click(screen.getByTestId('edit-tags-submit')); | ||||||
userEvent.click(await screen.findByTestId('edit-tags-submit')); | ||||||
|
||||||
await waitFor(() => expect(onSubmit).toBeCalledWith([sampleTags[0]])); | ||||||
}); | ||||||
await waitFor(() => expect(onSubmit).toBeCalledWith([sampleTags[0]])); | ||||||
}); | ||||||
|
||||||
it('add new tags on submit', async () => { | ||||||
appMockRender.render(<EditTags {...defaultProps} />); | ||||||
it('add new tags on submit', async () => { | ||||||
appMockRender.render(<EditTags {...defaultProps} />); | ||||||
|
||||||
userEvent.click(screen.getByTestId('tag-list-edit-button')); | ||||||
userEvent.click(await screen.findByTestId('tag-list-edit-button')); | ||||||
|
||||||
await waitFor(() => { | ||||||
expect(screen.getByTestId('edit-tags')).toBeInTheDocument(); | ||||||
}); | ||||||
expect(await screen.findByTestId('edit-tags')).toBeInTheDocument(); | ||||||
|
||||||
userEvent.type(screen.getByRole('combobox'), 'dude{enter}'); | ||||||
userEvent.type(screen.getByRole('combobox'), 'dude{enter}'); | ||||||
|
||||||
userEvent.click(screen.getByTestId('edit-tags-submit')); | ||||||
userEvent.click(await screen.findByTestId('edit-tags-submit')); | ||||||
|
||||||
await waitFor(() => expect(onSubmit).toBeCalledWith(['dude'])); | ||||||
}); | ||||||
await waitFor(() => expect(onSubmit).toBeCalledWith(['dude'])); | ||||||
}); | ||||||
|
||||||
it('trims the tags on submit', async () => { | ||||||
appMockRender.render(<EditTags {...defaultProps} />); | ||||||
it('trims the tags on submit', async () => { | ||||||
appMockRender.render(<EditTags {...defaultProps} />); | ||||||
|
||||||
userEvent.click(screen.getByTestId('tag-list-edit-button')); | ||||||
userEvent.click(await screen.findByTestId('tag-list-edit-button')); | ||||||
|
||||||
await waitFor(() => { | ||||||
expect(screen.getByTestId('edit-tags')).toBeInTheDocument(); | ||||||
}); | ||||||
expect(await screen.findByTestId('edit-tags')).toBeInTheDocument(); | ||||||
|
||||||
userEvent.type(screen.getByRole('combobox'), 'dude {enter}'); | ||||||
userEvent.type(screen.getByRole('combobox'), 'dude {enter}'); | ||||||
|
||||||
userEvent.click(screen.getByTestId('edit-tags-submit')); | ||||||
userEvent.click(await screen.findByTestId('edit-tags-submit')); | ||||||
|
||||||
await waitFor(() => expect(onSubmit).toBeCalledWith(['dude'])); | ||||||
}); | ||||||
await waitFor(() => expect(onSubmit).toBeCalledWith(['dude'])); | ||||||
}); | ||||||
|
||||||
it('cancels on cancel', async () => { | ||||||
appMockRender.render(<EditTags {...defaultProps} />); | ||||||
it('cancels on cancel', async () => { | ||||||
appMockRender.render(<EditTags {...defaultProps} />); | ||||||
|
||||||
userEvent.click(screen.getByTestId('tag-list-edit-button')); | ||||||
userEvent.click(await screen.findByTestId('tag-list-edit-button')); | ||||||
|
||||||
userEvent.type(screen.getByRole('combobox'), 'new{enter}'); | ||||||
userEvent.type(screen.getByRole('combobox'), 'new{enter}'); | ||||||
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.
|
||||||
|
||||||
await waitFor(() => { | ||||||
expect(screen.getByTestId('comboBoxInput')).toHaveTextContent('new'); | ||||||
}); | ||||||
expect(await screen.findByTestId('comboBoxInput')).toHaveTextContent('new'); | ||||||
|
||||||
userEvent.click(await screen.findByTestId('edit-tags-cancel')); | ||||||
|
||||||
userEvent.click(screen.getByTestId('edit-tags-cancel')); | ||||||
await waitFor(() => { | ||||||
expect(onSubmit).not.toBeCalled(); | ||||||
}); | ||||||
|
||||||
await waitFor(() => { | ||||||
expect(onSubmit).not.toBeCalled(); | ||||||
expect(screen.getByTestId('no-tags')).toBeInTheDocument(); | ||||||
expect(await screen.findByTestId('no-tags')).toBeInTheDocument(); | ||||||
}); | ||||||
}); | ||||||
|
||||||
it('shows error when tag is empty', async () => { | ||||||
appMockRender.render(<EditTags {...defaultProps} />); | ||||||
it('shows error when tag is empty', async () => { | ||||||
appMockRender.render(<EditTags {...defaultProps} />); | ||||||
|
||||||
userEvent.click(screen.getByTestId('tag-list-edit-button')); | ||||||
userEvent.click(await screen.findByTestId('tag-list-edit-button')); | ||||||
|
||||||
await waitFor(() => { | ||||||
expect(screen.getByTestId('edit-tags')).toBeInTheDocument(); | ||||||
}); | ||||||
expect(await screen.findByTestId('edit-tags')).toBeInTheDocument(); | ||||||
|
||||||
userEvent.type(screen.getByRole('combobox'), ' {enter}'); | ||||||
userEvent.type(screen.getByRole('combobox'), ' {enter}'); | ||||||
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.
|
||||||
|
||||||
await waitFor(() => { | ||||||
expect(screen.getByText('A tag must contain at least one non-space character.')); | ||||||
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.
Suggested change
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. Done! |
||||||
}); | ||||||
}); | ||||||
|
||||||
it('shows error when tag is too long', async () => { | ||||||
const longTag = 'z'.repeat(MAX_LENGTH_PER_TAG + 1); | ||||||
it('shows error when tag is too long', async () => { | ||||||
const longTag = 'z'.repeat(MAX_LENGTH_PER_TAG + 1); | ||||||
|
||||||
appMockRender.render(<EditTags {...defaultProps} />); | ||||||
appMockRender.render(<EditTags {...defaultProps} />); | ||||||
|
||||||
userEvent.click(screen.getByTestId('tag-list-edit-button')); | ||||||
userEvent.click(await screen.findByTestId('tag-list-edit-button')); | ||||||
|
||||||
await waitFor(() => { | ||||||
expect(screen.getByTestId('edit-tags')).toBeInTheDocument(); | ||||||
}); | ||||||
expect(await screen.findByTestId('edit-tags')).toBeInTheDocument(); | ||||||
|
||||||
userEvent.paste(screen.getByRole('combobox'), `${longTag}`); | ||||||
userEvent.keyboard('{enter}'); | ||||||
userEvent.paste(screen.getByRole('combobox'), `${longTag}`); | ||||||
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.
|
||||||
userEvent.keyboard('{enter}'); | ||||||
|
||||||
await waitFor(() => { | ||||||
expect( | ||||||
screen.getByText('The length of the tag is too long. The maximum length is 256 characters.') | ||||||
); | ||||||
await waitFor(() => { | ||||||
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. Is the 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. Thanks for catching this. I forgot them. I fixed it in |
||||||
expect( | ||||||
screen.getByText( | ||||||
'The length of the tag is too long. The maximum length is 256 characters.' | ||||||
) | ||||||
); | ||||||
}); | ||||||
}); | ||||||
}); | ||||||
|
||||||
it('does not render when the user does not have update permissions', () => { | ||||||
appMockRender.render( | ||||||
<TestProviders permissions={readCasesPermissions()}> | ||||||
<EditTags {...defaultProps} /> | ||||||
</TestProviders> | ||||||
); | ||||||
it('does not render when the user does not have update permissions', () => { | ||||||
appMockRender = createAppMockRenderer({ permissions: readCasesPermissions() }); | ||||||
appMockRender.render(<EditTags {...defaultProps} />); | ||||||
|
||||||
expect(screen.queryByTestId('tag-list-edit')).not.toBeInTheDocument(); | ||||||
}); | ||||||
expect(screen.queryByTestId('tag-list-edit')).not.toBeInTheDocument(); | ||||||
}); | ||||||
} | ||||||
}); |
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.
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.
I forgot them, thanks!
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.
Done!