Skip to content

Commit

Permalink
test: [M3-8609] - Cypress test for non-empty Linode landing page with…
Browse files Browse the repository at this point in the history
… restricted user (linode#11060)

* Initial commit for adding new test checks restricted user with no access cannot see existing linode and cannot create linode landing

* Initial commit for adding new test checks restricted user with no access cannot see existing linode and cannot create linode landing

* Removed no_access token test

* Resolved pre-commit error

* Added changeset: Cypress test for non-empty Linode landing page with restricted user

* Removed unwanted omment

* Removed it.only

* Worked on review comments to use mockGetLinodes and cy.wait() for mock profiles

* Reverting it.only from test
  • Loading branch information
subsingh-akamai authored Oct 16, 2024
1 parent 671d716 commit e96c819
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-11060-tests-1728375821627.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Cypress test for non-empty Linode landing page with restricted user ([#11060](https://github.com/linode/manager/pull/11060))
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,98 @@ describe('linode landing checks for empty state', () => {
.should('be.visible');
});
});

describe('linode landing checks for non-empty state with restricted user', () => {
beforeEach(() => {
// Mock setup to display the Linode landing page in an non-empty state
const mockLinodes: Linode[] = new Array(1).fill(null).map(
(_item: null, index: number): Linode => {
return linodeFactory.build({
label: `Linode ${index}`,
region: chooseRegion().id,
tags: [index % 2 == 0 ? 'even' : 'odd', 'nums'],
});
}
);

mockGetLinodes(mockLinodes).as('getLinodes');

// Alias the mockLinodes array
cy.wrap(mockLinodes).as('mockLinodes');
});

it('checks restricted user with read access has no access to create linode and can see existing linodes', () => {
// Mock setup for user profile, account user, and user grants with restricted permissions,
// simulating a default user without the ability to add Linodes.
const mockProfile = profileFactory.build({
username: randomLabel(),
restricted: true,
});

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

mockGetProfile(mockProfile);
mockGetProfileGrants(mockGrants);

// Intercept and alias the mock requests
cy.intercept('GET', apiMatcher('profile'), (req) => {
req.reply(mockProfile);
}).as('getProfile');

cy.intercept('GET', apiMatcher('profile/grants'), (req) => {
req.reply(mockGrants);
}).as('getProfileGrants');

// Login and wait for application to load
cy.visitWithLogin(routes.linodeLanding);
cy.wait('@getLinodes');
cy.url().should('endWith', routes.linodeLanding);

// Wait for the mock requests to complete
cy.wait('@getProfile');
cy.wait('@getProfileGrants');

// Assert that Create Linode button is visible and disabled
ui.button
.findByTitle('Create Linode')
.should('be.visible')
.and('be.disabled')
.trigger('mouseover');

// Assert that tooltip is visible with message
ui.tooltip
.findByText(
"You don't have permissions to create Linodes. Please contact your account administrator to request the necessary permissions."
)
.should('be.visible');

// Assert that List of Liondes table exist
cy.get('table[aria-label="List of Linodes"]').should('exist');

// Assert that Docs link exist
cy.get(
'a[aria-label="Docs - link opens in a new tab"][data-testid="external-link"]'
).should('exist');

// Assert that the correct number of Linode entries are present in the table
cy.get<Linode[]>('@mockLinodes').then((mockLinodes) => {
// Assert that the correct number of Linode entries are present in the table
cy.get('table[aria-label="List of Linodes"] tbody tr').should(
'have.length',
mockLinodes.length
);

// Assert that each Linode entry is present in the table
mockLinodes.forEach((linode) => {
cy.get('table[aria-label="List of Linodes"] tbody tr').should(
'contain',
linode.label
);
});
});
});
});

0 comments on commit e96c819

Please sign in to comment.