-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
114 additions
and
10 deletions.
There are no files selected for viewing
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
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
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
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
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,43 @@ | ||
import React, { useState } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { MenuItem } from '@dhis2/ui' | ||
import i18n from '@dhis2/d2-i18n' | ||
import { RunJobModal } from '../Modal' | ||
|
||
const RunQueueAction = ({ id, enabled, onComplete }) => { | ||
const [showModal, setShowModal] = useState(false) | ||
|
||
return ( | ||
<React.Fragment> | ||
<MenuItem | ||
dense | ||
onClick={() => { | ||
setShowModal(true) | ||
}} | ||
disabled={!enabled} | ||
label={i18n.t('Run manually')} | ||
/> | ||
{showModal && ( | ||
<RunJobModal | ||
id={id} | ||
hideModal={ | ||
/* istanbul ignore next */ | ||
() => setShowModal(false) | ||
} | ||
onComplete={onComplete} | ||
isQueue | ||
/> | ||
)} | ||
</React.Fragment> | ||
) | ||
} | ||
|
||
const { string, bool, func } = PropTypes | ||
|
||
RunQueueAction.propTypes = { | ||
id: string.isRequired, | ||
onComplete: func.isRequired, | ||
enabled: bool, | ||
} | ||
|
||
export default RunQueueAction |
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,23 @@ | ||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
import RunQueueAction from './RunQueueAction' | ||
|
||
describe('<RunQueueAction>', () => { | ||
it('shows the modal when MenuItem is clicked and the queue is enabled', () => { | ||
const wrapper = mount( | ||
<RunQueueAction id="id" enabled onComplete={() => {}} /> | ||
) | ||
|
||
expect(wrapper.find('RunJobModal')).toHaveLength(0) | ||
wrapper.find('a').simulate('click') | ||
expect(wrapper.find('RunJobModal')).toHaveLength(1) | ||
}) | ||
|
||
it('does not show the modal when MenuItem is clicked and the queue is disabled', () => { | ||
const wrapper = mount(<RunQueueAction id="id" onComplete={() => {}} />) | ||
|
||
expect(wrapper.find('RunJobModal')).toHaveLength(0) | ||
wrapper.find('a').simulate('click') | ||
expect(wrapper.find('RunJobModal')).toHaveLength(0) | ||
}) | ||
}) |
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