Skip to content
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

Adm 793 [frontend] Reduce the time of timeout to 10 minutes #1141

Merged
merged 41 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e6b9ee1
AMD-793 [frontend] feature: add reverify logic and timeout alert
Mar 7, 2024
fc01550
AMD-793 [frontend] refactor: abstract config button component for con…
Mar 8, 2024
2354ced
Merge branch 'main' into ADM-793
Mar 8, 2024
01ab2ed
AMD-793 [frontend] refactor: abstract timeout alert component for con…
Mar 8, 2024
12f8c26
AMD-793 [frontend] feat: add timeout alert component to config page f…
Mar 11, 2024
a59dfb5
AMD-793 [frontend] fix: merge main to 793
Mar 11, 2024
f619f9c
AMD-793 [frontend] test: add test for timeout alert component
Mar 11, 2024
d38f126
AMD-793 [frontend] test: add test for config button group component
Mar 11, 2024
4e3917c
Merge branch 'main' into ADM-793
Mar 12, 2024
49ff6a8
[ADM-793] style: fix css check
Mar 12, 2024
67817c1
AMD-793 [frontend] fix: set HB timeout and timeout alert false in Sou…
Mar 12, 2024
e132606
AMD-793 [frontend] fix: fix test for PipelineToolClient.test.ts and S…
Mar 12, 2024
c6eb632
[ADM-793] style: fix border css
Mar 12, 2024
8bc183b
[ADM-793] test: fix test for useVerifyBoardEffect
Mar 12, 2024
3345b5b
AMD-793 [frontend] test: add test of isHBTimeout for useVerifySourceC…
Mar 12, 2024
4ac618e
[ADM-793] test: add test for useVerifyPipelineToolEffect
Mar 12, 2024
7b7b851
[ADM-793] test: add test for getFieldsWithNoVerifiedError
Mar 12, 2024
666654c
AMD-793 [frontend] test: remove not use mock in test file and change …
Mar 12, 2024
638dada
ADM-856:[backend]feat: update all feign clients decoder error message…
weiraneve Mar 12, 2024
c9640dd
ADM-697:[docx] docx: add docx spike the logic of calculating card rew…
Liughgood Mar 12, 2024
92ffd21
ADM-691: [frontend] feat: add feat about rework settings (#1138)
neomgb Mar 12, 2024
87265f8
ADM-856:[backend]feat: add decode default case error message (#1139)
weiraneve Mar 12, 2024
ff5045e
ADM-837:[docs] docs: spike about optimizing generate report backend l…
sqsq5566 Mar 12, 2024
5e7a7bf
add test case
guzhongren Mar 12, 2024
e3558f4
Merge branch 'main' into ADM-793
Mar 13, 2024
6fafbe2
AMD-793 [frontend] style: fix color for reverify button
Mar 13, 2024
ae3c971
[ADM-793] fix: revert httpTimeout
Mar 13, 2024
09cf8cd
Build(deps): bump softprops/action-gh-release from 1 to 2 (#1136)
dependabot[bot] Mar 13, 2024
e0dd764
Merge branch 'main' into ADM-793
lxuebing Mar 13, 2024
575e9bd
AMD-793 [frontend] fix: remove annotation in test file
Mar 13, 2024
94899f5
AMD-793 [frontend] fix: update test name for clear
Mar 13, 2024
210c6ea
AMD-793 [frontend] fix: update test name use given when then
Mar 13, 2024
e06a936
chore: extend the overall timeout of e2e 1 more minute. (#1144)
mrcuriosity-tw Mar 13, 2024
267c51a
ADM-691: [frontend] fix: add request fields (#1143)
neomgb Mar 13, 2024
7683e22
ADM-691: [frontend] fix: fix sonar issue (#1145)
neomgb Mar 13, 2024
7512069
[ADM-793] refactor: rename AXIOS_REQUEST_ERROR_CODE
Mar 13, 2024
c5f66ee
Merge branch 'main' into ADM-793
lxuebing Mar 14, 2024
9f0b012
AMD-793 [frontend] fix: update alert position to keep element still
Mar 14, 2024
5e626a8
[ADM-793] feat: enhance style for alert
Mar 14, 2024
b331d3c
[ADM-793] feat: change moduleType text
Mar 14, 2024
76df053
[ADM-793] style: enhance style
Mar 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/__tests__/client/PipelineToolClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ afterAll(() => server.close());
describe('PipelineToolClient', () => {
describe('verify pipelineTool request', () => {
it('should isPipelineVerified is true when pipelineTool verify response status 204', async () => {
const result = await pipelineToolClient.verify(MOCK_PIPELINE_VERIFY_REQUEST_PARAMS);
const result = await pipelineToolClient.verify(MOCK_PIPELINE_VERIFY_REQUEST_PARAMS, jest.fn(), jest.fn());

expect(result.code).toEqual(HttpStatusCode.NoContent);
});
Expand All @@ -45,7 +45,7 @@ describe('PipelineToolClient', () => {
it.each(errorCases)('should return error code when verify endponint returns error', async ({ code }) => {
server.use(rest.post(MOCK_PIPELINE_VERIFY_URL, (req, res, ctx) => res(ctx.status(code))));

const result = await pipelineToolClient.verify(MOCK_PIPELINE_VERIFY_REQUEST_PARAMS);
const result = await pipelineToolClient.verify(MOCK_PIPELINE_VERIFY_REQUEST_PARAMS, jest.fn(), jest.fn());

expect(result.code).toEqual(code);
});
Expand Down
12 changes: 8 additions & 4 deletions frontend/__tests__/client/SourceControlClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ describe('verify sourceControl request', () => {
afterAll(() => server.close());

it('should return isSourceControlVerify true when sourceControl verify response status is 204', async () => {
const result = await sourceControlClient.verifyToken(MOCK_SOURCE_CONTROL_VERIFY_REQUEST_PARAMS);
const result = await sourceControlClient.verifyToken(
MOCK_SOURCE_CONTROL_VERIFY_REQUEST_PARAMS,
jest.fn(),
jest.fn(),
);

expect(result.code).toEqual(204);
});
Expand All @@ -27,7 +31,7 @@ describe('verify sourceControl request', () => {
),
);

sourceControlClient.verifyToken(MOCK_SOURCE_CONTROL_VERIFY_REQUEST_PARAMS).catch((e) => {
sourceControlClient.verifyToken(MOCK_SOURCE_CONTROL_VERIFY_REQUEST_PARAMS, jest.fn(), jest.fn()).catch((e) => {
expect(e).toBeInstanceOf(Error);
expect((e as Error).message).toMatch(VERIFY_ERROR_MESSAGE.BAD_REQUEST);
});
Expand All @@ -40,7 +44,7 @@ describe('verify sourceControl request', () => {
),
);

sourceControlClient.verifyToken(MOCK_SOURCE_CONTROL_VERIFY_REQUEST_PARAMS).catch((e) => {
sourceControlClient.verifyToken(MOCK_SOURCE_CONTROL_VERIFY_REQUEST_PARAMS, jest.fn(), jest.fn()).catch((e) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要用catch接,用reject.throw接错误

expect(e).toBeInstanceOf(Error);
expect((e as Error).message).toMatch(VERIFY_ERROR_MESSAGE.NOT_FOUND);
});
Expand All @@ -58,7 +62,7 @@ describe('verify sourceControl request', () => {
),
);

sourceControlClient.verifyToken(MOCK_SOURCE_CONTROL_VERIFY_REQUEST_PARAMS).catch((e) => {
sourceControlClient.verifyToken(MOCK_SOURCE_CONTROL_VERIFY_REQUEST_PARAMS, jest.fn(), jest.fn()).catch((e) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一样的问题

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原则:测试不要出现类似try catch的代码

expect(e).toBeInstanceOf(Error);
expect((e as Error).message).toMatch(VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ConfigButtonGrop } from '@src/containers/ConfigStep/ConfigButton';
import { render, screen } from '@testing-library/react';
import React from 'react';

describe('ConfigButtonGroup', () => {
const setup = (isVerified: boolean, isLoading: boolean, isHBTimeOut: boolean, isDisableVerifyButton: boolean) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsHBTimeout?isConfigTimeout??

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

收到,我理解是尽量避免变量名不涉及项目信息?比如IsHBTimeout中HB涉及到了,应换个普通点的名称?

return render(
<ConfigButtonGrop
isHBTimeOut={isHBTimeOut}
isVerified={isVerified}
isLoading={isLoading}
isDisableVerifyButton={isDisableVerifyButton}
/>,
);
};

it('should render a disabled VerifyButton with "Verified" text when isVerified is true and isLoading is false', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When - given,看一哈should given when 分别写什么

setup(true, false, false, false); // Use a different moduleType for clarity
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

expect(screen.getByText('Verified')).toBeInTheDocument();
expect(screen.getByText('Reset')).toBeInTheDocument();
expect(screen.getByText('Verified')).toBeDisabled();
});
it('should render a VerifyButton with "Reverify" text when isHBTimeOut is true', () => {
setup(false, false, true, false); // Use a different moduleType for clarity
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

expect(screen.getByText('Reverify')).toBeInTheDocument();
expect(screen.getByText('Reverify')).toHaveAttribute('type', 'submit');
});
});
48 changes: 48 additions & 0 deletions frontend/__tests__/containers/ConfigStep/TimeoutAlet.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { TimeoutAlert } from '@src/containers/ConfigStep/TimeoutAlert';
import { act, render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';

describe('TimeoutAlert', () => {
const setIsShowAlert = jest.fn();
const setup = (
setIsShowAlert: (value: boolean) => void,
isShowAlert: boolean,
isHBTimeOut: boolean,
moduleType: string,
) => {
return render(
<TimeoutAlert
setIsShowAlert={setIsShowAlert}
isShowAlert={isShowAlert}
isHBTimeOut={isHBTimeOut}
moduleType={moduleType}
/>,
);
};

it('should render the correct message when given the moduleType', () => {
setup(setIsShowAlert, true, true, 'Board'); // Use a different moduleType for clarity
const message = screen.getByText('Board'); // Use a regex for flexibility
expect(message).toBeInTheDocument();
});
it('should not render the alert when isHBTimeOut or isShowAlert is false', () => {
setup(setIsShowAlert, false, true, 'Board');
expect(screen.queryByText('Board')).not.toBeInTheDocument();

setup(setIsShowAlert, true, false, 'Board');
expect(screen.queryByText('Board')).not.toBeInTheDocument();
});

it('should call setIsShowAlert with false and hides the alert when click the close icon', async () => {
setup(setIsShowAlert, true, true, 'any'); // Ensure alert is visible
const closeIcon = screen.getByTestId('CloseIcon');
act(() => {
userEvent.click(closeIcon);
});
await waitFor(() => {
expect(setIsShowAlert).toHaveBeenCalledTimes(1);
expect(setIsShowAlert).toHaveBeenCalledWith(false);
});
});
});
3 changes: 3 additions & 0 deletions frontend/__tests__/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,9 @@ export const CYCLE_TIME_SETTINGS_SECTION = 'Cycle time settings section';
export const REAL_DONE_SETTING_SECTION = 'Real done setting section';
export const SELECT_CONSIDER_AS_DONE_MESSAGE = 'Must select which you want to consider as Done';
export const MOCK_SOURCE_CONTROL_VERIFY_ERROR_CASE_TEXT = 'Token is incorrect!';
export const MOCK_PIPELINE_VERIFY_UNAUTHORIZED_TEXT = 'Token is incorrect!';
export const MOCK_PIPELINE_VERIFY_FORBIDDEN_ERROR_TEXT =
'Forbidden request, please change your token with correct access permission.';

export const FAKE_TOKEN = 'fake-token';

Expand Down
114 changes: 62 additions & 52 deletions frontend/__tests__/hooks/useVerifyBoardEffect.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { useVerifyBoardEffect, useVerifyBoardStateInterface } from '@src/hooks/useVerifyBoardEffect';
import { MOCK_BOARD_URL_FOR_JIRA, FAKE_TOKEN } from '@test/fixtures';
import { act, renderHook, waitFor } from '@testing-library/react';
import { setupServer } from 'msw/node';
import { FAKE_TOKEN } from '@test/fixtures';
import { HttpStatusCode } from 'axios';

import { InternalServerException } from '@src/exceptions/InternalServerException';
import { UnauthorizedException } from '@src/exceptions/UnauthorizedException';
import { NotFoundException } from '@src/exceptions/NotFoundException';
import { TimeoutException } from '@src/exceptions/TimeoutException';
import { HEARTBEAT_EXCEPTION_CODE } from '@src/constants/resources';
import { boardClient } from '@src/clients/board/BoardClient';
import { BOARD_TYPES } from '@test/fixtures';
import { rest } from 'msw';

const mockDispatch = jest.fn();
jest.mock('react-redux', () => ({
Expand All @@ -18,8 +22,6 @@ jest.mock('@src/hooks/useAppDispatch', () => ({
useAppDispatch: jest.fn(() => jest.fn()),
}));

const server = setupServer();

const updateFields = (result: { current: useVerifyBoardStateInterface }) => {
result.current.updateField('Board Id', '1');
result.current.updateField('Email', 'fake@qq.com');
Expand All @@ -28,10 +30,8 @@ const updateFields = (result: { current: useVerifyBoardStateInterface }) => {
};

describe('use verify board state', () => {
beforeAll(() => server.listen());
afterAll(() => {
jest.clearAllMocks();
server.close();
});
it('should got initial data state when hook render given none input', async () => {
const { result } = renderHook(() => useVerifyBoardEffect());
Expand All @@ -41,16 +41,13 @@ describe('use verify board state', () => {
});

it('should got email and token fields error message when call verify function given a invalid token', async () => {
server.use(
rest.post(MOCK_BOARD_URL_FOR_JIRA, (_, res, ctx) => {
return res(ctx.status(HttpStatusCode.Unauthorized));
}),
);
const mockedError = new UnauthorizedException('', HttpStatusCode.Unauthorized, '');
boardClient.getVerifyBoard = jest.fn().mockImplementation(() => Promise.reject(mockedError));

const { result } = renderHook(() => useVerifyBoardEffect());
await act(() => {
updateFields(result);
result.current.verifyJira();
await act(async () => {
await updateFields(result);
await result.current.verifyJira();
});

const emailFiled = result.current.fields.find((field) => field.key === 'Email');
Expand All @@ -61,22 +58,34 @@ describe('use verify board state', () => {
);
});

it('when call verify function given a invalid site then should got site field error message', async () => {
server.use(
rest.post(MOCK_BOARD_URL_FOR_JIRA, (_, res, ctx) => {
return res(
ctx.status(HttpStatusCode.NotFound),
ctx.json({
message: 'site is incorrect',
}),
);
}),
);
it('should clear email validatedError when updateField by Email', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should Given when

const mockedError = new UnauthorizedException('', HttpStatusCode.Unauthorized, '');
boardClient.getVerifyBoard = jest.fn().mockImplementation(() => Promise.reject(mockedError));

const { result } = renderHook(() => useVerifyBoardEffect());
await act(() => {
updateFields(result);
result.current.verifyJira();
await act(async () => {
await updateFields(result);
await result.current.verifyJira();
});

const emailFiled = result.current.fields.find((field) => field.key === 'Email');
expect(emailFiled?.verifiedError).toBe('Email is incorrect!');

await act(async () => {
await result.current.updateField('Email', 'fake@qq.com');
});
const emailText = result.current.fields.find((field) => field.key === 'Email');
expect(emailText?.verifiedError).toBe('');
});

it('should got site field error message when call verify function given a invalid site', async () => {
const mockedError = new NotFoundException('site is incorrect', HttpStatusCode.NotFound, 'site is incorrect');
boardClient.getVerifyBoard = jest.fn().mockImplementation(() => Promise.reject(mockedError));

const { result } = renderHook(() => useVerifyBoardEffect());
await act(async () => {
await updateFields(result);
await result.current.verifyJira();
});

await waitFor(() => {
Expand All @@ -87,16 +96,8 @@ describe('use verify board state', () => {
});

it('should got board id field error message when call verify function given a invalid board id', async () => {
server.use(
rest.post(MOCK_BOARD_URL_FOR_JIRA, (_, res, ctx) => {
return res(
ctx.status(HttpStatusCode.NotFound),
ctx.json({
message: 'boardId is incorrect',
}),
);
}),
);
const mockedError = new NotFoundException('boardId is incorrect', HttpStatusCode.NotFound, 'boardId is incorrect');
boardClient.getVerifyBoard = jest.fn().mockImplementation(() => Promise.reject(mockedError));

const { result } = renderHook(() => useVerifyBoardEffect());
await act(() => {
Expand All @@ -111,28 +112,22 @@ describe('use verify board state', () => {
});

it('should got token fields error message when call verify function given a unknown error', async () => {
server.use(
rest.post(MOCK_BOARD_URL_FOR_JIRA, (_, res, ctx) => {
return res(ctx.status(HttpStatusCode.ServiceUnavailable));
}),
);
const mockedError = new InternalServerException('', HttpStatusCode.ServiceUnavailable, '');
boardClient.getVerifyBoard = jest.fn().mockImplementation(() => Promise.reject(mockedError));

const { result } = renderHook(() => useVerifyBoardEffect());
await act(() => {
updateFields(result);
result.current.verifyJira();
await act(async () => {
await updateFields(result);
await result.current.verifyJira();
});

const tokenField = result.current.fields.find((field) => field.key === 'Token');
expect(tokenField?.verifiedError).toBe('Unknown error');
});

it('should clear all verified error messages when update a verified error field', async () => {
server.use(
rest.post(MOCK_BOARD_URL_FOR_JIRA, (_, res, ctx) => {
return res(ctx.status(HttpStatusCode.Unauthorized));
}),
);
const mockedError = new UnauthorizedException('', HttpStatusCode.Unauthorized, '');
boardClient.getVerifyBoard = jest.fn().mockImplementation(() => Promise.reject(mockedError));

const { result } = renderHook(() => useVerifyBoardEffect());
await act(() => {
Expand All @@ -148,4 +143,19 @@ describe('use verify board state', () => {
expect(emailFiled?.verifiedError).toBe('');
expect(tokenField?.verifiedError).toBe('');
});

it('should set timeout is true when getVerifyBoard api is timeout', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given

const mockedError = new TimeoutException('', HEARTBEAT_EXCEPTION_CODE.TIMEOUT);
boardClient.getVerifyBoard = jest.fn().mockImplementation(() => Promise.reject(mockedError));

const { result } = renderHook(() => useVerifyBoardEffect());
await act(() => {
result.current.verifyJira();
});

await waitFor(() => {
const isHBTimeOut = result.current.isHBTimeOut;
expect(isHBTimeOut).toBe(true);
});
});
});
Loading
Loading