Skip to content

Commit

Permalink
fix: add new route structure (#559)
Browse files Browse the repository at this point in the history
* fix: add new route structure

* test: update tests to route changes

* refactor: update internal routes to new routing pattern

* test: update cypress links to new routing pattern

* test: add checkjobtype test

* chore: rename checkjobtype to jobvieworedit

* fix: ensure queues can not be named add
  • Loading branch information
ismay authored Aug 16, 2023
1 parent bfdb632 commit 75481c9
Show file tree
Hide file tree
Showing 39 changed files with 324 additions and 215 deletions.
2 changes: 1 addition & 1 deletion cypress/integration/add-route/back-to-all-jobs/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'

Given('the user navigated to the add job page', () => {
cy.visit('/#/add')
cy.visit('/#/job/add')
cy.findByRole('heading', { name: 'New Job' }).should('exist')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const saveAndExpect = (expected) => {
*/

Given('the user navigated to the add job page', () => {
cy.visit('/#/add')
cy.visit('/#/job/add')
cy.findByRole('heading', { name: 'New Job' }).should('exist')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const saveAndExpect = (expected) => {
*/

Given('the user navigated to the add job page', () => {
cy.visit('/#/add')
cy.visit('/#/job/add')
cy.findByRole('heading', { name: 'New Job' }).should('exist')
})

Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/add-route/cron-presets/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'

Given('the user navigated to the add job page', () => {
cy.visit('/#/add')
cy.visit('/#/job/add')
cy.findByRole('heading', { name: 'New Job' }).should('exist')
})

Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/add-route/info-link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const infoHref =
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-236/maintaining-the-system/scheduling.html'

Given('the user navigated to the add job page', () => {
cy.visit('/#/add')
cy.visit('/#/job/add')
cy.findByRole('heading', { name: 'New Job' }).should('exist')
})

Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/add-sequence/back-to-all-jobs/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'

Given('the user navigated to the add sequence page', () => {
cy.visit('/#/add-sequence')
cy.visit('/#/queue/add')
cy.findByRole('heading', { name: 'New Sequence' }).should('exist')
})

Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/add-sequence/create-sequence/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Given('two unqueued jobs exist', () => {
})

Given('the user navigated to the add sequence page', () => {
cy.visit('/#/add-sequence')
cy.visit('/#/queue/add')
cy.findByRole('heading', { name: 'New Sequence' }).should('exist')
})

Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/edit-route/back-to-all-jobs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Given('a single user job exists', () => {
})

Given('the user navigated to the edit job page', () => {
cy.visit('/#/edit/lnWRZN67iDU')
cy.visit('/#/job/lnWRZN67iDU')
cy.findByRole('heading', { name: 'Job: Job 1' }).should('exist')
})

Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/edit-route/cron-presets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Given('a single cron scheduled user job exists', () => {
})

Given('the user navigated to the edit job page', () => {
cy.visit('/#/edit/lnWRZN67iDU')
cy.visit('/#/job/lnWRZN67iDU')
cy.findByRole('heading', { name: 'Job: Job 1' }).should('exist')
})

Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/edit-route/delete-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Given('a single user job exists', () => {
})

Given('the user navigated to the edit job page', () => {
cy.visit('/#/edit/lnWRZN67iDU')
cy.visit('/#/job/lnWRZN67iDU')
cy.findByRole('heading', { name: 'Job: Job 1' }).should('exist')
})

Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/edit-route/display-jobs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Given('the user navigated to the edit job page', () => {
const now = new Date(2021, 3, 10).getTime()
cy.clock(now)

cy.visit('/#/edit/lnWRZN67iDU')
cy.visit('/#/job/lnWRZN67iDU')
cy.findByRole('heading', { name: 'Job: Job 1' }).should('exist')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Given('a single user job exists', () => {
})

Given('the user navigated to the edit job page', () => {
cy.visit('/#/edit/lnWRZN67iDU')
cy.visit('/#/job/lnWRZN67iDU')
cy.findByRole('heading', { name: 'Job: Job 1' }).should('exist')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Given('a single user job with parameters exists', () => {
})

Given('the user navigated to the edit job page', () => {
cy.visit('/#/edit/lnWRZN67iDU')
cy.visit('/#/job/lnWRZN67iDU')
cy.findByRole('heading', { name: 'Job: Job 1' }).should('exist')
})

Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/edit-route/info-link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Given('a single user job exists', () => {
})

Given('the user navigated to the edit job page', () => {
cy.visit('/#/edit/lnWRZN67iDU')
cy.visit('/#/job/lnWRZN67iDU')
cy.findByRole('heading', { name: 'Job: Job 1' }).should('exist')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Given('a sequence exists', () => {
})

Given('the user navigates to the edit sequence page', () => {
cy.visit('/#/edit-sequence/RWcaltWoKuN')
cy.visit('/#/queue/RWcaltWoKuN')
cy.findByRole('heading', { name: 'Sequence: one' }).should('exist')
})

Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/edit-sequence/edit-sequence/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Given('two unqueued jobs exist', () => {
})

Given('the user navigates to the edit sequence page', () => {
cy.visit('/#/edit-sequence/RWcaltWoKuN')
cy.visit('/#/queue/RWcaltWoKuN')
cy.findByRole('heading', { name: 'Sequence: one' }).should('exist')
})

Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/list-route/new-job/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Given('the user navigated to the job list page', () => {
Then('there is a link to the new job page', () => {
cy.findByRole('link', { name: 'New job' })
.should('exist')
.should('have.attr', 'href', '#/add')
.should('have.attr', 'href', '#/job/add')
})
2 changes: 1 addition & 1 deletion cypress/integration/view-route/back-to-all-jobs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Given('a single system job exists', () => {
})

Given('the user navigated to the view job page', () => {
cy.visit('/#/view/sHMedQF7VYa')
cy.visit('/#/job/sHMedQF7VYa')
cy.findByRole('heading', { name: 'System job: System Job 1' }).should(
'exist'
)
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/view-route/display-jobs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Given('the user navigated to the view job page', () => {
const now = new Date(2021, 3, 10).getTime()
cy.clock(now)

cy.visit('/#/view/sHMedQF7VYa')
cy.visit('/#/job/sHMedQF7VYa')
cy.findByRole('heading', { name: 'System job: System Job 1' }).should(
'exist'
)
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/view-route/info-link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Given('a single system job exists', () => {
})

Given('the user navigated to the view job page', () => {
cy.visit('/#/view/sHMedQF7VYa')
cy.visit('/#/job/sHMedQF7VYa')
cy.findByRole('heading', { name: 'System job: System Job 1' }).should(
'exist'
)
Expand Down
24 changes: 12 additions & 12 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2023-08-03T07:44:07.705Z\n"
"PO-Revision-Date: 2023-08-03T07:44:07.705Z\n"
"POT-Creation-Date: 2023-08-15T13:43:45.474Z\n"
"PO-Revision-Date: 2023-08-15T13:43:45.474Z\n"

msgid "Something went wrong"
msgstr "Something went wrong"
Expand Down Expand Up @@ -231,6 +231,16 @@ msgstr "Are you sure you want to run this job?"
msgid "Run"
msgstr "Run"

msgid "Could not load requested job"
msgstr "Could not load requested job"

msgid ""
"Something went wrong whilst loading the requested job. Make sure it has not "
"been deleted and try refreshing the page."
msgstr ""
"Something went wrong whilst loading the requested job. Make sure it has not "
"been deleted and try refreshing the page."

msgid "Toggle job"
msgstr "Toggle job"

Expand All @@ -243,16 +253,6 @@ msgstr "Configuration"
msgid "About job configuration"
msgstr "About job configuration"

msgid "Could not load requested job"
msgstr "Could not load requested job"

msgid ""
"Something went wrong whilst loading the requested job. Make sure it has not "
"been deleted and try refreshing the page."
msgstr ""
"Something went wrong whilst loading the requested job. Make sure it has not "
"been deleted and try refreshing the page."

msgid "Job: {{ name }}"
msgstr "Job: {{ name }}"

Expand Down
51 changes: 39 additions & 12 deletions src/components/FormFields/NameField.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,50 @@ import {
hasValue,
string,
} from '@dhis2/ui'
import PropTypes from 'prop-types'
import i18n from '@dhis2/d2-i18n'

const { Field } = ReactFinalForm

// The key under which this field will be sent to the backend
const FIELD_NAME = 'name'
const VALIDATOR = composeValidators(string, hasValue)

const NameField = () => (
<Field
name={FIELD_NAME}
component={InputFieldFF}
validate={VALIDATOR}
label={i18n.t('Name')}
type="text"
required
/>
)

// Validation
const restrictedNames = (value) => {
if (typeof value !== 'string') {
return
}

return value.toLowerCase() === 'add'
? i18n.t('Queues can\'t be named "Add" or "add"')
: undefined
}
const defaultValidators = [string, hasValue]
const queueValidators = [...defaultValidators, restrictedNames]

const NameField = ({ isQueue }) => {
const validators = isQueue ? queueValidators : defaultValidators

return (
<Field
name={FIELD_NAME}
component={InputFieldFF}
validate={composeValidators(...validators)}
label={i18n.t('Name')}
type="text"
required
/>
)
}

NameField.defaultProps = {
isQueue: false,
}

const { bool } = PropTypes

NameField.propTypes = {
isQueue: bool,
}

export default NameField
52 changes: 52 additions & 0 deletions src/components/FormFields/NameField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,56 @@ describe('<NameField>', () => {

expect(actual).toEqual(expect.stringMatching(expected))
})

it('does not allow naming a queue "Add"', () => {
const expected = 'Queues can\'t be named "Add" or "add"'
const wrapper = mount(
<Form onSubmit={() => {}}>
{({ handleSubmit }) => (
<form onSubmit={handleSubmit}>
<NameField isQueue />
</form>
)}
</Form>
)

wrapper
.find('input[name="name"]')
.simulate('change', { target: { value: 'Add' } })

// Trigger validation
wrapper.find('form').simulate('submit')

const actual = wrapper
.find({ 'data-test': 'dhis2-uiwidgets-inputfield-validation' })
.text()

expect(actual).toEqual(expect.stringMatching(expected))
})

it('does not allow naming a queue "add"', () => {
const expected = 'Queues can\'t be named "Add" or "add"'
const wrapper = mount(
<Form onSubmit={() => {}}>
{({ handleSubmit }) => (
<form onSubmit={handleSubmit}>
<NameField isQueue />
</form>
)}
</Form>
)

wrapper
.find('input[name="name"]')
.simulate('change', { target: { value: 'add' } })

// Trigger validation
wrapper.find('form').simulate('submit')

const actual = wrapper
.find({ 'data-test': 'dhis2-uiwidgets-inputfield-validation' })
.text()

expect(actual).toEqual(expect.stringMatching(expected))
})
})
2 changes: 1 addition & 1 deletion src/components/Forms/SequenceAddForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const SequenceAddForm = ({
return (
<form onSubmit={handleSubmit}>
<Box maxWidth="600px">
<NameField />
<NameField isQueue />
</Box>
<Box marginTop="16px" maxWidth="400px">
<CronField />
Expand Down
2 changes: 1 addition & 1 deletion src/components/Forms/SequenceEditForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const SequenceEditForm = ({
return (
<form onSubmit={handleSubmit}>
<Box maxWidth="600px">
<NameField />
<NameField isQueue />
</Box>
<Box marginTop="16px" maxWidth="400px">
<CronField />
Expand Down
4 changes: 4 additions & 0 deletions src/components/Forms/SequenceEditForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('<SequenceEditForm>', () => {
it('shows submit errors if there are any', () => {
const message = 'Generic submit error'
const props = {
name: 'name',
handleSubmit: () => {},
pristine: false,
submitting: false,
Expand All @@ -41,6 +42,7 @@ describe('<SequenceEditForm>', () => {

it('shows a spinner when submitting', () => {
const props = {
name: 'name',
handleSubmit: () => {},
pristine: false,
submitting: true,
Expand Down Expand Up @@ -71,6 +73,7 @@ describe('<SequenceEditForm>', () => {

it('disables the submit button when pristine', () => {
const props = {
name: 'name',
handleSubmit: () => {},
pristine: true,
submitting: false,
Expand All @@ -96,6 +99,7 @@ describe('<SequenceEditForm>', () => {

it('disables the submit button when submitting', () => {
const props = {
name: 'name',
handleSubmit: () => {},
pristine: false,
submitting: true,
Expand Down
Loading

1 comment on commit 75481c9

@dhis2-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.