forked from thoughtworks/HeartBeat
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADM-699: [frontend] test: prompt test coverage
- Loading branch information
Showing
2 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
frontend/__tests__/src/components/Metrics/ReportStep/BoardMetrics.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import clearAllMocks = jest.clearAllMocks; | ||
import BoardMetrics from '@src/components/Metrics/ReportStep/BoradMetrics'; | ||
import { MOCK_REPORT_RESPONSE } from '../../../../src/fixtures'; | ||
import { setupStore } from '../../../../src/utils/setupStoreUtil'; | ||
import { Provider } from 'react-redux'; | ||
import { RETRY } from '@src/constants/resources'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
describe('Report Card', () => { | ||
afterEach(() => { | ||
clearAllMocks(); | ||
}); | ||
|
||
let store = setupStore(); | ||
|
||
const mockData = { | ||
...MOCK_REPORT_RESPONSE, | ||
reportError: { | ||
pipelineError: null, | ||
sourceControlError: null, | ||
boardError: { | ||
status: 404, | ||
message: 'Not Found', | ||
}, | ||
}, | ||
}; | ||
|
||
const mockHandleRetry = jest.fn(); | ||
const onShowDetail = jest.fn(); | ||
|
||
const setup = () => { | ||
store = setupStore(); | ||
return render( | ||
<Provider store={store}> | ||
<BoardMetrics | ||
isBackFromDetail={false} | ||
startDate={''} | ||
endDate={''} | ||
startToRequestBoardData={mockHandleRetry} | ||
onShowDetail={onShowDetail} | ||
boardReport={mockData} | ||
csvTimeStamp={1705014731} | ||
timeoutError={''} | ||
/> | ||
</Provider> | ||
); | ||
}; | ||
|
||
it('should show retry button when have reportError and click retry will triger api call', async () => { | ||
const { getByText } = setup(); | ||
|
||
expect(getByText(RETRY)).toBeInTheDocument(); | ||
|
||
await userEvent.click(getByText(RETRY)); | ||
|
||
expect(mockHandleRetry).toHaveBeenCalled(); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
frontend/__tests__/src/components/Metrics/ReportStep/DoraMetrics.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import clearAllMocks = jest.clearAllMocks; | ||
import DoraMetrics from '@src/components/Metrics/ReportStep/DoraMetrics'; | ||
import { MOCK_REPORT_RESPONSE } from '../../../../src/fixtures'; | ||
import { setupStore } from '../../../../src/utils/setupStoreUtil'; | ||
import { Provider } from 'react-redux'; | ||
import { RETRY } from '@src/constants/resources'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
describe('Report Card', () => { | ||
afterEach(() => { | ||
clearAllMocks(); | ||
}); | ||
|
||
let store = setupStore(); | ||
|
||
const mockData = { | ||
...MOCK_REPORT_RESPONSE, | ||
reportError: { | ||
boardError: null, | ||
sourceControlError: { | ||
status: 404, | ||
message: 'Not Found', | ||
}, | ||
pipelineError: { | ||
status: 404, | ||
message: 'Not Found', | ||
}, | ||
}, | ||
}; | ||
|
||
const mockHandleRetry = jest.fn(); | ||
const onShowDetail = jest.fn(); | ||
|
||
const setup = () => { | ||
store = setupStore(); | ||
return render( | ||
<Provider store={store}> | ||
<DoraMetrics | ||
isBackFromDetail={false} | ||
startDate={''} | ||
endDate={''} | ||
startToRequestDoraData={mockHandleRetry} | ||
onShowDetail={onShowDetail} | ||
doraReport={mockData} | ||
csvTimeStamp={1705014731} | ||
timeoutError={''} | ||
/> | ||
</Provider> | ||
); | ||
}; | ||
|
||
it('should show retry button when have reportError and click retry will triger api call', async () => { | ||
const { getByText } = setup(); | ||
|
||
expect(getByText(RETRY)).toBeInTheDocument(); | ||
|
||
await userEvent.click(getByText(RETRY)); | ||
|
||
expect(mockHandleRetry).toHaveBeenCalled(); | ||
}); | ||
}); |