forked from thoughtworks/HeartBeat
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADM-691: [frontend] feat: add feat about rework settings (#1138)
* ADM-691: [frontend] feat: add new metrics field * ADM-691: [frontend] feat: add rework setting title * ADM-691: [frontend] feat: complete basic function about rework settings * ADM-691: [frontend] feat: use redux to store fields * ADM-691: [frontend] feat: replace undefind to null * ADM-691: [frontend] feat: import config with rework times settings * ADM-691: [frontend] fix: fix unit test * ADM-691: [frontend] fix: fix unit test * ADM-691: [frontend] fix: fix unit test * ADM-691: [frontend] chore: refactor code after cr * ADM-691: [frontend] fix: fix unit test * ADM-691: [frontend] fix: fix unit test * ADM-691: [frontend] test: improve test coverage * ADM-691: [frontend] test: remove unused code * ADM-691: [frontend] test: add test for rework setting * ADM-691: [frontend] fix: fix e2e * ADM-691: [frontend] fix: fix sonar --------- Co-authored-by: Leiqiuhong <qiuhong.lei@thoughtworks.com>
- Loading branch information
1 parent
c9640dd
commit 92ffd21
Showing
21 changed files
with
365 additions
and
14 deletions.
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
50 changes: 50 additions & 0 deletions
50
frontend/__tests__/containers/MetricsStep/ReworkSettings/SingleSelection.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,50 @@ | ||
import { SingleSelection } from '@src/containers/MetricsStep/ReworkSettings/SingleSelection'; | ||
import { act, render, waitFor, within } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { LIST_OPEN } from '@test/fixtures'; | ||
|
||
describe('SingleSelection', () => { | ||
const mockOptions = ['opton1', 'opton2', 'opton3']; | ||
const mockLabel = 'mockLabel'; | ||
const mockValue = 'mockOptions 1'; | ||
const mockOnValueChange = jest.fn(); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const setup = () => | ||
render( | ||
<SingleSelection options={mockOptions} label={mockLabel} value={mockValue} onValueChange={mockOnValueChange} />, | ||
); | ||
|
||
it('should trigger onValueChange callback when select value option', async () => { | ||
const { getByText, getByRole, getAllByRole } = setup(); | ||
|
||
await waitFor(() => { | ||
expect(getByText(mockLabel)).toBeInTheDocument(); | ||
}); | ||
|
||
await act(async () => { | ||
await userEvent.click(getAllByRole('button', { name: LIST_OPEN })[0]); | ||
}); | ||
|
||
const stepsListBox = within(getByRole('listbox')); | ||
await act(async () => { | ||
await userEvent.click(stepsListBox.getByText(mockOptions[1])); | ||
}); | ||
|
||
expect(mockOnValueChange).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should show no options when search the wrong keyword', async () => { | ||
const { getAllByRole, getByText } = setup(); | ||
const buttonElements = getAllByRole('button', { name: LIST_OPEN }); | ||
|
||
await act(async () => { | ||
await userEvent.type(buttonElements[0], 'wrong keyword'); | ||
}); | ||
|
||
expect(getByText('No options')).toBeInTheDocument(); | ||
}); | ||
}); |
90 changes: 90 additions & 0 deletions
90
frontend/__tests__/containers/MetricsStep/reworkSettings.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,90 @@ | ||
import { | ||
ALL, | ||
LIST_OPEN, | ||
REWORK_EXCLUDE_WHICH_STATE, | ||
REWORK_SETTINGS_TITLE, | ||
REWORK_TO_WHICH_STATE, | ||
} from '../../fixtures'; | ||
import { act, render, screen, waitFor, within } from '@testing-library/react'; | ||
import ReworkSettings from '@src/containers/MetricsStep/ReworkSettings'; | ||
import { CYCLE_TIME_LIST } from '@src/constants/resources'; | ||
import { setupStore } from '../../utils/setupStoreUtil'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { Provider } from 'react-redux'; | ||
import React from 'react'; | ||
|
||
const mockedUseAppDispatch = jest.fn(); | ||
jest.mock('@src/hooks/useAppDispatch', () => ({ | ||
useAppDispatch: () => mockedUseAppDispatch, | ||
})); | ||
|
||
const store = setupStore(); | ||
|
||
describe('reworkSetting', () => { | ||
const setup = () => | ||
render( | ||
<Provider store={store}> | ||
<ReworkSettings /> | ||
</Provider>, | ||
); | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should show initial content', () => { | ||
setup(); | ||
|
||
expect(screen.getByText(REWORK_SETTINGS_TITLE)).toBeInTheDocument(); | ||
expect(screen.getByText(REWORK_TO_WHICH_STATE)).toBeInTheDocument(); | ||
expect(screen.getByText(REWORK_EXCLUDE_WHICH_STATE)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should get correct rework setting when pick option', async () => { | ||
const { getByRole, getAllByRole } = setup(); | ||
await act(async () => { | ||
await userEvent.click(getAllByRole('button', { name: LIST_OPEN })[0]); | ||
}); | ||
const stepsListBox = within(getByRole('listbox')); | ||
await act(async () => { | ||
await userEvent.click(stepsListBox.getByText('----')); | ||
}); | ||
await waitFor(async () => { | ||
await expect( | ||
(screen.getByTestId('rework-single-selection-rework-to-which-state').querySelector('input') as HTMLInputElement) | ||
.value, | ||
).toBe('----'); | ||
}); | ||
}); | ||
|
||
it('should get correct value when pick all or other value', async () => { | ||
const { getByRole, getAllByRole, queryByRole } = setup(); | ||
await act(async () => { | ||
await userEvent.click(getAllByRole('button', { name: LIST_OPEN })[1]); | ||
}); | ||
const stepsListBox = within(getByRole('listbox')); | ||
await act(async () => { | ||
await userEvent.click(stepsListBox.getByText(ALL)); | ||
}); | ||
await waitFor(async () => { | ||
CYCLE_TIME_LIST.forEach((value) => { | ||
expect(getByRole('button', { name: value })).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
await act(async () => { | ||
await userEvent.click(stepsListBox.getByText(ALL)); | ||
}); | ||
await waitFor(() => { | ||
CYCLE_TIME_LIST.forEach((value) => { | ||
expect(queryByRole('button', { name: value })).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
await act(async () => { | ||
await userEvent.click(stepsListBox.getByText(CYCLE_TIME_LIST[0])); | ||
}); | ||
await waitFor(async () => { | ||
expect(getByRole('button', { name: CYCLE_TIME_LIST[0] })).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
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
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
Oops, something went wrong.