diff --git a/packages/manager/.changeset/pr-10139-tests-1707331596288.md b/packages/manager/.changeset/pr-10139-tests-1707331596288.md new file mode 100644 index 00000000000..af67be49f66 --- /dev/null +++ b/packages/manager/.changeset/pr-10139-tests-1707331596288.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Tests +--- + +Add test to check proxy user disabled username/email field ([#10139](https://github.com/linode/manager/pull/10139)) diff --git a/packages/manager/cypress/e2e/core/account/change-username.spec.ts b/packages/manager/cypress/e2e/core/account/change-username.spec.ts index a2323877ade..faa509ee209 100644 --- a/packages/manager/cypress/e2e/core/account/change-username.spec.ts +++ b/packages/manager/cypress/e2e/core/account/change-username.spec.ts @@ -1,3 +1,11 @@ +import { Profile } from '@linode/api-v4'; +import { profileFactory } from '@src/factories'; +import { + mockAppendFeatureFlags, + mockGetFeatureFlagClientstream, +} from 'support/intercepts/feature-flags'; +import { makeFeatureFlagData } from 'support/util/feature-flags'; +import { mockGetProfile } from 'support/intercepts/profile'; import { getProfile } from 'support/api/account'; import { interceptGetProfile } from 'support/intercepts/profile'; import { @@ -7,6 +15,50 @@ import { import { ui } from 'support/ui'; import { randomString } from 'support/util/random'; +const verifyUsernameAndEmail = ( + mockRestrictedProxyProfile: Profile, + tooltip: string, + checkEmail: boolean +) => { + // TODO: Parent/Child - M3-7559 clean up when feature is live in prod and feature flag is removed. + mockAppendFeatureFlags({ + parentChildAccountAccess: makeFeatureFlagData(true), + }).as('getFeatureFlags'); + mockGetFeatureFlagClientstream().as('getClientStream'); + + mockGetProfile(mockRestrictedProxyProfile); + + // Navigate to User Profile page + cy.visitWithLogin('/profile/display'); + + // Confirm the username and email address fields are disabled, as well their respective save buttons + cy.get('[id="username"]').should('be.disabled'); + ui.button + .findByTitle('Update Username') + .should('be.visible') + .should('be.disabled') + .trigger('mouseover'); + // Click the button first, then confirm the tooltip is shown + ui.tooltip.findByText(tooltip).should('be.visible'); + + // Refresh the page + mockGetProfile(mockRestrictedProxyProfile); + cy.reload(); + + if (checkEmail) { + cy.get('[id="email"]').should('be.disabled'); + ui.button + .findByTitle('Update Email') + .should('be.visible') + .should('be.disabled') + .trigger('mouseover'); + // Click the button first, then confirm the tooltip is shown + ui.tooltip + .findByText('This account type cannot update this field.') + .should('be.visible'); + } +}; + describe('username', () => { /* * - Validates username update flow via the user profile page using mocked data. @@ -96,4 +148,45 @@ describe('username', () => { cy.findByText('Username updated successfully.').should('be.visible'); }); }); + + it('disables username/email fields for restricted proxy user', () => { + const mockRestrictedProxyProfile = profileFactory.build({ + username: 'restricted-proxy-user', + user_type: 'proxy', + restricted: true, + }); + + verifyUsernameAndEmail( + mockRestrictedProxyProfile, + 'This account type cannot update this field.', + true + ); + }); + + it('disables username/email fields for unrestricted proxy user', () => { + const mockUnrestrictedProxyProfile = profileFactory.build({ + username: 'unrestricted-proxy-user', + user_type: 'proxy', + }); + + verifyUsernameAndEmail( + mockUnrestrictedProxyProfile, + 'This account type cannot update this field.', + true + ); + }); + + it('disables username/email fields for regular restricted user', () => { + const mockRegularRestrictedProfile = profileFactory.build({ + username: 'regular-restricted-user', + user_type: null, + restricted: true, + }); + + verifyUsernameAndEmail( + mockRegularRestrictedProfile, + 'Restricted users cannot update their username. Please contact an account administrator.', + false + ); + }); });