Skip to content

Commit

Permalink
feat(mr settings): permissions table
Browse files Browse the repository at this point in the history
Signed-off-by: gitdallas <[email protected]>

auto lint fixes

Signed-off-by: gitdallas <[email protected]>

fix lints

Signed-off-by: gitdallas <[email protected]>

some cleanup

Signed-off-by: gitdallas <[email protected]>

tests for mr permissions

Signed-off-by: gitdallas <[email protected]>
  • Loading branch information
gitdallas committed Jul 2, 2024
1 parent 0c6256d commit 9836d03
Show file tree
Hide file tree
Showing 27 changed files with 1,062 additions and 358 deletions.
51 changes: 34 additions & 17 deletions frontend/src/__mocks__/mockRoleBindingK8sResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type MockResourceConfigType = {
subjects?: RoleBindingSubject[];
roleRefName?: string;
uid?: string;
modelRegistryName?: string;
};

export const mockRoleBindingK8sResource = ({
Expand All @@ -22,22 +23,38 @@ export const mockRoleBindingK8sResource = ({
],
roleRefName = 'view',
uid = genUID('rolebinding'),
}: MockResourceConfigType): RoleBindingKind => ({
kind: 'RoleBinding',
apiVersion: 'rbac.authorization.k8s.io/v1',
metadata: {
name,
namespace,
uid,
creationTimestamp: '2023-02-14T21:43:59Z',
labels: {
modelRegistryName = '',
}: MockResourceConfigType): RoleBindingKind => {
let labels;
if (modelRegistryName) {
labels = {
'app.kubernetes.io/name': modelRegistryName,
app: modelRegistryName,
'app.kubernetes.io/component': 'model-registry',
'app.kubernetes.io/part-of': 'model-registry',
[KnownLabels.DASHBOARD_RESOURCE]: 'true',
component: 'model-registry',
};
} else {
labels = {
[KnownLabels.DASHBOARD_RESOURCE]: 'true',
};
}
return {
kind: 'RoleBinding',
apiVersion: 'rbac.authorization.k8s.io/v1',
metadata: {
name,
namespace,
uid,
creationTimestamp: '2023-02-14T21:43:59Z',
labels,
},
subjects,
roleRef: {
apiGroup: 'rbac.authorization.k8s.io',
kind: 'ClusterRole',
name: roleRefName,
},
},
subjects,
roleRef: {
apiGroup: 'rbac.authorization.k8s.io',
kind: 'ClusterRole',
name: roleRefName,
},
});
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ export class TableRow extends Contextual<HTMLTableRowElement> {
findKebabAction(name: string): Cypress.Chainable<JQuery<HTMLElement>> {
return this.find().findKebabAction(name);
}

findKebab(): Cypress.Chainable<JQuery<HTMLElement>> {
return this.find().findKebab();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Contextual } from './components/Contextual';
import { TableRow } from './components/table';

class PermissionsTableRow extends TableRow {}

class UsersTab {
visit(mrName: string, wait = true) {
cy.visitWithLogin(`/modelRegistrySettings/permissions/${mrName}`);
if (wait) {
this.wait();
}
}

private wait() {
cy.findByTestId('app-page-title');
cy.testA11y();
}

findAddUserButton() {
return cy.findByTestId('add-button User');
}

findAddGroupButton() {
return cy.findByTestId('add-button Group');
}

getUserTable() {
return new PermissionTable(() => cy.findByTestId('role-binding-table User'));
}

getGroupTable() {
return new PermissionTable(() => cy.findByTestId('role-binding-table Group'));
}
}

class PermissionTable extends Contextual<HTMLElement> {
findRows() {
return this.find().find(`[data-label=Username]`);
}

findAddInput() {
return this.find().findByTestId('role-binding-name-input');
}

findEditInput(id: string) {
return this.find().findByTestId(['role-binding-name-input', id]);
}

findGroupSelect() {
return this.find().get(`[aria-label="Name selection"]`);
}

getTableRow(name: string) {
return new PermissionsTableRow(() =>
this.find().find(`[data-label=Username]`).contains(name).parents('tr'),
);
}

findTableHeaderButton(name: string) {
return this.find().find('thead').findByRole('button', { name });
}

findSaveNewButton() {
return this.find().findByTestId(['save-new-button']);
}

findEditSaveButton(id: string) {
return this.find().findByTestId(['save-button', id]);
}
}

export const usersTab = new UsersTab();
10 changes: 5 additions & 5 deletions frontend/src/__tests__/cypress/cypress/pages/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class PermissionsTab {
}

getUserTable() {
return new PermissionTable(() => cy.findByTestId('project-sharing-table User'));
return new PermissionTable(() => cy.findByTestId('role-binding-table User'));
}

getGroupTable() {
return new PermissionTable(() => cy.findByTestId('project-sharing-table Group'));
return new PermissionTable(() => cy.findByTestId('role-binding-table Group'));
}
}

Expand All @@ -37,11 +37,11 @@ class PermissionTable extends Contextual<HTMLElement> {
}

findAddInput() {
return this.find().findByTestId('project-sharing-name-input');
return this.find().findByTestId('role-binding-name-input');
}

findEditInput(id: string) {
return this.find().findByTestId(['project-sharing-name-input', id]);
return this.find().findByTestId(['role-binding-name-input', id]);
}

getTableRow(name: string) {
Expand All @@ -56,7 +56,7 @@ class PermissionTable extends Contextual<HTMLElement> {

selectPermission(id: string, name: string) {
return this.find()
.findByTestId(['project-sharing-name-input', id])
.findByTestId(['role-binding-name-input', id])
.parents('tr')
.findByRole('button', { name: 'Options menu' })
.findSelectOption(name)
Expand Down
Loading

0 comments on commit 9836d03

Please sign in to comment.