|
| 1 | +import { grantsFactory, profileFactory } from '@linode/utilities'; |
1 | 2 | import { authenticate } from 'support/api/authentication'; |
| 3 | +import { longviewEmptyStateMessage } from 'support/constants/longview'; |
| 4 | +import { mockGetUser } from 'support/intercepts/account'; |
2 | 5 | import { |
| 6 | + mockGetLongviewClients, |
3 | 7 | mockGetLongviewPlan, |
| 8 | + mockUnauthorizedLongviewPlanRequest, |
4 | 9 | mockUpdateLongviewPlan, |
5 | 10 | } from 'support/intercepts/longview'; |
| 11 | +import { |
| 12 | + mockGetProfile, |
| 13 | + mockGetProfileGrants, |
| 14 | +} from 'support/intercepts/profile'; |
6 | 15 | import { ui } from 'support/ui'; |
7 | 16 | import { cleanUp } from 'support/util/cleanup'; |
| 17 | +import { randomLabel } from 'support/util/random'; |
8 | 18 |
|
| 19 | +import { accountUserFactory } from 'src/factories'; |
9 | 20 | import { longviewActivePlanFactory } from 'src/factories'; |
10 | 21 |
|
11 | 22 | import type { ActiveLongviewPlan } from '@linode/api-v4'; |
@@ -60,3 +71,57 @@ describe('longview plan', () => { |
60 | 71 | .should('be.disabled'); |
61 | 72 | }); |
62 | 73 | }); |
| 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 | +}); |
0 commit comments