From fc8af80b840a3322950033609cb2a2b5d51367c7 Mon Sep 17 00:00:00 2001 From: Gilbert Cherrie Date: Wed, 16 Jul 2025 09:16:20 -0400 Subject: [PATCH 1/3] Fix start page not being honoured --- .../components/visual-settings-form/index.jsx | 41 +++++++++++++------ .../visual-settings-form.schema.js | 6 +-- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/app/javascript/components/visual-settings-form/index.jsx b/app/javascript/components/visual-settings-form/index.jsx index 39e40c069f8..3785508b0da 100644 --- a/app/javascript/components/visual-settings-form/index.jsx +++ b/app/javascript/components/visual-settings-form/index.jsx @@ -5,21 +5,36 @@ import MiqFormRenderer from '@@ddf'; import createSchema from './visual-settings-form.schema'; const VisualSettingsForm = ({ recordId }) => { - const [{ initialValues, timezoneOptions, isLoading }, setState] = useState({ isLoading: true }); + const [{ + initialValues, shortcuts, timezoneOptions, isLoading, + }, setState] = useState({ isLoading: true }); useEffect(() => { - API.get('/api').then(({ timezones }) => { - const timezoneOptions = []; - timezones.forEach((timezone) => { - timezoneOptions.push({ value: timezone.name, label: timezone.description }); + API.get('/api/shortcuts?expand=resources&attributes=description,url').then(({ resources }) => { + const shortcuts = []; + + resources.forEach((shortcut) => { + shortcuts.push({ value: shortcut.url, label: shortcut.description }); + }); + + return shortcuts; + }).then((shortcuts) => { + API.get('/api').then(({ timezones }) => { + const timezoneOptions = []; + + timezones.forEach((timezone) => { + timezoneOptions.push({ value: timezone.name, label: timezone.description }); + }); + + return timezoneOptions; + }).then((timezoneOptions) => { + API.get(`/api/users/${recordId}?attributes=settings`).then(({ settings }) => setState({ + initialValues: settings, + shortcuts, + timezoneOptions, + isLoading: false, + })); }); - return timezoneOptions; - }).then((timezoneOptions) => { - API.get(`/api/users/${recordId}?attributes=settings`).then(({ settings }) => setState({ - initialValues: settings, - timezoneOptions, - isLoading: false, - })); }); }, [recordId]); @@ -42,7 +57,7 @@ const VisualSettingsForm = ({ recordId }) => { } return ( ({ +const createSchema = (shortcuts, timezoneOptions) => ({ fields: [ { component: componentTypes.SUB_FORM, @@ -98,8 +98,8 @@ const createSchema = (timezoneOptions) => ({ id: 'display.startpage', label: __('Start Page'), isSearchable: true, - loadOptions: () => API.get('/api/shortcuts?expand=resources&attributes=description,url') - .then(({ resources }) => resources.map(({ url, description }) => ({ value: url, label: description }))), + simpleValue: true, + options: shortcuts, }, { component: componentTypes.SELECT, From 3b6f01a98f295a0f61d355d3aabc51c0ff516437 Mon Sep 17 00:00:00 2001 From: Gilbert Cherrie Date: Mon, 18 Aug 2025 10:34:03 -0400 Subject: [PATCH 2/3] Added cypress tests for startpage --- cypress/e2e/ui/settings.cy.js | 33 +++++++++++++++++++++++++++++- cypress/support/commands/select.js | 16 +++++++++++++++ cypress/support/e2e.js | 1 + 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 cypress/support/commands/select.js diff --git a/cypress/e2e/ui/settings.cy.js b/cypress/e2e/ui/settings.cy.js index 2d722669db2..fa4b9d343e7 100644 --- a/cypress/e2e/ui/settings.cy.js +++ b/cypress/e2e/ui/settings.cy.js @@ -1,6 +1,37 @@ /* eslint-disable no-undef */ -describe('GTL', () => { +describe('Settings > My Settings', () => { beforeEach(() => { cy.login(); + cy.menu('Settings', 'My Settings'); + }); + + it('Saves the start page setting', () => { + cy.get('#display\\.startpage').then((value) => { + expect(value[0].value).to.be.oneOf(['', 'Overview / Dashboard']); + }); + cy.changeSelect('display\\.startpage', 'Overview / Utilization'); + cy.intercept('PATCH', '/api/users/1').as('settingsUpdate'); + cy.contains('button', 'Save').click(); + cy.wait('@settingsUpdate').its('response.statusCode').should('eq', 200); + + // Wait for page to load before clicking log out to prevent errors + cy.get('[name="general-subform"] > :nth-child(2) > .bx--select'); + cy.get('#menu_item_logout').click(); + cy.login(); + cy.url().should('include', '/utilization'); + + cy.menu('Settings', 'My Settings'); + cy.get('#display\\.startpage').then((value) => { + expect(value[0].value).to.equal('Overview / Utilization'); + }); + cy.changeSelect('display\\.startpage', 'Overview / Dashboard'); + cy.intercept('PATCH', '/api/users/1').as('settingsUpdate'); + cy.contains('button', 'Save').click(); + cy.wait('@settingsUpdate').its('response.statusCode').should('eq', 200); + + cy.get('[name="general-subform"] > :nth-child(2) > .bx--select'); + cy.get('#menu_item_logout').click(); + cy.login(); + cy.url().should('include', '/dashboard'); }); }); diff --git a/cypress/support/commands/select.js b/cypress/support/commands/select.js new file mode 100644 index 00000000000..98e6c9d4664 --- /dev/null +++ b/cypress/support/commands/select.js @@ -0,0 +1,16 @@ +/* eslint-disable no-undef */ + +// selectId: String of the ID of the select element to interact with. +// optionToSelect: String of the option to select from the dropdown. +Cypress.Commands.add('changeSelect', (selectId, optionToSelect) => { + cy.get(`#${selectId}`).click(); + cy.get('.bx--list-box__menu-item__option').then((options) => { + const optionArray = Cypress.$.makeArray(options); + const match = optionArray.find((el) => el.innerText.trim() === optionToSelect); + if (match) { + cy.wrap(match).click(); + } else { + throw new Error('No match'); + } + }); +}); diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index 1fec6ef1477..841e2f49d6d 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -50,6 +50,7 @@ import './commands/menu.js'; import './commands/stub_notifications.js'; import './commands/throttle_response.js'; import './commands/toolbar.js'; +import './commands/select.js'; // Assertions import './assertions/expect_alerts.js'; From 11a98812070dad2ee1f78ef0304dfac1cb8916d1 Mon Sep 17 00:00:00 2001 From: Gilbert Cherrie Date: Wed, 3 Sep 2025 11:03:36 -0400 Subject: [PATCH 3/3] Update cypress tests --- cypress/e2e/ui/settings.cy.js | 4 ++-- cypress/support/commands/select.js | 31 +++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/cypress/e2e/ui/settings.cy.js b/cypress/e2e/ui/settings.cy.js index fa4b9d343e7..419184a0c78 100644 --- a/cypress/e2e/ui/settings.cy.js +++ b/cypress/e2e/ui/settings.cy.js @@ -10,7 +10,7 @@ describe('Settings > My Settings', () => { expect(value[0].value).to.be.oneOf(['', 'Overview / Dashboard']); }); cy.changeSelect('display\\.startpage', 'Overview / Utilization'); - cy.intercept('PATCH', '/api/users/1').as('settingsUpdate'); + cy.intercept('PATCH', '/api/users/*').as('settingsUpdate'); cy.contains('button', 'Save').click(); cy.wait('@settingsUpdate').its('response.statusCode').should('eq', 200); @@ -25,7 +25,7 @@ describe('Settings > My Settings', () => { expect(value[0].value).to.equal('Overview / Utilization'); }); cy.changeSelect('display\\.startpage', 'Overview / Dashboard'); - cy.intercept('PATCH', '/api/users/1').as('settingsUpdate'); + cy.intercept('PATCH', '/api/users/*').as('settingsUpdate'); cy.contains('button', 'Save').click(); cy.wait('@settingsUpdate').its('response.statusCode').should('eq', 200); diff --git a/cypress/support/commands/select.js b/cypress/support/commands/select.js index 98e6c9d4664..2001e2b6471 100644 --- a/cypress/support/commands/select.js +++ b/cypress/support/commands/select.js @@ -3,14 +3,27 @@ // selectId: String of the ID of the select element to interact with. // optionToSelect: String of the option to select from the dropdown. Cypress.Commands.add('changeSelect', (selectId, optionToSelect) => { - cy.get(`#${selectId}`).click(); - cy.get('.bx--list-box__menu-item__option').then((options) => { - const optionArray = Cypress.$.makeArray(options); - const match = optionArray.find((el) => el.innerText.trim() === optionToSelect); - if (match) { - cy.wrap(match).click(); - } else { - throw new Error('No match'); - } + // First, get the select element and store its text + let selectElementText = ''; + cy.get(`#${selectId}`).then((selectElement) => { + // Get the currently displayed text in the select element + selectElementText = selectElement.text().trim(); + // Click to open the dropdown + cy.wrap(selectElement).click(); + }).then(() => { + // Now find the options and try to select the requested one + cy.get('.bx--list-box__menu-item__option').then((options) => { + const optionArray = Cypress.$.makeArray(options); + const match = optionArray.find((el) => el.innerText.trim() === optionToSelect); + + if (match) { + cy.wrap(match).click(); + } else { + // Include both the requested option and the select element's text in the error + cy.logAndThrowError( + `Could not find "${optionToSelect}" in select element with text "${selectElementText}"` + ); + } + }); }); });