Skip to content

automation: select all custom permissions #13892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion cypress/e2e/po/pages/explorer/cluster-project-members.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import AsyncButtonPo from '@/cypress/e2e/po/components/async-button.po';
import RadioGroupInputPo from '@/cypress/e2e/po/components/radio-group-input.po';
import CheckboxInputPo from '@/cypress/e2e/po/components/checkbox-input.po';
import SortableTablePo from '@/cypress/e2e/po/components/sortable-table.po';

import BannersPo from '@/cypress/e2e/po/components/banners.po';
export default class ClusterProjectMembersPo extends PagePo {
private static createPath(clusterId: string, tabId: string) {
return `/c/${ clusterId }/explorer/members#${ tabId }`;
Expand Down Expand Up @@ -45,6 +45,10 @@ export default class ClusterProjectMembersPo extends PagePo {
permissionOptions.set(3);
}

customPermissionsCheckboxes() {
return cy.get('.custom-permissions').find('.checkbox-container');
}

checkTheseProjectCustomPermissions(permissionIndices: number[]) {
permissionIndices.forEach((permissionIndex) => {
const checkbox = new CheckboxInputPo(`[data-testid="custom-permission-${ permissionIndex }"]`);
Expand All @@ -66,6 +70,10 @@ export default class ClusterProjectMembersPo extends PagePo {
return new AsyncButtonPo('[data-testid="form-cancel"]', this.self());
}

createFormErrorBanner(): BannersPo {
return new BannersPo('.card-body [data-testid="banner-content"]');
}

resourcesList() {
return new BaseResourceList(this.self());
}
Expand Down
30 changes: 26 additions & 4 deletions cypress/e2e/tests/pages/explorer2/cluster-project-members.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe('Cluster Project and Members', { tags: ['@explorer2', '@adminUser'] },
});
});
});

it('Clicking cancel should return to Cluster and Project members ', () => {
HomePagePo.goTo();
const clusterMembership = new ClusterProjectMembersPo('local', 'cluster-membership');
Expand All @@ -73,6 +74,7 @@ describe('Cluster Project and Members', { tags: ['@explorer2', '@adminUser'] },
clusterMembership.cancelCreateForm().click();
clusterMembership.waitForPageWithExactUrl();
});

it('Can create a member with custom permissions', () => {
// add user to Cluster membership
const projectMembership = new ClusterProjectMembersPo('local', 'project-membership');
Expand All @@ -82,12 +84,28 @@ describe('Cluster Project and Members', { tags: ['@explorer2', '@adminUser'] },
projectMembership.triggerAddProjectMemberAction('default');
projectMembership.selectProjectCustomPermission();
projectMembership.selectClusterOrProjectMember(username);
projectMembership.checkTheseProjectCustomPermissions([0, 1]);

// testing https://github.com/rancher/dashboard/issues/13764
// select all project roles
projectMembership.customPermissionsCheckboxes().then(($checkboxes) => {
const indexes = Array.from({ length: $checkboxes.length }, (_, i) => i);

projectMembership.checkTheseProjectCustomPermissions(indexes);
});

// store checkbox labels in an alias
projectMembership.customPermissionsCheckboxes().find('span.checkbox-label').then(($labels) => {
const labels = $labels.toArray().map((label) => Cypress.$(label).text().trim());

cy.wrap(labels).as('checkboxLabels');
});

cy.intercept('POST', '/v3/projectroletemplatebindings').as('createProjectMembership');
projectMembership.submitProjectCreateButton();
cy.wait('@createProjectMembership');
cy.wait('@createProjectMembership').its('response.statusCode').should('eq', 201);
projectMembership.createFormErrorBanner().checkNotExists();
cy.get('.modal-overlay').should('not.exist');
projectMembership.waitForPage();

projectMembership.goTo();
projectMembership.waitForPageWithSpecificUrl('/c/local/explorer/members#project-membership');
Expand All @@ -96,12 +114,16 @@ describe('Cluster Project and Members', { tags: ['@explorer2', '@adminUser'] },
if (el.find('tr.no-rows').is(':visible')) {
cy.reload();
}
});

// retrieve the labels and assert UI contains each label
cy.get('@checkboxLabels').then((labels: any) => {
projectMembership.projectTable().rowElementWithName(username).find('td:nth-of-type(3)').first()
.invoke('text')
.then((t) => {
expect(t).to.include('Create Namespaces');
expect(t).to.include('Manage Config Maps');
labels.forEach((label) => {
expect(t).to.include(label);
});
});
});
});
Expand Down
Loading