Skip to content

Commit ce3206f

Browse files
test [M3-9597]: Cypress test for Longview create page for restricted users (#12230)
* longview test for restricted user * Added changeset: Cypress test for Longview create page for restricted users * edits after pr review
1 parent c2bb882 commit ce3206f

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Tests
3+
---
4+
5+
Cypress test for Longview create page for restricted users ([#12230](https://github.com/linode/manager/pull/12230))

packages/manager/cypress/e2e/core/longview/longview-plan.spec.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1+
import { grantsFactory, profileFactory } from '@linode/utilities';
12
import { authenticate } from 'support/api/authentication';
3+
import { longviewEmptyStateMessage } from 'support/constants/longview';
4+
import { mockGetUser } from 'support/intercepts/account';
25
import {
6+
mockGetLongviewClients,
37
mockGetLongviewPlan,
8+
mockUnauthorizedLongviewPlanRequest,
49
mockUpdateLongviewPlan,
510
} from 'support/intercepts/longview';
11+
import {
12+
mockGetProfile,
13+
mockGetProfileGrants,
14+
} from 'support/intercepts/profile';
615
import { ui } from 'support/ui';
716
import { cleanUp } from 'support/util/cleanup';
17+
import { randomLabel } from 'support/util/random';
818

19+
import { accountUserFactory } from 'src/factories';
920
import { longviewActivePlanFactory } from 'src/factories';
1021

1122
import type { ActiveLongviewPlan } from '@linode/api-v4';
@@ -60,3 +71,57 @@ describe('longview plan', () => {
6071
.should('be.disabled');
6172
});
6273
});
74+
75+
describe('restricted user does not have permission to create plan', () => {
76+
before(() => {
77+
const mockProfile = profileFactory.build({
78+
restricted: true,
79+
username: randomLabel(),
80+
});
81+
82+
const mockUser = accountUserFactory.build({
83+
restricted: true,
84+
user_type: 'default',
85+
username: mockProfile.username,
86+
});
87+
88+
const mockGrants = grantsFactory.build({
89+
global: {
90+
add_longview: false,
91+
longview_subscription: false,
92+
},
93+
});
94+
95+
mockGetProfile(mockProfile);
96+
mockGetProfileGrants(mockGrants);
97+
mockGetUser(mockUser);
98+
});
99+
100+
/*
101+
* - Verifies restricted user cannot view or edit plans
102+
*/
103+
it('restricted user cannot create plan on empty landing page', () => {
104+
mockGetLongviewClients([]).as('getLongviewClients');
105+
mockUnauthorizedLongviewPlanRequest().as('getLongviewPlan');
106+
cy.visitWithLogin('/longview');
107+
cy.wait(['@getLongviewClients', '@getLongviewPlan']);
108+
// Confirm that the "Add Client" button is disabled
109+
ui.button
110+
.findByTitle('Add Client')
111+
.should('be.visible')
112+
.should('be.disabled')
113+
.trigger('mouseover');
114+
ui.tooltip.findByText(
115+
"You don't have permissions to create Longview Clients. Please contact your account administrator to request the necessary permissions."
116+
);
117+
118+
// Confirms that a landing page empty state message is displayed
119+
cy.findByText(longviewEmptyStateMessage).should('be.visible');
120+
121+
ui.tabList.findTabByTitle('Plan Details').should('be.visible').click();
122+
ui.tabList.findTabByTitle('Plan Details').within(() => {
123+
cy.get('table').should('not.exist');
124+
cy.get('imput').should('not.exist');
125+
});
126+
});
127+
});

packages/manager/cypress/support/intercepts/longview.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { makeErrorResponse } from 'support/util/errors';
12
import { apiMatcher } from 'support/util/intercepts';
23
import { paginateResponse } from 'support/util/paginate';
34
import { makeResponse } from 'support/util/response';
@@ -100,6 +101,14 @@ export const mockGetLongviewPlan = (
100101
return cy.intercept('GET', apiMatcher('longview/plan'), makeResponse(plan));
101102
};
102103

104+
export const mockUnauthorizedLongviewPlanRequest =
105+
(): Cypress.Chainable<null> => {
106+
return cy.intercept(
107+
apiMatcher('longview/plan'),
108+
makeErrorResponse('Unauthorized', 403)
109+
);
110+
};
111+
103112
export const mockUpdateLongviewPlan = (
104113
newPlan: ActiveLongviewPlan
105114
): Cypress.Chainable<null> => {

0 commit comments

Comments
 (0)