From 4b3fe8aee5c25bca40f60b86ca0ec16232674167 Mon Sep 17 00:00:00 2001 From: hasyed-akamai Date: Fri, 22 Nov 2024 11:56:10 +0530 Subject: [PATCH] test: [M3-8918] - Cypress test for restricted user Image empty landing page (#11281) * test: [M3-8918] - Cypress test for restricted user Image empty landing page * Added changeset: Cypress test for restricted user Image Empty landing page * Reordered assertion and added reference section check as per review comments * Added reference section inside the test --- .../pr-11281-tests-1732015326269.md | 5 ++ .../images/images-empty-landing-page.spec.ts | 74 ++++++++++++++++++- 2 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 packages/manager/.changeset/pr-11281-tests-1732015326269.md diff --git a/packages/manager/.changeset/pr-11281-tests-1732015326269.md b/packages/manager/.changeset/pr-11281-tests-1732015326269.md new file mode 100644 index 00000000000..fbd3c812b03 --- /dev/null +++ b/packages/manager/.changeset/pr-11281-tests-1732015326269.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Tests +--- + +Cypress test for restricted user Image Empty landing page ([#11281](https://github.com/linode/manager/pull/11281)) diff --git a/packages/manager/cypress/e2e/core/images/images-empty-landing-page.spec.ts b/packages/manager/cypress/e2e/core/images/images-empty-landing-page.spec.ts index 667b8feabc8..3f7eb49d61d 100644 --- a/packages/manager/cypress/e2e/core/images/images-empty-landing-page.spec.ts +++ b/packages/manager/cypress/e2e/core/images/images-empty-landing-page.spec.ts @@ -1,15 +1,27 @@ import { ui } from 'support/ui'; import { mockGetAllImages } from 'support/intercepts/images'; +import { profileFactory } from '@src/factories'; +import { accountUserFactory } from '@src/factories/accountUsers'; +import { grantsFactory } from '@src/factories/grants'; +import { mockGetUser } from 'support/intercepts/account'; +import { + mockGetProfile, + mockGetProfileGrants, +} from 'support/intercepts/profile'; +import { randomLabel } from 'support/util/random'; describe('Images empty landing page', () => { - /** + beforeEach(() => { + // Mock setup to display the Image landing page in an empty state + mockGetAllImages([]).as('getImages'); + }); + + /* * - Confirms Images landing page empty state is shown when no Images are present: * - Confirms that "Getting Started Guides" and "Video Playlist" are listed on landing page. * - Confirms that clicking "Create Image" navigates user to image create page. */ it('shows the empty state when there are no images', () => { - mockGetAllImages([]).as('getImages'); - cy.visitWithLogin('/images'); cy.wait(['@getImages']); @@ -46,4 +58,60 @@ describe('Images empty landing page', () => { cy.url().should('endWith', '/images/create/disk'); }); + + /* + * - Confirms Images table not exist. + * - Confirms that "Create Image" button is disabled for restricted user. + * - Confirms that hovering "Create Image" button shows a Warning for restricted user. + */ + it('checks restricted user has no access to create Image on Image landing page', () => { + // object to create a mockProfile for non-restricted user + const mockProfile = profileFactory.build({ + username: randomLabel(), + restricted: true, + }); + + // object to create a mockUser for non-restricted user + const mockUser = accountUserFactory.build({ + username: mockProfile.username, + restricted: true, + user_type: 'default', + }); + + // object to create a mockGrants for non-restricted user + const mockGrants = grantsFactory.build({ + global: { + add_images: false, + }, + }); + + mockGetProfile(mockProfile); + mockGetProfileGrants(mockGrants); + mockGetUser(mockUser); + + // Login and wait for application to load + cy.visitWithLogin('/images'); + cy.wait('@getImages'); + cy.url().should('endWith', '/images'); + + // Assert that List of Images table not exist + cy.get('table[aria-label="List of Images"]').should('not.exist'); + + // confirms 'Create Image' button is disabled + ui.button + .findByTitle('Create Image') + .should('be.visible') + .and('be.disabled') + .trigger('mouseover'); + + ui.tooltip + .findByText( + "You don't have permissions to create Images. Please contact your account administrator to request the necessary permissions." + ) + .should('be.visible'); + + // checks for reference section on empty page + cy.findByText('Getting Started Guides').should('be.visible'); + cy.findByText('Video Playlist').should('be.visible'); + }); });