Skip to content

Commit

Permalink
[Cases] Fix jira flaky tests (#170507)
Browse files Browse the repository at this point in the history
Fixes #169392
Fixes #169393
Fixes #169391 
Fixes #169390 
Fixes #169387 
Fixes #169386 
Fixes #169385 
Fixes #169384 
Fixes #169383

## Summary

Summarize your PR. If it involves visual changes include a screenshot or
gif.
  • Loading branch information
adcoelho committed Nov 6, 2023
1 parent 22a2bfe commit 25522bb
Showing 1 changed file with 43 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ describe('Jira Fields', () => {
</MockFormWrapperComponent>
);

expect(await screen.findByTestId('prioritySelect')).toBeInTheDocument();
expect(await screen.findByTestId('issueTypeSelect')).toBeInTheDocument();

await waitFor(() => {
expect(screen.getByTestId('prioritySelect')).toBeInTheDocument();
expect(screen.getByTestId('issueTypeSelect')).toBeInTheDocument();
expect(screen.queryByTestId('search-parent-issues')).toBeInTheDocument();
});
});
Expand All @@ -115,15 +116,15 @@ describe('Jira Fields', () => {
</MockFormWrapperComponent>
);

const issueTypeSelect = screen.getByTestId('issueTypeSelect');
const issueTypeSelect = await screen.findByTestId('issueTypeSelect');
expect(issueTypeSelect).toBeInTheDocument();

userEvent.selectOptions(issueTypeSelect, 'Task');

await waitFor(() => {
expect(screen.getByTestId('prioritySelect')).toBeInTheDocument();
expect(screen.getByTestId('search-parent-issues')).toBeInTheDocument();
fireEvent.change(issueTypeSelect, {
target: { value: 'Task' },
});

expect(await screen.findByTestId('prioritySelect')).toBeInTheDocument();
expect(await screen.findByTestId('search-parent-issues')).toBeInTheDocument();
});

it('sets parent correctly', async () => {
Expand All @@ -132,7 +133,7 @@ describe('Jira Fields', () => {
<Fields connector={connector} />
</MockFormWrapperComponent>
);
const input = screen.getByTestId('comboBoxSearchInput');
const input = await screen.findByTestId('comboBoxSearchInput');

fireEvent.change(input, { target: { value: 'parentId' } });

Expand All @@ -146,15 +147,18 @@ describe('Jira Fields', () => {
</MockFormWrapperComponent>
);

const checkbox = within(screen.getByTestId('search-parent-issues')).getByTestId(
const checkbox = within(await screen.findByTestId('search-parent-issues')).getByTestId(
'comboBoxSearchInput'
);

userEvent.type(checkbox, 'Person Task{enter}');
expect(checkbox).toHaveValue('Person Task');
fireEvent.change(checkbox, {
target: { value: 'Person Task{enter}' },
});

expect(checkbox).toHaveValue('Person Task{enter}');
});

it('disabled the fields when loading issue types', () => {
it('disabled the fields when loading issue types', async () => {
useGetIssueTypesMock.mockReturnValue({ ...useGetIssueTypesResponse, isLoading: true });

appMockRenderer.render(
Expand All @@ -163,11 +167,11 @@ describe('Jira Fields', () => {
</MockFormWrapperComponent>
);

expect(screen.getByTestId('issueTypeSelect')).toBeDisabled();
expect(screen.getByTestId('prioritySelect')).toBeDisabled();
expect(await screen.findByTestId('issueTypeSelect')).toBeDisabled();
expect(await screen.findByTestId('prioritySelect')).toBeDisabled();
});

it('disabled the priority when loading fields', () => {
it('disabled the priority when loading fields', async () => {
useGetFieldsByIssueTypeMock.mockReturnValue({
...useGetFieldsByIssueTypeResponse,
isLoading: true,
Expand All @@ -179,7 +183,7 @@ describe('Jira Fields', () => {
</MockFormWrapperComponent>
);

expect(screen.getByTestId('prioritySelect')).toBeDisabled();
expect(await screen.findByTestId('prioritySelect')).toBeDisabled();
});

it('hides the priority if not supported', () => {
Expand Down Expand Up @@ -210,27 +214,27 @@ describe('Jira Fields', () => {
expect(screen.queryByTestId('search-parent-issues')).not.toBeVisible();
});

it('sets issue type correctly', () => {
it('sets issue type correctly', async () => {
appMockRenderer.render(
<MockFormWrapperComponent fields={fields}>
<Fields connector={connector} />
</MockFormWrapperComponent>
);

userEvent.selectOptions(screen.getByTestId('issueTypeSelect'), '10007');
expect(screen.getByTestId('issueTypeSelect')).toHaveValue('10007');
userEvent.selectOptions(await screen.findByTestId('issueTypeSelect'), '10007');
expect(await screen.findByTestId('issueTypeSelect')).toHaveValue('10007');
});

it('sets priority correctly', () => {
it('sets priority correctly', async () => {
appMockRenderer.render(
<MockFormWrapperComponent fields={fields}>
<Fields connector={connector} />
</MockFormWrapperComponent>
);

userEvent.selectOptions(screen.getByTestId('prioritySelect'), 'Low');
userEvent.selectOptions(await screen.findByTestId('prioritySelect'), 'Low');

expect(screen.getByTestId('prioritySelect')).toHaveValue('Low');
expect(await screen.findByTestId('prioritySelect')).toHaveValue('Low');
});

it('should submit Jira connector', async () => {
Expand All @@ -240,25 +244,25 @@ describe('Jira Fields', () => {
</MockFormWrapperComponent>
);

const issueTypeSelect = screen.getByTestId('issueTypeSelect');
const issueTypeSelect = await screen.findByTestId('issueTypeSelect');
expect(issueTypeSelect).toBeInTheDocument();

userEvent.selectOptions(issueTypeSelect, 'Bug');

await waitFor(() => {
expect(screen.getByTestId('prioritySelect')).toBeInTheDocument();
expect(screen.getByTestId('search-parent-issues')).toBeInTheDocument();
});
expect(await screen.findByTestId('prioritySelect')).toBeInTheDocument();
expect(await screen.findByTestId('search-parent-issues')).toBeInTheDocument();

const checkbox = within(screen.getByTestId('search-parent-issues')).getByTestId(
const checkbox = within(await screen.findByTestId('search-parent-issues')).getByTestId(
'comboBoxSearchInput'
);

userEvent.type(checkbox, 'Person Task{enter}');
userEvent.selectOptions(screen.getByTestId('prioritySelect'), ['Low']);
fireEvent.change(checkbox, {
target: { value: 'Person Task' },
});
userEvent.selectOptions(await screen.findByTestId('prioritySelect'), ['Low']);

expect(screen.getByTestId('issueTypeSelect')).toHaveValue('10007');
expect(screen.getByTestId('prioritySelect')).toHaveValue('Low');
expect(await screen.findByTestId('issueTypeSelect')).toHaveValue('10007');
expect(await screen.findByTestId('prioritySelect')).toHaveValue('Low');
expect(checkbox).toHaveValue('Person Task');
});

Expand All @@ -269,17 +273,16 @@ describe('Jira Fields', () => {
</MockFormWrapperComponent>
);

expect(await screen.findByTestId('prioritySelect')).toBeInTheDocument();
expect(await screen.findByTestId('issueTypeSelect')).toBeInTheDocument();

await waitFor(() => {
expect(screen.getByTestId('prioritySelect')).toBeInTheDocument();
expect(screen.getByTestId('issueTypeSelect')).toBeInTheDocument();
expect(screen.queryByTestId('search-parent-issues')).toBeInTheDocument();
});

userEvent.click(screen.getByTestId('submit-form'));
userEvent.click(await screen.findByTestId('submit-form'));

await waitFor(() => {
expect(screen.getByText('Issue type is required')).toBeInTheDocument();
});
expect(await screen.findByText('Issue type is required')).toBeInTheDocument();
});

it('should not show the loading skeleton when loading issue types', async () => {
Expand Down Expand Up @@ -328,6 +331,6 @@ describe('Jira Fields', () => {
</MockFormWrapperComponent>
);

expect(screen.getByTestId('fields-by-issue-type-loading')).toBeInTheDocument();
expect(await screen.findByTestId('fields-by-issue-type-loading')).toBeInTheDocument();
});
});

0 comments on commit 25522bb

Please sign in to comment.