Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-12230-tests-1747340294690.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Cypress test for Longview create page for restricted users ([#12230](https://github.com/linode/manager/pull/12230))
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { grantsFactory, profileFactory } from '@linode/utilities';
import { authenticate } from 'support/api/authentication';
import { longviewEmptyStateMessage } from 'support/constants/longview';
import { mockGetUser } from 'support/intercepts/account';
import {
mockGetLongviewClients,
mockGetLongviewPlan,
mockUnauthorizedLongviewPlanRequest,
mockUpdateLongviewPlan,
} from 'support/intercepts/longview';
import {
mockGetProfile,
mockGetProfileGrants,
} from 'support/intercepts/profile';
import { ui } from 'support/ui';
import { cleanUp } from 'support/util/cleanup';
import { randomLabel } from 'support/util/random';

import { accountUserFactory } from 'src/factories';
import { longviewActivePlanFactory } from 'src/factories';

import type { ActiveLongviewPlan } from '@linode/api-v4';
Expand Down Expand Up @@ -60,3 +71,57 @@ describe('longview plan', () => {
.should('be.disabled');
});
});

describe('restricted user does not have permission to create plan', () => {
before(() => {
const mockProfile = profileFactory.build({
restricted: true,
username: randomLabel(),
});

const mockUser = accountUserFactory.build({
restricted: true,
user_type: 'default',
username: mockProfile.username,
});

const mockGrants = grantsFactory.build({
global: {
add_longview: false,
longview_subscription: false,
},
});

mockGetProfile(mockProfile);
mockGetProfileGrants(mockGrants);
mockGetUser(mockUser);
});

/*
* - Verifies restricted user cannot view or edit plans
*/
it('restricted user cannot create plan on empty landing page', () => {
mockGetLongviewClients([]).as('getLongviewClients');
mockUnauthorizedLongviewPlanRequest().as('getLongviewPlan');
cy.visitWithLogin('/longview');
cy.wait(['@getLongviewClients', '@getLongviewPlan']);
// Confirm that the "Add Client" button is disabled
ui.button
.findByTitle('Add Client')
.should('be.visible')
.should('be.disabled')
.trigger('mouseover');
ui.tooltip.findByText(
`You don't have permissions to create Longview Clients. Please contact your account administrator to request the necessary permissions.`
);

// Confirms that a landing page empty state message is displayed
cy.findByText(longviewEmptyStateMessage).should('be.visible');

ui.tabList.findTabByTitle('Plan Details').should('be.visible').click();
ui.tabList.findTabByTitle('Plan Details').within(() => {
cy.get('table').should('not.exist');
cy.get('imput').should('not.exist');
});
});
});
9 changes: 9 additions & 0 deletions packages/manager/cypress/support/intercepts/longview.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { makeErrorResponse } from 'support/util/errors';
import { apiMatcher } from 'support/util/intercepts';
import { paginateResponse } from 'support/util/paginate';
import { makeResponse } from 'support/util/response';
Expand Down Expand Up @@ -100,6 +101,14 @@ export const mockGetLongviewPlan = (
return cy.intercept('GET', apiMatcher('longview/plan'), makeResponse(plan));
};

export const mockUnauthorizedLongviewPlanRequest =
(): Cypress.Chainable<null> => {
return cy.intercept(
apiMatcher('longview/plan'),
makeErrorResponse('Unauthorized', 403)
);
};

export const mockUpdateLongviewPlan = (
newPlan: ActiveLongviewPlan
): Cypress.Chainable<null> => {
Expand Down