Skip to content

Commit

Permalink
feat(tests): add control permission + navigation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NuttyShrimp committed Sep 6, 2024
1 parent b1633d7 commit 6b20b6f
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
89 changes: 89 additions & 0 deletions loama/tests/permission-table.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,93 @@ test.describe("Permission table", () => {
await readPermCheckbox.check();
await expect(readPermCheckbox).toBeEnabled();
});

test("Granting control permission give's a popup", async ({ page }) => {
await page.getByText("README").click();

// Check if right panel is loaded
const rightPanelElem = page.locator(".right-panel");
const listHeader = rightPanelElem.locator(".list-header");
await expect(listHeader).toContainText("Subjects with permissions")

await rightPanelElem.getByRole("button", { name: "Edit" }).click();

const tableDrawer = page.locator(".permission-drawer");
const publicSubjectRow = tableDrawer.locator("tr", { hasText: "Public" });
await expect(publicSubjectRow).toBeVisible();
await publicSubjectRow.getByRole("button", { name: "Edit" }).click();

const subjectEditorDrawer = page.locator(".subject-drawer");
await expect(subjectEditorDrawer).toBeVisible()
const controlPermCheckbox = subjectEditorDrawer.getByLabel('Control')
await expect(controlPermCheckbox).not.toBeChecked();
await controlPermCheckbox.check();

const checkDialog = page.getByText("Grant control permission?");
await expect(checkDialog).toBeVisible();
});

test("Grant btn in popup contol permission gives the permission", async ({ page }) => {
await page.getByText("README").click();

// Check if right panel is loaded
const rightPanelElem = page.locator(".right-panel");
const listHeader = rightPanelElem.locator(".list-header");
await expect(listHeader).toContainText("Subjects with permissions")

await rightPanelElem.getByRole("button", { name: "Edit" }).click();

const tableDrawer = page.locator(".permission-drawer");
const publicSubjectRow = tableDrawer.locator("tr", { hasText: "Public" });
await expect(publicSubjectRow).toBeVisible();
await publicSubjectRow.getByRole("button", { name: "Edit" }).click();

const subjectEditorDrawer = page.locator(".subject-drawer");
await expect(subjectEditorDrawer).toBeVisible()
const controlPermCheckbox = subjectEditorDrawer.getByLabel('Control')
await expect(controlPermCheckbox).not.toBeChecked();
await controlPermCheckbox.check();

const checkDialog = page.getByRole("alertdialog", { name: "Grant control permission?" });
await expect(checkDialog).toBeVisible();

await checkDialog.getByRole("button", { name: "Grant" }).click();

await expect(controlPermCheckbox).toBeEnabled();
await expect(controlPermCheckbox).toBeChecked();
await controlPermCheckbox.uncheck();
await expect(controlPermCheckbox).toBeEnabled();
});

test("An toast should show while updating permissions", async ({ page }) => {
await page.getByText("README").click();

// Check if right panel is loaded
const rightPanelElem = page.locator(".right-panel");
const listHeader = rightPanelElem.locator(".list-header");
await expect(listHeader).toContainText("Subjects with permissions")

await rightPanelElem.getByRole("button", { name: "Edit" }).click();

const tableDrawer = page.locator(".permission-drawer");
const publicSubjectRow = tableDrawer.locator("tr", { hasText: "Public" });
await expect(publicSubjectRow).toBeVisible();
await publicSubjectRow.getByRole("button", { name: "Edit" }).click();

const subjectEditorDrawer = page.locator(".subject-drawer");
await expect(subjectEditorDrawer).toBeVisible()
const writePermCheckbox = subjectEditorDrawer.getByLabel('Write')
await expect(writePermCheckbox).not.toBeChecked();
await writePermCheckbox.check();

const mask = page.locator(".p-drawer-mask", { hasText: "Edit subject" })
await mask.click({ position: { x: 1, y: 1 } });

const alertToast = page.getByRole("alert")
await expect(alertToast).toBeVisible();

await expect(writePermCheckbox).toBeEnabled();
await writePermCheckbox.uncheck();
await expect(writePermCheckbox).toBeEnabled();
})
})
12 changes: 12 additions & 0 deletions loama/tests/resource-explorer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,16 @@ test.describe("Resource Explorer", () => {

expect(page.getByText("card")).toBeVisible();
})
test("Can go up a level", async ({ page }) => {
await page.getByRole("button", { name: "View resources" }).click();
const breadcrumsElement = page.locator("#explorer-breadcrumbs");
await expect(breadcrumsElement).toContainText("/home/profile/");

await expect(page.locator(".left-panel").getByText("card")).toBeVisible();

const homeLink = page.getByRole('link', { name: 'home' });
await homeLink.click();
await expect(page.locator('div').filter({ hasText: /^profile$/ })).toBeVisible();
await expect(breadcrumsElement).toContainText("/home/");
})
})

0 comments on commit 6b20b6f

Please sign in to comment.