From ad29bbd29636d0988a29941557e77c6c29080b73 Mon Sep 17 00:00:00 2001 From: ismay Date: Thu, 16 Nov 2023 15:10:24 +0100 Subject: [PATCH] refactor: rename switch --- cypress/integration/list/job-toggle/index.js | 8 ++++---- i18n/en.pot | 11 +++++++---- src/components/JobTable/JobTableRow.js | 4 ++-- src/components/JobTable/QueueTableRow.js | 5 +++-- .../Switches/{ToggleJobSwitch.js => JobSwitch.js} | 8 ++++---- .../{ToggleJobSwitch.test.js => JobSwitch.test.js} | 10 +++++----- src/components/Switches/index.js | 2 +- 7 files changed, 26 insertions(+), 22 deletions(-) rename src/components/Switches/{ToggleJobSwitch.js => JobSwitch.js} (86%) rename src/components/Switches/{ToggleJobSwitch.test.js => JobSwitch.test.js} (90%) diff --git a/cypress/integration/list/job-toggle/index.js b/cypress/integration/list/job-toggle/index.js index 87f9e5d11..d96b7f5ec 100644 --- a/cypress/integration/list/job-toggle/index.js +++ b/cypress/integration/list/job-toggle/index.js @@ -20,7 +20,7 @@ Given('the user navigated to the job list page', () => { }) Given('the job toggle switch is off', () => { - cy.findByRole('switch', { name: 'Toggle job' }).should('not.be.checked') + cy.findByRole('switch', { name: 'Enable' }).should('not.be.checked') }) When('the user clicks the enabled job toggle switch', () => { @@ -33,7 +33,7 @@ When('the user clicks the enabled job toggle switch', () => { { fixture: 'list/disabled-user-job' } ) - cy.findByRole('switch', { name: 'Toggle job' }).click() + cy.findByRole('switch', { name: 'Disable' }).click() }) When('the user clicks the disabled job toggle switch', () => { @@ -46,9 +46,9 @@ When('the user clicks the disabled job toggle switch', () => { { fixture: 'list/enabled-user-job' } ) - cy.findByRole('switch', { name: 'Toggle job' }).click() + cy.findByRole('switch', { name: 'Enable' }).click() }) Then('the job toggle switch is on', () => { - cy.findByRole('switch', { name: 'Toggle job' }).should('be.checked') + cy.findByRole('switch', { name: 'Disable' }).should('be.checked') }) diff --git a/i18n/en.pot b/i18n/en.pot index e5017e98e..98fa1b6a8 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-11-16T13:48:39.789Z\n" -"PO-Revision-Date: 2023-11-16T13:48:39.789Z\n" +"POT-Creation-Date: 2023-11-16T14:05:43.332Z\n" +"PO-Revision-Date: 2023-11-16T14:05:43.332Z\n" msgid "Something went wrong" msgstr "Something went wrong" @@ -259,8 +259,11 @@ 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" +msgid "Disable" +msgstr "Disable" + +msgid "Enable" +msgstr "Enable" msgid "New Job" msgstr "New Job" diff --git a/src/components/JobTable/JobTableRow.js b/src/components/JobTable/JobTableRow.js index 18c9b05b9..d73f5b582 100644 --- a/src/components/JobTable/JobTableRow.js +++ b/src/components/JobTable/JobTableRow.js @@ -2,7 +2,7 @@ import React from 'react' import PropTypes from 'prop-types' import { TableRow, TableCell } from '@dhis2/ui' import { jobTypesMap } from '../../services/server-translations' -import { ToggleJobSwitch } from '../Switches' +import { JobSwitch } from '../Switches' import JobActions from './JobActions' import Status from './Status' import NextRun from './NextRun' @@ -36,7 +36,7 @@ const JobTableRow = ({ - - { +const JobSwitch = ({ id, checked, disabled, refetch }) => { const [disableQuery] = useState({ resource: `jobConfigurations/${id}/disable`, type: 'create', @@ -27,18 +27,18 @@ const ToggleJobSwitch = ({ id, checked, disabled, refetch }) => { onChange={() => { toggleJob().then(refetch) }} - ariaLabel={i18n.t('Toggle job')} + ariaLabel={checked ? i18n.t('Disable') : i18n.t('Enable')} /> ) } const { bool, string, func } = PropTypes -ToggleJobSwitch.propTypes = { +JobSwitch.propTypes = { checked: bool.isRequired, disabled: bool.isRequired, id: string.isRequired, refetch: func.isRequired, } -export default ToggleJobSwitch +export default JobSwitch diff --git a/src/components/Switches/ToggleJobSwitch.test.js b/src/components/Switches/JobSwitch.test.js similarity index 90% rename from src/components/Switches/ToggleJobSwitch.test.js rename to src/components/Switches/JobSwitch.test.js index 1de96a98c..b66000251 100644 --- a/src/components/Switches/ToggleJobSwitch.test.js +++ b/src/components/Switches/JobSwitch.test.js @@ -2,12 +2,12 @@ import React from 'react' import waitForExpect from 'wait-for-expect' import { shallow, mount } from 'enzyme' import { CustomDataProvider } from '@dhis2/app-runtime' -import ToggleJobSwitch from './ToggleJobSwitch' +import JobSwitch from './JobSwitch' -describe('', () => { +describe('', () => { it('renders without errors', () => { shallow( - ', () => { refetch: refetchSpy, } const data = { 'jobConfigurations/id/enable': answerSpy } - const wrapper = mount(, { + const wrapper = mount(, { wrappingComponent: CustomDataProvider, wrappingComponentProps: { data }, }) @@ -58,7 +58,7 @@ describe('', () => { refetch: refetchSpy, } const data = { 'jobConfigurations/id/disable': answerSpy } - const wrapper = mount(, { + const wrapper = mount(, { wrappingComponent: CustomDataProvider, wrappingComponentProps: { data }, }) diff --git a/src/components/Switches/index.js b/src/components/Switches/index.js index 8987b2795..890554dd9 100644 --- a/src/components/Switches/index.js +++ b/src/components/Switches/index.js @@ -1 +1 @@ -export { default as ToggleJobSwitch } from './ToggleJobSwitch' +export { default as JobSwitch } from './JobSwitch'