Skip to content

Commit

Permalink
test: [M3-8918] - Cypress test for restricted user Image empty landin…
Browse files Browse the repository at this point in the history
…g 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
  • Loading branch information
hasyed-akamai authored Nov 22, 2024
1 parent c59c943 commit 4b3fe8a
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-11281-tests-1732015326269.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Cypress test for restricted user Image Empty landing page ([#11281](https://github.com/linode/manager/pull/11281))
Original file line number Diff line number Diff line change
@@ -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']);

Expand Down Expand Up @@ -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');
});
});

0 comments on commit 4b3fe8a

Please sign in to comment.