From 75481c95bf25a55d9943253dbb0627d90be0bdb4 Mon Sep 17 00:00:00 2001
From: ismay <7355199+ismay@users.noreply.github.com>
Date: Wed, 16 Aug 2023 16:34:31 +0200
Subject: [PATCH] fix: add new route structure (#559)
* 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
---
.../add-route/back-to-all-jobs/index.js | 2 +-
.../add-route/create-parameter-jobs/index.js | 2 +-
.../create-parameterless-jobs/index.js | 2 +-
.../add-route/cron-presets/index.js | 2 +-
.../integration/add-route/info-link/index.js | 2 +-
.../add-sequence/back-to-all-jobs/index.js | 2 +-
.../add-sequence/create-sequence/index.js | 2 +-
.../edit-route/back-to-all-jobs/index.js | 2 +-
.../edit-route/cron-presets/index.js | 2 +-
.../edit-route/delete-button/index.js | 2 +-
.../edit-route/display-jobs/index.js | 2 +-
.../edit-route/edit-parameter-jobs/index.js | 2 +-
.../edit-parameterless-jobs/index.js | 2 +-
.../integration/edit-route/info-link/index.js | 2 +-
.../edit-sequence/back-to-all-jobs/index.js | 2 +-
.../edit-sequence/edit-sequence/index.js | 2 +-
.../integration/list-route/new-job/index.js | 2 +-
.../view-route/back-to-all-jobs/index.js | 2 +-
.../view-route/display-jobs/index.js | 2 +-
.../integration/view-route/info-link/index.js | 2 +-
i18n/en.pot | 24 ++---
src/components/FormFields/NameField.js | 51 ++++++++---
src/components/FormFields/NameField.test.js | 52 +++++++++++
src/components/Forms/SequenceAddForm.js | 2 +-
src/components/Forms/SequenceEditForm.js | 2 +-
src/components/Forms/SequenceEditForm.test.js | 4 +
src/components/JobTable/EditJobAction.js | 2 +-
src/components/JobTable/EditJobAction.test.js | 2 +-
src/components/JobTable/ViewJobAction.js | 2 +-
src/components/JobTable/ViewJobAction.test.js | 2 +-
src/components/Routes/JobViewOrEdit.js | 37 ++++++++
src/components/Routes/JobViewOrEdit.test.js | 88 +++++++++++++++++++
src/components/Routes/Routes.js | 21 +++--
src/hooks/jobs/use-jobs.js | 1 +
src/pages/JobEdit/JobEdit.js | 40 ++++-----
src/pages/JobEdit/JobEdit.test.js | 61 ++-----------
src/pages/JobList/JobList.js | 4 +-
src/pages/JobView/JobView.js | 39 ++++----
src/pages/JobView/JobView.test.js | 65 +++-----------
39 files changed, 324 insertions(+), 215 deletions(-)
create mode 100644 src/components/Routes/JobViewOrEdit.js
create mode 100644 src/components/Routes/JobViewOrEdit.test.js
diff --git a/cypress/integration/add-route/back-to-all-jobs/index.js b/cypress/integration/add-route/back-to-all-jobs/index.js
index 6642e76ff..f7bd9a2b1 100644
--- a/cypress/integration/add-route/back-to-all-jobs/index.js
+++ b/cypress/integration/add-route/back-to-all-jobs/index.js
@@ -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')
})
diff --git a/cypress/integration/add-route/create-parameter-jobs/index.js b/cypress/integration/add-route/create-parameter-jobs/index.js
index 51f71e91c..f7d93ba6d 100644
--- a/cypress/integration/add-route/create-parameter-jobs/index.js
+++ b/cypress/integration/add-route/create-parameter-jobs/index.js
@@ -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')
})
diff --git a/cypress/integration/add-route/create-parameterless-jobs/index.js b/cypress/integration/add-route/create-parameterless-jobs/index.js
index d71b13177..632fd9289 100644
--- a/cypress/integration/add-route/create-parameterless-jobs/index.js
+++ b/cypress/integration/add-route/create-parameterless-jobs/index.js
@@ -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')
})
diff --git a/cypress/integration/add-route/cron-presets/index.js b/cypress/integration/add-route/cron-presets/index.js
index c1cf88529..34ceb81df 100644
--- a/cypress/integration/add-route/cron-presets/index.js
+++ b/cypress/integration/add-route/cron-presets/index.js
@@ -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')
})
diff --git a/cypress/integration/add-route/info-link/index.js b/cypress/integration/add-route/info-link/index.js
index 2243c584d..d90b71deb 100644
--- a/cypress/integration/add-route/info-link/index.js
+++ b/cypress/integration/add-route/info-link/index.js
@@ -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')
})
diff --git a/cypress/integration/add-sequence/back-to-all-jobs/index.js b/cypress/integration/add-sequence/back-to-all-jobs/index.js
index 34f6d6f50..ab796ac08 100644
--- a/cypress/integration/add-sequence/back-to-all-jobs/index.js
+++ b/cypress/integration/add-sequence/back-to-all-jobs/index.js
@@ -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')
})
diff --git a/cypress/integration/add-sequence/create-sequence/index.js b/cypress/integration/add-sequence/create-sequence/index.js
index 565fc9d04..9a5e6dbd9 100644
--- a/cypress/integration/add-sequence/create-sequence/index.js
+++ b/cypress/integration/add-sequence/create-sequence/index.js
@@ -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')
})
diff --git a/cypress/integration/edit-route/back-to-all-jobs/index.js b/cypress/integration/edit-route/back-to-all-jobs/index.js
index e37d27fa1..6165cefc3 100644
--- a/cypress/integration/edit-route/back-to-all-jobs/index.js
+++ b/cypress/integration/edit-route/back-to-all-jobs/index.js
@@ -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')
})
diff --git a/cypress/integration/edit-route/cron-presets/index.js b/cypress/integration/edit-route/cron-presets/index.js
index ae862228b..8a13a2926 100644
--- a/cypress/integration/edit-route/cron-presets/index.js
+++ b/cypress/integration/edit-route/cron-presets/index.js
@@ -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')
})
diff --git a/cypress/integration/edit-route/delete-button/index.js b/cypress/integration/edit-route/delete-button/index.js
index 37fd88b6a..a762932a3 100644
--- a/cypress/integration/edit-route/delete-button/index.js
+++ b/cypress/integration/edit-route/delete-button/index.js
@@ -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')
})
diff --git a/cypress/integration/edit-route/display-jobs/index.js b/cypress/integration/edit-route/display-jobs/index.js
index 0cf40a184..db12c9bef 100644
--- a/cypress/integration/edit-route/display-jobs/index.js
+++ b/cypress/integration/edit-route/display-jobs/index.js
@@ -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')
})
diff --git a/cypress/integration/edit-route/edit-parameter-jobs/index.js b/cypress/integration/edit-route/edit-parameter-jobs/index.js
index 5a7b70b00..8c9a30cb3 100644
--- a/cypress/integration/edit-route/edit-parameter-jobs/index.js
+++ b/cypress/integration/edit-route/edit-parameter-jobs/index.js
@@ -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')
})
diff --git a/cypress/integration/edit-route/edit-parameterless-jobs/index.js b/cypress/integration/edit-route/edit-parameterless-jobs/index.js
index e960112dd..e3feb3874 100644
--- a/cypress/integration/edit-route/edit-parameterless-jobs/index.js
+++ b/cypress/integration/edit-route/edit-parameterless-jobs/index.js
@@ -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')
})
diff --git a/cypress/integration/edit-route/info-link/index.js b/cypress/integration/edit-route/info-link/index.js
index 7e9f15a8c..685499aa8 100644
--- a/cypress/integration/edit-route/info-link/index.js
+++ b/cypress/integration/edit-route/info-link/index.js
@@ -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')
})
diff --git a/cypress/integration/edit-sequence/back-to-all-jobs/index.js b/cypress/integration/edit-sequence/back-to-all-jobs/index.js
index 6ea9e92c9..83f9702d3 100644
--- a/cypress/integration/edit-sequence/back-to-all-jobs/index.js
+++ b/cypress/integration/edit-sequence/back-to-all-jobs/index.js
@@ -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')
})
diff --git a/cypress/integration/edit-sequence/edit-sequence/index.js b/cypress/integration/edit-sequence/edit-sequence/index.js
index 25f11793c..cbc6022bd 100644
--- a/cypress/integration/edit-sequence/edit-sequence/index.js
+++ b/cypress/integration/edit-sequence/edit-sequence/index.js
@@ -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')
})
diff --git a/cypress/integration/list-route/new-job/index.js b/cypress/integration/list-route/new-job/index.js
index 6d11c0917..ff54ef2c9 100644
--- a/cypress/integration/list-route/new-job/index.js
+++ b/cypress/integration/list-route/new-job/index.js
@@ -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')
})
diff --git a/cypress/integration/view-route/back-to-all-jobs/index.js b/cypress/integration/view-route/back-to-all-jobs/index.js
index a7515e79a..37ef3f10f 100644
--- a/cypress/integration/view-route/back-to-all-jobs/index.js
+++ b/cypress/integration/view-route/back-to-all-jobs/index.js
@@ -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'
)
diff --git a/cypress/integration/view-route/display-jobs/index.js b/cypress/integration/view-route/display-jobs/index.js
index d2d8c910a..495e0dc77 100644
--- a/cypress/integration/view-route/display-jobs/index.js
+++ b/cypress/integration/view-route/display-jobs/index.js
@@ -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'
)
diff --git a/cypress/integration/view-route/info-link/index.js b/cypress/integration/view-route/info-link/index.js
index 3941c582c..f00182677 100644
--- a/cypress/integration/view-route/info-link/index.js
+++ b/cypress/integration/view-route/info-link/index.js
@@ -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'
)
diff --git a/i18n/en.pot b/i18n/en.pot
index 1302c6572..b62bf2679 100644
--- a/i18n/en.pot
+++ b/i18n/en.pot
@@ -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"
@@ -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"
@@ -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 }}"
diff --git a/src/components/FormFields/NameField.js b/src/components/FormFields/NameField.js
index 8c7102677..76e16c54e 100644
--- a/src/components/FormFields/NameField.js
+++ b/src/components/FormFields/NameField.js
@@ -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 = () => (
-
-)
+
+// 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 (
+
+ )
+}
+
+NameField.defaultProps = {
+ isQueue: false,
+}
+
+const { bool } = PropTypes
+
+NameField.propTypes = {
+ isQueue: bool,
+}
export default NameField
diff --git a/src/components/FormFields/NameField.test.js b/src/components/FormFields/NameField.test.js
index 1732dd757..4ae4c7152 100644
--- a/src/components/FormFields/NameField.test.js
+++ b/src/components/FormFields/NameField.test.js
@@ -27,4 +27,56 @@ describe('', () => {
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(
+
+ )}
+
+ )
+
+ 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(
+
+ )}
+
+ )
+
+ 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))
+ })
})
diff --git a/src/components/Forms/SequenceAddForm.js b/src/components/Forms/SequenceAddForm.js
index bd6796533..e46585e3f 100644
--- a/src/components/Forms/SequenceAddForm.js
+++ b/src/components/Forms/SequenceAddForm.js
@@ -20,7 +20,7 @@ const SequenceAddForm = ({
return (