Skip to content

Commit

Permalink
[frontend]ADM-728: extra const and change type for placement (#957)
Browse files Browse the repository at this point in the history
* ADM-728 [frontend] refactor: extra const and change type for Placement

* ADM-728 [frontend] refactor: use const from fixtures

* ADM-728 [frontend] refactor: add onBack function

* ADM-728 [frontend] refactor: rename
  • Loading branch information
lxuebing authored Jan 18, 2024
1 parent 2f49b93 commit bf5840c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 36 deletions.
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,14 +140,11 @@ const BoardMetrics = ({
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());
Expand All @@ -161,9 +158,9 @@ const BoardMetrics = ({
{!(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

0 comments on commit bf5840c

Please sign in to comment.