|
| 1 | +/** |
| 2 | + * Integration tests involving Host Maintenance Policy account settings. |
| 3 | + */ |
| 4 | + |
| 5 | +import { |
| 6 | + mockGetAccountSettings, |
| 7 | + mockUpdateAccountSettings, |
| 8 | + mockUpdateAccountSettingsError, |
| 9 | +} from 'support/intercepts/account'; |
| 10 | +import { mockAppendFeatureFlags } from 'support/intercepts/feature-flags'; |
| 11 | +import { mockGetMaintenancePolicies } from 'support/intercepts/maintenance'; |
| 12 | +import { ui } from 'support/ui'; |
| 13 | + |
| 14 | +import { accountSettingsFactory } from 'src/factories'; |
| 15 | +import { maintenancePolicyFactory } from 'src/factories/maintenancePolicy'; |
| 16 | + |
| 17 | +describe('Host Maintenance Policy account settings', () => { |
| 18 | + const mockMaintenancePolicies = [ |
| 19 | + maintenancePolicyFactory.build({ |
| 20 | + slug: 'linode/migrate', |
| 21 | + label: 'Migrate', |
| 22 | + type: 'linode_migrate', |
| 23 | + }), |
| 24 | + maintenancePolicyFactory.build({ |
| 25 | + slug: 'linode/power_off_on', |
| 26 | + label: 'Power Off / Power On', |
| 27 | + type: 'linode_power_off_on', |
| 28 | + }), |
| 29 | + ]; |
| 30 | + |
| 31 | + describe('When feature flag is enabled', () => { |
| 32 | + beforeEach(() => { |
| 33 | + mockAppendFeatureFlags({ |
| 34 | + vmHostMaintenance: { |
| 35 | + enabled: true, |
| 36 | + }, |
| 37 | + }); |
| 38 | + mockGetMaintenancePolicies(mockMaintenancePolicies); |
| 39 | + }); |
| 40 | + |
| 41 | + /* |
| 42 | + * - Confirms that the value of the "Maintenance Policy" drop-down matches the account setting on page load. |
| 43 | + */ |
| 44 | + it('shows the expected maintenance policy in the drop-down', () => { |
| 45 | + mockMaintenancePolicies.forEach((maintenancePolicy) => { |
| 46 | + mockGetAccountSettings( |
| 47 | + accountSettingsFactory.build({ |
| 48 | + maintenance_policy: maintenancePolicy.slug, |
| 49 | + }) |
| 50 | + ); |
| 51 | + |
| 52 | + cy.visitWithLogin('/account/settings'); |
| 53 | + cy.findByText('Host Maintenance Policy') |
| 54 | + .should('be.visible') |
| 55 | + .closest('[data-qa-paper]') |
| 56 | + .within(() => { |
| 57 | + cy.findByLabelText('Maintenance Policy').should( |
| 58 | + 'have.value', |
| 59 | + maintenancePolicy.label |
| 60 | + ); |
| 61 | + }); |
| 62 | + }); |
| 63 | + }); |
| 64 | + |
| 65 | + /* |
| 66 | + * - Confirms that the user can update their default maintenance policy. |
| 67 | + * - Confirms that Cloud Manager displays API errors upon unsuccessful account settings update. |
| 68 | + * - Confirms that Cloud Manager shows toast notification upon successful account settings update. |
| 69 | + */ |
| 70 | + it('can update the default maintenance policy type', () => { |
| 71 | + mockGetAccountSettings( |
| 72 | + accountSettingsFactory.build({ |
| 73 | + maintenance_policy: 'linode/migrate', |
| 74 | + }) |
| 75 | + ); |
| 76 | + mockUpdateAccountSettingsError('An unknown error occurred', 500).as( |
| 77 | + 'updateMaintenancePolicy' |
| 78 | + ); |
| 79 | + |
| 80 | + cy.visitWithLogin('/account/settings'); |
| 81 | + cy.findByText('Host Maintenance Policy') |
| 82 | + .should('be.visible') |
| 83 | + .closest('[data-qa-paper]') |
| 84 | + .within(() => { |
| 85 | + ui.button |
| 86 | + .findByTitle('Save Maintenance Policy') |
| 87 | + .should('be.disabled'); |
| 88 | + |
| 89 | + // Change the maintenance policy selection from "Migrate" to "Power Off / Power On". |
| 90 | + cy.findByLabelText('Maintenance Policy').clear(); |
| 91 | + ui.autocompletePopper.find().within(() => { |
| 92 | + cy.contains('Power Off / Power On').should('be.visible').click(); |
| 93 | + }); |
| 94 | + cy.findByLabelText('Maintenance Policy').should( |
| 95 | + 'have.value', |
| 96 | + 'Power Off / Power On' |
| 97 | + ); |
| 98 | + |
| 99 | + // Confirm that "Save Maintenance Policy" button becomes enabled and click it, |
| 100 | + // then that Cloud Manager displays an error message if an API error occurs. |
| 101 | + ui.button |
| 102 | + .findByTitle('Save Maintenance Policy') |
| 103 | + .should('be.enabled') |
| 104 | + .click(); |
| 105 | + cy.wait('@updateMaintenancePolicy'); |
| 106 | + cy.findByText('An unknown error occurred').should('be.visible'); |
| 107 | + |
| 108 | + // Click the "Save Maintenance Policy" button again, this time confirm |
| 109 | + // that Cloud responds as expected upon receiving a successful API response. |
| 110 | + mockUpdateAccountSettings( |
| 111 | + accountSettingsFactory.build({ |
| 112 | + maintenance_policy: 'linode/power_off_on', |
| 113 | + }) |
| 114 | + ).as('updateMaintenancePolicy'); |
| 115 | + |
| 116 | + ui.button |
| 117 | + .findByTitle('Save Maintenance Policy') |
| 118 | + .should('be.enabled') |
| 119 | + .click(); |
| 120 | + cy.wait('@updateMaintenancePolicy').then((xhr) => { |
| 121 | + expect(xhr.request.body.maintenance_policy).to.equal( |
| 122 | + 'linode/power_off_on' |
| 123 | + ); |
| 124 | + }); |
| 125 | + }); |
| 126 | + |
| 127 | + ui.toast.assertMessage('Host Maintenance Policy settings updated.'); |
| 128 | + }); |
| 129 | + }); |
| 130 | + |
| 131 | + // TODO M3-10046 - Delete feature flag negative tests when "vmHostMaintenance" feature flag is removed. |
| 132 | + describe('When feature flag is disabled', () => { |
| 133 | + /* |
| 134 | + * - Confirms that the "Host Maintenance Policy" section is absent when `vmHostMaintenance` is disabled. |
| 135 | + */ |
| 136 | + it('does not show Host Maintenance Policy section on settings page', () => { |
| 137 | + mockAppendFeatureFlags({ |
| 138 | + vmHostMaintenance: { |
| 139 | + enabled: false, |
| 140 | + }, |
| 141 | + }); |
| 142 | + |
| 143 | + cy.visitWithLogin('/account/settings'); |
| 144 | + |
| 145 | + // Confirm that page contents has loaded by confirming that certain content |
| 146 | + // is visible. We'll assert that the Linode Managed informational text is present. |
| 147 | + cy.contains( |
| 148 | + 'Linode Managed includes Backups, Longview Pro, cPanel, and round-the-clock monitoring' |
| 149 | + ); |
| 150 | + |
| 151 | + // Confirm that the "Host Maintenance Policy" section is absent. |
| 152 | + cy.findByText('Host Maintenance Policy').should('not.exist'); |
| 153 | + }); |
| 154 | + }); |
| 155 | +}); |
0 commit comments