Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(ZNTA-1865): Write tests for CancellableProgressBar
- Loading branch information
Earl Floden
committed
Jul 6, 2017
1 parent
380caad
commit 456f7da
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...er/zanata-frontend/src/frontend/app/components/ProgressBar/CancellableProgressBar.test.js
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,59 @@ | ||
jest.disableAutomock() | ||
|
||
import React from 'react' | ||
import ReactDOMServer from 'react-dom/server' | ||
import CancellableProgressBar from './CancellableProgressBar' | ||
import { ProgressBar } from 'react-bootstrap' | ||
import { isProcessEnded } from '../../utils/EnumValueUtils' | ||
|
||
describe('CancellableProgressBarTest', () => { | ||
it('can render CancellableProgressBar markup', () => { | ||
const clickFun = () => {} | ||
const processShape = { | ||
url: '/rest/process/key/TMMergeForVerKey-1-ja', | ||
percentageComplete: 0, | ||
statusCode: 'Running' | ||
} | ||
const actual = ReactDOMServer.renderToStaticMarkup( | ||
<CancellableProgressBar onCancelOperation={clickFun} | ||
processStatus={processShape} buttonLabel='Cancel TM Merge' | ||
queryProgress={clickFun} /> | ||
) | ||
const expected = ReactDOMServer.renderToStaticMarkup( | ||
<div> | ||
<ProgressBar now={0}label={' 0%'} /> | ||
<button type='button' className='btn-danger btn btn-primary'> | ||
Cancel TM Merge | ||
</button> | ||
</div> | ||
) | ||
expect(actual).toEqual(expected) | ||
}) | ||
it('detects loading process completion', () => { | ||
const cancelledShape = { | ||
url: '/rest/process/key/TMMergeForVerKey-1-ja', | ||
percentageComplete: 0, | ||
statusCode: 'Cancelled' | ||
} | ||
const clickFun = () => {} | ||
// Test the isProcessEnded utils function | ||
const cancelled = isProcessEnded(cancelledShape) | ||
const cancelledExpected = true | ||
expect(cancelled).toEqual(cancelledExpected) | ||
// Test the CancellableProgressBar markup cancel button is disabled | ||
const actual = ReactDOMServer.renderToStaticMarkup( | ||
<CancellableProgressBar onCancelOperation={clickFun} | ||
processStatus={cancelledShape} buttonLabel='Cancel TM Merge' | ||
queryProgress={clickFun} /> | ||
) | ||
const expected = ReactDOMServer.renderToStaticMarkup( | ||
<div> | ||
<ProgressBar now={0}label={' 0%'} /> | ||
<button disabled type='button' className='btn-danger btn btn-primary'> | ||
Cancel TM Merge | ||
</button> | ||
</div> | ||
) | ||
expect(actual).toEqual(expected) | ||
}) | ||
}) |