Skip to content

Commit

Permalink
ADM-777:[frontend]feat: add should refresh state for board info load
Browse files Browse the repository at this point in the history
  • Loading branch information
weiraneve committed Feb 2, 2024
1 parent 3afa378 commit 4aeb557
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions frontend/__tests__/containers/MetricsStep/MetricsStep.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { closeAllNotifications } from '@src/context/notification/NotificationSli
import { CYCLE_TIME_SETTINGS_TYPES } from '@src/constants/resources';

Check failure on line 27 in frontend/__tests__/containers/MetricsStep/MetricsStep.test.tsx

View workflow job for this annotation

GitHub Actions / frontend-check

Insert `backStep,·nextStep·}·from·'@src/context/stepper/StepperSlice';⏎import·{·`
import userEvent from '@testing-library/user-event';
import { HttpStatusCode } from 'axios';

Check failure on line 29 in frontend/__tests__/containers/MetricsStep/MetricsStep.test.tsx

View workflow job for this annotation

GitHub Actions / frontend-check

Delete `';⏎import·{·backStep,·nextStep·}·from·'@src/context/stepper/StepperSlice`
import { backStep, nextStep } from '@src/context/stepper/StepperSlice';

jest.mock('@src/context/notification/NotificationSlice', () => ({
...jest.requireActual('@src/context/notification/NotificationSlice'),
Expand Down Expand Up @@ -259,6 +260,24 @@ describe('MetricsStep', () => {
expect(queryByText(REAL_DONE)).not.toBeInTheDocument();
});

it('should not call closeAllNotifications if back step and shouldRefreshData is false', async () => {
store.dispatch(backStep());
setup();

await waitFor(() => {
expect(closeAllNotifications).not.toHaveBeenCalled();
});
});

it('should call closeAllNotifications if next step and shouldRefreshData is false', async () => {
store.dispatch(nextStep());
setup();

await waitFor(() => {
expect(closeAllNotifications).toHaveBeenCalled();
});
});

it('should be render no card container when get board card when no data', async () => {
server.use(
rest.post(MOCK_BOARD_INFO_URL, (_, res, ctx) => {
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/containers/MetricsStep/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { selectMetricsContent, updateMetricsState } from '@src/context/Metrics/m
import { CYCLE_TIME_SETTINGS_TYPES, DONE, REQUIRED_DATA } from '@src/constants/resources';
import { closeAllNotifications } from '@src/context/notification/NotificationSlice';
import { Classification } from '@src/containers/MetricsStep/Classification';
import { shouldRefreshData } from '@src/context/stepper/StepperSlice';
import DateRangeViewer from '@src/components/Common/DateRangeViewer';
import { useGetBoardInfoEffect } from '@src/hooks/useGetBoardInfo';
import { CycleTime } from '@src/containers/MetricsStep/CycleTime';
Expand Down Expand Up @@ -48,6 +49,7 @@ const MetricsStep = () => {
cycleTimeSettingsType === CYCLE_TIME_SETTINGS_TYPES.BY_COLUMN &&
cycleTimeSettings.filter((e) => e.value === DONE).length > 1;
const { getBoardInfo, isLoading, errorMessage } = useGetBoardInfoEffect();
const shouldRefresh = useAppSelector(shouldRefreshData);

const getInfo = () => {
getBoardInfo({
Expand All @@ -63,6 +65,7 @@ const MetricsStep = () => {
};

useLayoutEffect(() => {
if (!shouldRefresh) return;
dispatch(closeAllNotifications());
getInfo();
}, []);
Expand Down

0 comments on commit 4aeb557

Please sign in to comment.