Skip to content

Commit

Permalink
test: [M3-7698] - Add test to check proxy user disabled username/emai…
Browse files Browse the repository at this point in the history
…l field (#10139)

* M3-7689: Add test to check proxy user disabled username/email field

* fix comments

* fix comments

* Added changeset: Add test to check proxy user disabled username/email field
  • Loading branch information
cliu-akamai authored Feb 8, 2024
1 parent ef6d814 commit 731a274
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-10139-tests-1707331596288.md
Original file line number Diff line number Diff line change
@@ -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))
93 changes: 93 additions & 0 deletions packages/manager/cypress/e2e/core/account/change-username.spec.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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.
Expand Down Expand Up @@ -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
);
});
});

0 comments on commit 731a274

Please sign in to comment.