Skip to content

Commit

Permalink
Enum optmization (#1476)[frontend]
Browse files Browse the repository at this point in the history
* pref(script): update scirpt of tset

* pref(enum): update enum

* pref(enum): update enum

* pref(enum): update enum

* pref(enum): update enum

* pref(enum): update enum

* pref(enum): update enum AxiosRequestErrorCode

* pref(enum): update enum SortingDateRangeText

* pref(enum): update enum CycleTimeMetricsName
  • Loading branch information
guzhongren authored Jun 2, 2024
1 parent dfc8296 commit a3bc003
Show file tree
Hide file tree
Showing 75 changed files with 636 additions and 642 deletions.
24 changes: 12 additions & 12 deletions frontend/__tests__/client/BoardClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
MOCK_BOARD_URL_FOR_JIRA,
MOCK_BOARD_VERIFY_REQUEST_PARAMS,
MOCK_JIRA_BOARD_VERIFY_REQUEST_PARAMS,
VERIFY_ERROR_MESSAGE,
AXIOS_ERROR_MESSAGE,
VerifyErrorMessage,
AxiosErrorMessage,
} from '../fixtures';
import { boardClient } from '@src/clients/board/BoardClient';
import { http, HttpResponse } from 'msw';
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('verify board request', () => {
http.post(MOCK_BOARD_URL_FOR_JIRA, () => {
return new HttpResponse(
JSON.stringify({
hintInfo: VERIFY_ERROR_MESSAGE.BAD_REQUEST,
hintInfo: VerifyErrorMessage.BadRequest,
}),
{
status: HttpStatusCode.BadRequest,
Expand All @@ -65,7 +65,7 @@ describe('verify board request', () => {

boardClient.getVerifyBoard(MOCK_BOARD_VERIFY_REQUEST_PARAMS).catch((e) => {
expect(e).toBeInstanceOf(Error);
expect((e as Error).message).toMatch(VERIFY_ERROR_MESSAGE.BAD_REQUEST);
expect((e as Error).message).toMatch(VerifyErrorMessage.BadRequest);
});
});

Expand All @@ -74,7 +74,7 @@ describe('verify board request', () => {
http.post(MOCK_BOARD_URL_FOR_JIRA, () => {
return new HttpResponse(
JSON.stringify({
hintInfo: VERIFY_ERROR_MESSAGE.UNAUTHORIZED,
hintInfo: VerifyErrorMessage.Unauthorized,
}),
{
status: HttpStatusCode.Unauthorized,
Expand All @@ -85,15 +85,15 @@ describe('verify board request', () => {

await expect(async () => {
await boardClient.getVerifyBoard(MOCK_BOARD_VERIFY_REQUEST_PARAMS);
}).rejects.toThrow(VERIFY_ERROR_MESSAGE.UNAUTHORIZED);
}).rejects.toThrow(VerifyErrorMessage.Unauthorized);
});

it('should throw error when board verify response status 500', async () => {
server.use(
http.post(MOCK_BOARD_URL_FOR_JIRA, () => {
return new HttpResponse(
JSON.stringify({
hintInfo: VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR,
hintInfo: VerifyErrorMessage.InternalServerError,
}),
{
status: HttpStatusCode.InternalServerError,
Expand All @@ -104,15 +104,15 @@ describe('verify board request', () => {

await expect(async () => {
await boardClient.getVerifyBoard(MOCK_BOARD_VERIFY_REQUEST_PARAMS);
}).rejects.toThrow(VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR);
}).rejects.toThrow(VerifyErrorMessage.InternalServerError);
});

it('should throw error when board verify response status 503', async () => {
server.use(
http.post(MOCK_BOARD_URL_FOR_JIRA, () => {
return new HttpResponse(
JSON.stringify({
hintInfo: VERIFY_ERROR_MESSAGE.REQUEST_TIMEOUT,
hintInfo: VerifyErrorMessage.RequestTimeout,
}),
{
status: HttpStatusCode.ServiceUnavailable,
Expand All @@ -123,7 +123,7 @@ describe('verify board request', () => {

await expect(async () => {
await boardClient.getVerifyBoard(MOCK_BOARD_VERIFY_REQUEST_PARAMS);
}).rejects.toThrow(VERIFY_ERROR_MESSAGE.REQUEST_TIMEOUT);
}).rejects.toThrow(VerifyErrorMessage.RequestTimeout);
});

it('should throw error when board verify response status 300', async () => {
Expand All @@ -137,7 +137,7 @@ describe('verify board request', () => {

await expect(async () => {
await boardClient.getVerifyBoard(MOCK_BOARD_VERIFY_REQUEST_PARAMS);
}).rejects.toThrow(VERIFY_ERROR_MESSAGE.UNKNOWN);
}).rejects.toThrow(VerifyErrorMessage.Unknown);
});

it('should throw `Network Error` when board verify encountered netwrok error', async () => {
Expand All @@ -149,6 +149,6 @@ describe('verify board request', () => {

await expect(async () => {
await boardClient.getVerifyBoard(MOCK_BOARD_VERIFY_REQUEST_PARAMS);
}).rejects.toThrow(AXIOS_ERROR_MESSAGE.ERR_NETWORK);
}).rejects.toThrow(AxiosErrorMessage.ErrorNetwork);
});
});
6 changes: 3 additions & 3 deletions frontend/__tests__/client/CSVClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MOCK_EXPORT_CSV_REQUEST_PARAMS, MOCK_EXPORT_CSV_URL, VERIFY_ERROR_MESSAGE } from '../fixtures';
import { MOCK_EXPORT_CSV_REQUEST_PARAMS, MOCK_EXPORT_CSV_URL, VerifyErrorMessage } from '../fixtures';
import { csvClient } from '@src/clients/report/CSVClient';
import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';
Expand Down Expand Up @@ -40,13 +40,13 @@ describe('verify export csv', () => {
http.get(MOCK_EXPORT_CSV_URL, () => {
return new HttpResponse(null, {
status: HttpStatusCode.InternalServerError,
statusText: VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR,
statusText: VerifyErrorMessage.InternalServerError,
});
}),
);

await expect(async () => {
await csvClient.exportCSVData(MOCK_EXPORT_CSV_REQUEST_PARAMS);
}).rejects.toThrow(VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR);
}).rejects.toThrow(VerifyErrorMessage.InternalServerError);
});
});
6 changes: 3 additions & 3 deletions frontend/__tests__/client/HeaderClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MOCK_VERSION_URL, VERIFY_ERROR_MESSAGE, VERSION_RESPONSE } from '../fixtures';
import { MOCK_VERSION_URL, VerifyErrorMessage, VERSION_RESPONSE } from '../fixtures';
import { headerClient } from '@src/clients/header/HeaderClient';
import { HttpResponse, http } from 'msw';
import { setupServer } from 'msw/node';
Expand Down Expand Up @@ -35,7 +35,7 @@ describe('header client', () => {
http.get(MOCK_VERSION_URL, () => {
return new HttpResponse(
JSON.stringify({
hintInfo: VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR,
hintInfo: VerifyErrorMessage.InternalServerError,
}),
{
status: HttpStatusCode.InternalServerError,
Expand All @@ -46,6 +46,6 @@ describe('header client', () => {

expect(async () => {
await headerClient.getVersion();
}).rejects.toThrow(VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR);
}).rejects.toThrow(VerifyErrorMessage.InternalServerError);
});
});
10 changes: 5 additions & 5 deletions frontend/__tests__/client/MetricsClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BASE_URL, MOCK_GET_STEPS_PARAMS, VERIFY_ERROR_MESSAGE } from '../fixtures';
import { BASE_URL, MOCK_GET_STEPS_PARAMS, VerifyErrorMessage } from '../fixtures';
import { metricsClient } from '@src/clients/MetricsClient';
import { HttpResponse, http } from 'msw';
import { setupServer } from 'msw/node';
Expand Down Expand Up @@ -28,29 +28,29 @@ describe('get steps from metrics response', () => {
it('should throw error when getSteps response status 500', async () => {
server.use(
http.get(getStepsUrl, () => {
return new HttpResponse(JSON.stringify({ hintInfo: VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR }), {
return new HttpResponse(JSON.stringify({ hintInfo: VerifyErrorMessage.InternalServerError }), {
status: HttpStatusCode.InternalServerError,
});
}),
);

await expect(async () => {
await metricsClient.getSteps(params[0], buildId, organizationId, pipelineType, token);
}).rejects.toThrow(VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR);
}).rejects.toThrow(VerifyErrorMessage.InternalServerError);
});

it('should throw error when getSteps response status 400', async () => {
server.use(
http.get(getStepsUrl, () => {
return new HttpResponse(JSON.stringify({ hintInfo: VERIFY_ERROR_MESSAGE.BAD_REQUEST }), {
return new HttpResponse(JSON.stringify({ hintInfo: VerifyErrorMessage.BadRequest }), {
status: HttpStatusCode.BadRequest,
});
}),
);

await expect(async () => {
await metricsClient.getSteps(params[0], buildId, organizationId, pipelineType, token);
}).rejects.toThrow(VERIFY_ERROR_MESSAGE.BAD_REQUEST);
}).rejects.toThrow(VerifyErrorMessage.BadRequest);
});

it('should show isNoStep True when getSteps response status 204', async () => {
Expand Down
14 changes: 7 additions & 7 deletions frontend/__tests__/client/ReportClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
MOCK_GENERATE_REPORT_REQUEST_PARAMS,
MOCK_REPORT_RESPONSE,
MOCK_RETRIEVE_REPORT_RESPONSE,
VERIFY_ERROR_MESSAGE,
VerifyErrorMessage,
} from '../fixtures';
import { reportClient } from '@src/clients/report/ReportClient';
import { HttpResponse, http } from 'msw';
Expand Down Expand Up @@ -48,7 +48,7 @@ describe('report client', () => {
http.post(MOCK_REPORT_URL, () => {
return new HttpResponse(
JSON.stringify({
hintInfo: VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR,
hintInfo: VerifyErrorMessage.InternalServerError,
}),
{
status: HttpStatusCode.InternalServerError,
Expand All @@ -59,15 +59,15 @@ describe('report client', () => {

await expect(async () => {
await reportClient.retrieveByUrl(MOCK_GENERATE_REPORT_REQUEST_PARAMS, '/reports');
}).rejects.toThrow(VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR);
}).rejects.toThrow(VerifyErrorMessage.InternalServerError);
});

it('should throw error when generate report response status 400', async () => {
server.use(
http.post(MOCK_REPORT_URL, () => {
return new HttpResponse(
JSON.stringify({
hintInfo: VERIFY_ERROR_MESSAGE.BAD_REQUEST,
hintInfo: VerifyErrorMessage.BadRequest,
}),
{
status: HttpStatusCode.BadRequest,
Expand All @@ -78,15 +78,15 @@ describe('report client', () => {

await expect(async () => {
await reportClient.retrieveByUrl(MOCK_GENERATE_REPORT_REQUEST_PARAMS, '/reports');
}).rejects.toThrow(VERIFY_ERROR_MESSAGE.BAD_REQUEST);
}).rejects.toThrow(VerifyErrorMessage.BadRequest);
});

it('should throw error when calling pollingReport given response status 500', () => {
server.use(
http.get(MOCK_REPORT_URL, () => {
return new HttpResponse(
JSON.stringify({
hintInfo: VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR,
hintInfo: VerifyErrorMessage.InternalServerError,
}),
{
status: HttpStatusCode.InternalServerError,
Expand All @@ -97,7 +97,7 @@ describe('report client', () => {

expect(async () => {
await reportClient.polling(MOCK_REPORT_URL);
}).rejects.toThrow(VERIFY_ERROR_MESSAGE.INTERNAL_SERVER_ERROR);
}).rejects.toThrow(VerifyErrorMessage.InternalServerError);
});

it('should return status and response when calling pollingReport given response status 201', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ReportForTwoColumns from '@src/components/Common/ReportForTwoColumns';
import { CYCLE_TIME, DEPLOYMENT_FREQUENCY, VELOCITY } from '../../fixtures';
import { REPORT_SUFFIX_UNITS } from '@src/constants/resources';
import { ReportSuffixUnits } from '@src/constants/resources';
import { render, screen } from '@testing-library/react';

describe('Report for two columns', () => {
Expand All @@ -18,9 +18,9 @@ describe('Report for two columns', () => {

it('should show cycle time table row', () => {
const mockData = [
{ id: 0, name: 'name1', valueList: [{ value: '1.1', units: REPORT_SUFFIX_UNITS.PER_CARD }] },
{ id: 1, name: 'name2', valueList: [{ value: '2', units: REPORT_SUFFIX_UNITS.PER_CARD }] },
{ id: 2, name: <div>name3</div>, valueList: [{ value: '3', units: REPORT_SUFFIX_UNITS.PER_CARD }] },
{ id: 0, name: 'name1', valueList: [{ value: '1.1', units: ReportSuffixUnits.DaysPerCard }] },
{ id: 1, name: 'name2', valueList: [{ value: '2', units: ReportSuffixUnits.DaysPerCard }] },
{ id: 2, name: <div>name3</div>, valueList: [{ value: '3', units: ReportSuffixUnits.DaysPerCard }] },
];

render(<ReportForTwoColumns title={CYCLE_TIME} data={mockData} />);
Expand All @@ -42,8 +42,8 @@ describe('Report for two columns', () => {

it('should show table when data with Units is not empty', () => {
const mockData = [
{ id: 0, name: 'name1', valueList: [{ value: 1, units: REPORT_SUFFIX_UNITS.PER_CARD }] },
{ id: 1, name: 'name2', valueList: [{ value: 2, units: REPORT_SUFFIX_UNITS.PER_CARD }] },
{ id: 0, name: 'name1', valueList: [{ value: 1, units: ReportSuffixUnits.DaysPerCard }] },
{ id: 1, name: 'name2', valueList: [{ value: 2, units: ReportSuffixUnits.DaysPerCard }] },
];

render(<ReportForTwoColumns title={CYCLE_TIME} data={mockData} />);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ErrorNotification } from '@src/components/ErrorNotification';
import { BOARD_TYPES, VERIFY_ERROR_MESSAGE } from '../../fixtures';
import { BOARD_TYPES, VerifyErrorMessage } from '../../fixtures';
import { render } from '@testing-library/react';

describe('error notification', () => {
it('should show error message when render error notification', () => {
const { getByText } = render(
<ErrorNotification message={`${BOARD_TYPES.JIRA} ${VERIFY_ERROR_MESSAGE.BAD_REQUEST}`} />,
<ErrorNotification message={`${BOARD_TYPES.JIRA} ${VerifyErrorMessage.BadRequest}`} />,
);

expect(getByText(`${BOARD_TYPES.JIRA} ${VERIFY_ERROR_MESSAGE.BAD_REQUEST}`)).toBeInTheDocument();
expect(getByText(`${BOARD_TYPES.JIRA} ${VerifyErrorMessage.BadRequest}`)).toBeInTheDocument();
});
});
16 changes: 8 additions & 8 deletions frontend/__tests__/containers/ConfigStep/Board.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
BOARD_FIELDS,
BOARD_TYPES,
CONFIG_TITLE,
ConfigTitle,
ERROR_MESSAGE_COLOR,
MOCK_BOARD_URL_FOR_JIRA,
RESET,
Expand All @@ -15,8 +15,8 @@ import {
import { boardConfigDefaultValues } from '@src/containers/ConfigStep/Form/useDefaultValues';
import { boardConfigSchema } from '@src/containers/ConfigStep/Form/schema';
import { render, screen, waitFor, within } from '@testing-library/react';
import { AXIOS_REQUEST_ERROR_CODE } from '@src/constants/resources';
import { UnauthorizedError } from '@src/errors/UnauthorizedError';
import { AxiosRequestErrorCode } from '@src/constants/resources';
import { boardClient } from '@src/clients/board/BoardClient';
import { Board } from '@src/containers/ConfigStep/Board';
import { setupStore } from '../../utils/setupStoreUtil';
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('Board', () => {
BOARD_FIELDS.map((field) => {
expect(screen.getByLabelText(`${field} *`)).toBeInTheDocument();
});
expect(screen.getAllByText(CONFIG_TITLE.BOARD)[0]).toBeInTheDocument();
expect(screen.getAllByText(ConfigTitle.Board)[0]).toBeInTheDocument();
});

it('should show default value jira when init board component', () => {
Expand All @@ -96,7 +96,7 @@ describe('Board', () => {

it('should show detail options when click board field', async () => {
setup();
await userEvent.click(screen.getByRole('combobox', { name: CONFIG_TITLE.BOARD }));
await userEvent.click(screen.getByRole('combobox', { name: ConfigTitle.Board }));
const listBox = within(screen.getByRole('listbox'));
const options = listBox.getAllByRole('option');
const optionValue = options.map((li) => li.getAttribute('data-value'));
Expand All @@ -106,7 +106,7 @@ describe('Board', () => {

it('should show board type when select board field value ', async () => {
setup();
await userEvent.click(screen.getByRole('combobox', { name: CONFIG_TITLE.BOARD }));
await userEvent.click(screen.getByRole('combobox', { name: ConfigTitle.Board }));

await waitFor(() => {
expect(screen.getByRole('option', { name: /jira/i })).toBeInTheDocument();
Expand Down Expand Up @@ -181,7 +181,7 @@ describe('Board', () => {
it('should hidden timeout alert when click reset button', async () => {
const { getByLabelText, queryByLabelText } = setup();
await fillBoardFieldsInformation();
const mockedError = new TimeoutError('', AXIOS_REQUEST_ERROR_CODE.TIMEOUT);
const mockedError = new TimeoutError('', AxiosRequestErrorCode.Timeout);
boardClient.getVerifyBoard = jest.fn().mockImplementation(() => Promise.reject(mockedError));

await userEvent.click(screen.getByText(VERIFY));
Expand All @@ -196,7 +196,7 @@ describe('Board', () => {
it('should hidden timeout alert when the error type of api call becomes other', async () => {
const { getByLabelText, queryByLabelText } = setup();
await fillBoardFieldsInformation();
const timeoutError = new TimeoutError('', AXIOS_REQUEST_ERROR_CODE.TIMEOUT);
const timeoutError = new TimeoutError('', AxiosRequestErrorCode.Timeout);
boardClient.getVerifyBoard = jest.fn().mockImplementation(() => Promise.reject(timeoutError));

await userEvent.click(screen.getByText(VERIFY));
Expand Down Expand Up @@ -334,7 +334,7 @@ describe('Board', () => {
it('should close alert modal when user manually close the alert', async () => {
setup();
await fillBoardFieldsInformation();
const timeoutError = new TimeoutError('', AXIOS_REQUEST_ERROR_CODE.TIMEOUT);
const timeoutError = new TimeoutError('', AxiosRequestErrorCode.Timeout);
boardClient.getVerifyBoard = jest.fn().mockImplementation(() => Promise.reject(timeoutError));

await userEvent.click(screen.getByText(VERIFY));
Expand Down
Loading

0 comments on commit a3bc003

Please sign in to comment.