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

[frontend]ADM-728: extra const and change type for placement #957

Merged
merged 5 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import ReportForThreeColumns from '@src/components/Common/ReportForThreeColumns';
import clearAllMocks = jest.clearAllMocks;
import { LOADING, VELOCITY } from '../../fixtures';

describe('Report for three columns', () => {
afterEach(() => {
clearAllMocks();
});

it('should show loading when data is empty', () => {
render(<ReportForThreeColumns title='title' fieldName='fieldName' listName='listName' data={undefined} />);
render(<ReportForThreeColumns title={VELOCITY} fieldName='fieldName' listName='listName' data={null} />);

expect(screen.getByTestId('loading')).toBeInTheDocument();
expect(screen.getByText('title')).toBeInTheDocument();
expect(screen.getByTestId(LOADING)).toBeInTheDocument();
expect(screen.getByText(VELOCITY)).toBeInTheDocument();
});

it('should show table when has data', () => {
it('should show table when data is not empty', () => {
const mockData = [
{ id: 0, name: 'name1', valuesList: [{ name: 'test1', value: '1' }] },
{ id: 1, name: 'name2', valuesList: [{ name: 'test2', value: '2' }] },
{ id: 2, name: 'name3', valuesList: [{ name: 'test3', value: '3' }] },
];

render(<ReportForThreeColumns title='title' fieldName='fieldName' listName='listName' data={mockData} />);
render(<ReportForThreeColumns title={VELOCITY} fieldName='fieldName' listName='listName' data={mockData} />);

expect(screen.getByTestId('title')).toBeInTheDocument();
expect(screen.getByTestId(VELOCITY)).toBeInTheDocument();
});
});
13 changes: 7 additions & 6 deletions frontend/__tests__/src/components/Loading/Loading.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { Loading } from '@src/components/Loading';
import { LOADING } from '../../fixtures';

describe('Loading', () => {
it('should show Loading', () => {
Expand All @@ -11,20 +12,20 @@ describe('Loading', () => {
});

it('should show Loading message when has message', () => {
render(<Loading message={'loading...'} />);
render(<Loading message={LOADING} />);

expect(screen.getByText('loading...')).toBeInTheDocument();
expect(screen.getByText(LOADING)).toBeInTheDocument();
});

it('should in page center when placement is center', () => {
render(<Loading placement={'center'} />);

expect(screen.getByTestId('loading')).toHaveStyle({ 'align-items': 'center' });
expect(screen.getByTestId(LOADING)).toHaveStyle({ 'align-items': 'center' });
});

it('should in page start when placement is start', () => {
render(<Loading placement={'start'} />);
it('should in page start when placement is left', () => {
render(<Loading placement={'left'} />);

expect(screen.getByTestId('loading')).toHaveStyle({ 'align-items': 'flex-start' });
expect(screen.getByTestId(LOADING)).toHaveStyle({ 'align-items': 'flex-start' });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('board', () => {

render(
<Provider store={setupStore()}>
<BoardDetail data={data} onBack={jest.fn()} />
<BoardDetail data={data} onBack={() => 'back'} />
</Provider>
);

Expand All @@ -39,7 +39,7 @@ describe('board', () => {

render(
<Provider store={setupStore()}>
<BoardDetail data={data} onBack={jest.fn()} />
<BoardDetail data={data} onBack={() => 'back'} />
</Provider>
);

Expand All @@ -56,7 +56,7 @@ describe('board', () => {

render(
<Provider store={setupStore()}>
<BoardDetail data={data} onBack={jest.fn()} />
<BoardDetail data={data} onBack={() => 'back'} />
</Provider>
);

Expand All @@ -76,7 +76,7 @@ describe('board', () => {

render(
<Provider store={setupStore()}>
<BoardDetail data={data} onBack={jest.fn()} />
<BoardDetail data={data} onBack={() => 'back'} />
</Provider>
);

Expand All @@ -93,7 +93,7 @@ describe('board', () => {

render(
<Provider store={setupStore()}>
<BoardDetail data={data} onBack={jest.fn()} />
<BoardDetail data={data} onBack={() => 'back'} />
</Provider>
);

Expand All @@ -116,7 +116,7 @@ describe('board', () => {

render(
<Provider store={store}>
<BoardDetail data={data} onBack={jest.fn()} />
<BoardDetail data={data} onBack={() => 'back'} />
</Provider>
);

Expand All @@ -133,7 +133,7 @@ describe('board', () => {

render(
<Provider store={setupStore()}>
<BoardDetail data={data} onBack={jest.fn()} />
<BoardDetail data={data} onBack={() => 'back'} />
</Provider>
);

Expand All @@ -159,7 +159,7 @@ describe('board', () => {

render(
<Provider store={store}>
<BoardDetail data={data} onBack={jest.fn()} />
<BoardDetail data={data} onBack={() => 'back'} />
</Provider>
);

Expand Down
2 changes: 2 additions & 0 deletions frontend/__tests__/src/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const CHINA_CALENDAR = 'Calendar with Chinese Holiday';

export const NEXT = 'Next';

export const LOADING = 'loading';

export const PREVIOUS = 'Previous';

export const SAVE = 'Save';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Loading/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CircularProgress } from '@mui/material';
import { LoadingDrop, LoadingTypography } from './style';
import React from 'react';

export type Placement = 'start' | 'center';
export type Placement = 'left' | 'center';

export interface LoadingProps {
message?: string;
Expand Down
17 changes: 7 additions & 10 deletions frontend/src/containers/ReportStep/BoradMetrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,15 @@
startToRequestBoardData(getBoardReportRequestBody());
};

const isShowShowMoreLoading = () => {
return (
boardMetrics.length === 1 &&
boardMetrics[0] === REQUIRED_DATA.CLASSIFICATION &&
!(timeoutError || getErrorMessage()) &&
!boardReport?.boardMetricsCompleted
);
};
const isShowMoreLoadingDisplay = () =>
boardMetrics.length === 1 &&
boardMetrics[0] === REQUIRED_DATA.CLASSIFICATION &&
!(timeoutError || getErrorMessage()) &&
!boardReport?.boardMetricsCompleted;

useEffect(() => {
!isBackFromDetail && startToRequestBoardData(getBoardReportRequestBody());
}, []);

Check warning on line 151 in frontend/src/containers/ReportStep/BoradMetrics/index.tsx

View workflow job for this annotation

GitHub Actions / frontend-check

React Hook useEffect has missing dependencies: 'getBoardReportRequestBody', 'isBackFromDetail', and 'startToRequestBoardData'. Either include them or remove the dependency array. If 'startToRequestBoardData' changes too often, find the parent component that defines it and wrap that definition in useCallback

Check warning on line 151 in frontend/src/containers/ReportStep/BoradMetrics/index.tsx

View workflow job for this annotation

GitHub Actions / frontend-check

React Hook useEffect has missing dependencies: 'getBoardReportRequestBody', 'isBackFromDetail', and 'startToRequestBoardData'. Either include them or remove the dependency array. If 'startToRequestBoardData' changes too often, find the parent component that defines it and wrap that definition in useCallback

return (
<>
Expand All @@ -161,9 +158,9 @@
{!(timeoutError || getErrorMessage()) && boardReport?.boardMetricsCompleted && (
<StyledShowMore onClick={onShowDetail}>{SHOW_MORE}</StyledShowMore>
)}
{isShowShowMoreLoading() && (
{isShowMoreLoadingDisplay() && (
<StyledLoading>
<Loading placement='start' size='0.8rem' backgroundColor='transparent' />
<Loading placement='left' size='0.8rem' backgroundColor='transparent' />
</StyledLoading>
)}
{(timeoutError || getErrorMessage()) && <StyledRetry onClick={handleRetry}>{RETRY}</StyledRetry>}
Expand Down
Loading