Update collab permission tests and minor fixes

This commit is contained in:
thiloho
2024-09-06 16:08:34 +02:00
parent a77d2b2d0c
commit b8d23eab00
16 changed files with 804 additions and 610 deletions

View File

@@ -84,3 +84,7 @@ FROM
ALTER TABLE internal.website ALTER TABLE internal.website
DROP COLUMN title_search; DROP COLUMN title_search;
GRANT SELECT, UPDATE, DELETE ON api.website TO authenticated_user;
GRANT SELECT, INSERT, UPDATE, DELETE ON api.article TO authenticated_user;

View File

@@ -103,6 +103,8 @@ SELECT
FROM FROM
internal.article; internal.article;
GRANT SELECT, INSERT, UPDATE, DELETE ON api.article TO authenticated_user;
DROP VIEW api.docs_category; DROP VIEW api.docs_category;
ALTER TABLE internal.article ALTER TABLE internal.article

View File

@@ -104,3 +104,5 @@ FROM
JOIN internal.home ho ON w.id = ho.website_id JOIN internal.home ho ON w.id = ho.website_id
JOIN internal.footer f ON w.id = f.website_id; JOIN internal.footer f ON w.id = f.website_id;
GRANT SELECT ON api.website_overview TO authenticated_user;

View File

@@ -52,3 +52,5 @@ FROM
ALTER TABLE internal.article ALTER TABLE internal.article
DROP COLUMN article_weight; DROP COLUMN article_weight;
GRANT SELECT, INSERT, UPDATE, DELETE ON api.article TO authenticated_user;

View File

@@ -136,3 +136,5 @@ FROM
JOIN internal.home ho ON w.id = ho.website_id JOIN internal.home ho ON w.id = ho.website_id
JOIN internal.footer f ON w.id = f.website_id; JOIN internal.footer f ON w.id = f.website_id;
GRANT SELECT ON api.website_overview TO authenticated_user;

View File

@@ -136,3 +136,5 @@ FROM
JOIN internal.home ho ON w.id = ho.website_id JOIN internal.home ho ON w.id = ho.website_id
JOIN internal.footer f ON w.id = f.website_id; JOIN internal.footer f ON w.id = f.website_id;
GRANT SELECT ON api.website_overview TO authenticated_user;

View File

@@ -3,6 +3,13 @@ ALTER TABLE internal.article
ALTER COLUMN publication_date DROP NOT NULL; ALTER COLUMN publication_date DROP NOT NULL;
-- migrate:down -- migrate:down
UPDATE
internal.article
SET
publication_date = CURRENT_DATE
WHERE
publication_date IS NULL;
ALTER TABLE internal.article ALTER TABLE internal.article
ALTER COLUMN publication_date SET NOT NULL; ALTER COLUMN publication_date SET NOT NULL;

View File

@@ -33,3 +33,5 @@ SELECT
FROM FROM
internal.website; internal.website;
GRANT SELECT, UPDATE, DELETE ON api.website TO authenticated_user;

View File

@@ -6,10 +6,12 @@ const config: PlaywrightTestConfig = {
url: "http://localhost:4173" url: "http://localhost:4173"
}, },
use: { use: {
baseURL: "http://localhost:4173" baseURL: "http://localhost:4173",
video: "retain-on-failure"
}, },
testDir: "tests", testDir: "tests",
testMatch: /(.+\.)?(test|spec)\.ts/, testMatch: /(.+\.)?(test|spec)\.ts/,
retries: 3,
// Firefox and Webkit are not packaged yet, see https://github.com/NixOS/nixpkgs/issues/288826 // Firefox and Webkit are not packaged yet, see https://github.com/NixOS/nixpkgs/issues/288826
projects: [ projects: [
{ {

View File

@@ -5,33 +5,16 @@ import { join } from "node:path";
export const load: PageServerLoad = async ({ fetch, cookies, url, locals }) => { export const load: PageServerLoad = async ({ fetch, cookies, url, locals }) => {
const searchQuery = url.searchParams.get("website_search_query"); const searchQuery = url.searchParams.get("website_search_query");
const sortBy = url.searchParams.get("website_sort");
const filterBy = url.searchParams.get("website_filter"); const filterBy = url.searchParams.get("website_filter");
const params = new URLSearchParams(); const params = new URLSearchParams();
const baseFetchUrl = `${API_BASE_PREFIX}/website`; const baseFetchUrl = `${API_BASE_PREFIX}/website?order=last_modified_at.desc,created_at.desc`;
if (searchQuery) { if (searchQuery) {
params.append("title_search", `wfts(english).${searchQuery}`); params.append("title_search", `wfts(english).${searchQuery}`);
} }
switch (sortBy) {
case null:
case "creation-time":
params.append("order", "created_at.desc");
break;
case "last-modified":
params.append("order", "last_modified_at.desc");
break;
case "title-a-to-z":
params.append("order", "title.asc");
break;
case "title-z-to-a":
params.append("order", "title.desc");
break;
}
switch (filterBy) { switch (filterBy) {
case "creations": case "creations":
params.append("user_id", `eq.${locals.user.id}`); params.append("user_id", `eq.${locals.user.id}`);
@@ -41,7 +24,7 @@ export const load: PageServerLoad = async ({ fetch, cookies, url, locals }) => {
break; break;
} }
const constructedFetchUrl = `${baseFetchUrl}?${params.toString()}`; const constructedFetchUrl = `${baseFetchUrl}&${params.toString()}`;
const totalWebsitesData = await fetch(baseFetchUrl, { const totalWebsitesData = await fetch(baseFetchUrl, {
method: "HEAD", method: "HEAD",

View File

@@ -54,7 +54,7 @@
</h2> </h2>
<details> <details>
<summary>Search & Sort & Filter</summary> <summary>Search & Filter</summary>
<form method="GET"> <form method="GET">
<label> <label>
Search: Search:
@@ -64,16 +64,6 @@
value={$page.url.searchParams.get("website_search_query")} value={$page.url.searchParams.get("website_search_query")}
/> />
</label> </label>
<label>
Sort:
<select name="website_sort">
{#each sortOptions as { value, text }}
<option {value} selected={value === $page.url.searchParams.get("website_sort")}
>{text}</option
>
{/each}
</select>
</label>
<label> <label>
Filter: Filter:
<select name="website_filter"> <select name="website_filter">

View File

@@ -12,6 +12,11 @@ export const load: PageServerLoad = async ({ params, fetch, cookies, url, parent
baseFetchUrl += baseFetchUrl +=
",article_weight,docs_category(category_name,category_weight)&order=docs_category(category_weight).desc.nullslast,article_weight.desc.nullslast"; ",article_weight,docs_category(category_name,category_weight)&order=docs_category(category_weight).desc.nullslast,article_weight.desc.nullslast";
} }
if (website.content_type === "Blog") {
baseFetchUrl += "&order=last_modified_at.desc,created_at.desc";
}
console.log(baseFetchUrl);
const parameters = new URLSearchParams(); const parameters = new URLSearchParams();

View File

@@ -5,7 +5,7 @@ export const load: PageServerLoad = async ({ parent, params, fetch, cookies }) =
const { website, home } = await parent(); const { website, home } = await parent();
const collabData = await fetch( const collabData = await fetch(
`${API_BASE_PREFIX}/collab?website_id=eq.${params.websiteId}&select=*,user!user_id(*)`, `${API_BASE_PREFIX}/collab?website_id=eq.${params.websiteId}&select=*,user!user_id(*)&order=last_modified_at.desc,added_at.desc`,
{ {
method: "GET", method: "GET",
headers: { headers: {

View File

@@ -14,40 +14,42 @@ const test = base.extend<{ authenticatedPage: Page }>({
} }
}); });
test("Register", async ({ page }) => { test.describe.serial("Account tests", () => {
await page.goto("/register"); test("Register", async ({ page }) => {
await page.getByLabel("Username:").click(); await page.goto("/register");
await page.getByLabel("Username:").fill(username); await page.getByLabel("Username:").click();
await page.getByLabel("Password:").click(); await page.getByLabel("Username:").fill(username);
await page.getByLabel("Password:").fill(password); await page.getByLabel("Password:").click();
await page.getByRole("button", { name: "Submit" }).click(); await page.getByLabel("Password:").fill(password);
await expect(page.getByText("Successfully registered, you")).toBeVisible(); await page.getByRole("button", { name: "Submit" }).click();
}); await expect(page.getByText("Successfully registered, you")).toBeVisible();
});
test("Login", async ({ page }) => { test("Login", async ({ page }) => {
await page.goto("/login"); await page.goto("/login");
await page.getByLabel("Username:").click(); await page.getByLabel("Username:").click();
await page.getByLabel("Username:").fill(username); await page.getByLabel("Username:").fill(username);
await page.getByLabel("Password:").click(); await page.getByLabel("Password:").click();
await page.getByLabel("Password:").fill(password); await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByRole("heading", { name: "Dashboard" })).toBeVisible(); await expect(page.getByRole("heading", { name: "Dashboard" })).toBeVisible();
}); });
test("Logout", async ({ authenticatedPage: page }) => { test("Logout", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Account" }).click(); await page.getByRole("link", { name: "Account" }).click();
await page.getByRole("button", { name: "Logout" }).click(); await page.getByRole("button", { name: "Logout" }).click();
await expect(page.getByRole("heading", { name: "Login" })).toBeVisible(); await expect(page.getByRole("heading", { name: "Login" })).toBeVisible();
}); });
test("Delete account", async ({ authenticatedPage: page }) => { test("Delete account", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Account" }).click(); await page.getByRole("link", { name: "Account" }).click();
await page.getByRole("button", { name: "Delete account" }).click(); await page.getByRole("button", { name: "Delete account" }).click();
await page.getByLabel("Password:").click(); await page.getByLabel("Password:").click();
await page.getByLabel("Password:").fill(password); await page.getByLabel("Password:").fill(password);
await page await page
.locator("#delete-account-modal") .locator("#delete-account-modal")
.getByRole("button", { name: "Delete account" }) .getByRole("button", { name: "Delete account" })
.click(); .click();
await expect(page.getByRole("heading", { name: "Login" })).toBeVisible(); await expect(page.getByRole("heading", { name: "Login" })).toBeVisible();
});
}); });

View File

@@ -1,293 +1,471 @@
import { test, expect, type Page } from "@playwright/test"; import { test, expect } from "@playwright/test";
import { randomBytes } from "node:crypto"; import { randomBytes } from "node:crypto";
const username = randomBytes(8).toString("hex"); const username = randomBytes(8).toString("hex");
const collabUsername = randomBytes(8).toString("hex"); const collabUsername = randomBytes(8).toString("hex");
const collabUsername2 = randomBytes(8).toString("hex"); const collabUsername2 = randomBytes(8).toString("hex");
const collabUsername3 = randomBytes(8).toString("hex"); const collabUsername3 = randomBytes(8).toString("hex");
const collaborators = [collabUsername, collabUsername2, collabUsername3]; const collabUsername4 = randomBytes(8).toString("hex");
const password = "T3stuser??!!"; const password = "T3stuser??!!";
const permissionLevels = [10, 20, 30]; const permissionLevels = [10, 20, 30];
test("Setup", async ({ page }) => { test.describe.serial("Collaborator tests", () => {
await page.goto("/register"); test("Setup", async ({ page }) => {
await page.goto("/register");
await page.getByLabel("Username:").click(); await page.getByLabel("Username:").click();
await page.getByLabel("Username:").fill(username); await page.getByLabel("Username:").fill(username);
await page.getByLabel("Password:").click(); await page.getByLabel("Password:").click();
await page.getByLabel("Password:").fill(password); await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();
await page.getByLabel("Username:").click(); await page.getByLabel("Username:").click();
await page.getByLabel("Username:").fill(collabUsername); await page.getByLabel("Username:").fill(collabUsername);
await page.getByLabel("Password:").click(); await page.getByLabel("Password:").click();
await page.getByLabel("Password:").fill(password); await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();
await page.getByLabel("Username:").click(); await page.getByLabel("Username:").click();
await page.getByLabel("Username:").fill(collabUsername2); await page.getByLabel("Username:").fill(collabUsername2);
await page.getByLabel("Password:").click(); await page.getByLabel("Password:").click();
await page.getByLabel("Password:").fill(password); await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();
await page.getByLabel("Username:").click(); await page.getByLabel("Username:").click();
await page.getByLabel("Username:").fill(collabUsername3); await page.getByLabel("Username:").fill(collabUsername3);
await page.getByLabel("Password:").click(); await page.getByLabel("Password:").click();
await page.getByLabel("Password:").fill(password); await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();
await page.goto("/login"); await page.getByLabel("Username:").click();
await page.getByLabel("Username:").fill(username); await page.getByLabel("Username:").fill(collabUsername4);
await page.getByLabel("Password:").fill(password); await page.getByLabel("Password:").click();
await page.getByRole("button", { name: "Submit" }).click(); await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("button", { name: "Create website" }).click();
await page.getByLabel("Title:").click();
await page.getByLabel("Title:").fill("Blog");
await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("button", { name: "Create website" }).click();
await page.getByLabel("Type: BlogDocs").selectOption("Docs");
await page.getByLabel("Title:").click();
await page.getByLabel("Title:").fill("Documentation");
await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Articles" }).click();
await page.getByRole("button", { name: "Create article" }).click();
await page.getByLabel("Title:").click();
await page.getByLabel("Title:").fill("Article");
await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("link", { name: "Collaborators" }).click();
await page.getByRole("button", { name: "Add collaborator" }).click();
await page.getByLabel("Username:").click();
await page.getByLabel("Username:").fill(collabUsername);
await page.getByRole("button", { name: "Submit" }).click();
await page.goto("/");
await page.getByRole("link", { name: "Documentation" }).click();
await page.getByRole("link", { name: "Categories" }).click();
await page.getByRole("button", { name: "Create category" }).click();
await page.getByLabel("Name:").click();
await page.getByLabel("Name:").fill("Category");
await page.getByLabel("Weight:").click();
await page.getByLabel("Weight:").fill("1000");
await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("link", { name: "Collaborators" }).click();
await page.getByRole("button", { name: "Add collaborator" }).click();
await page.getByLabel("Username:").click();
await page.getByLabel("Username:").fill(collabUsername);
await page.getByRole("button", { name: "Submit" }).click();
});
for (const permissionLevel of permissionLevels) {
test(`Set collaborator permission level to ${permissionLevel}`, async ({ page }) => {
await page.goto("/login"); await page.goto("/login");
await page.getByLabel("Username:").fill(username); await page.getByLabel("Username:").fill(username);
await page.getByLabel("Password:").fill(password); await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("button", { name: "Create website" }).click();
await page.getByLabel("Title:").click();
await page.getByLabel("Title:").fill("Blog");
await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("button", { name: "Create website" }).click();
await page.getByLabel("Type: BlogDocs").selectOption("Docs");
await page.getByLabel("Title:").click();
await page.getByLabel("Title:").fill("Documentation");
await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("link", { name: "Blog" }).click(); await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Articles" }).click();
await page.getByRole("button", { name: "Create article" }).click();
await page.getByLabel("Title:").click();
await page.getByLabel("Title:").fill("Article-10");
await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("link", { name: "Collaborators" }).click(); await page.getByRole("link", { name: "Collaborators" }).click();
await page.getByRole("button", { name: "Update" }).click(); await page.getByRole("button", { name: "Add collaborator" }).click();
await page.getByRole("combobox").selectOption(permissionLevel.toString()); await page.getByLabel("Username:").click();
await page.getByRole("button", { name: "Update collaborator" }).click(); await page.getByLabel("Username:").fill(collabUsername);
await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("button", { name: "Add collaborator" }).click();
await page.getByLabel("Username:").click();
await page.getByLabel("Username:").fill(collabUsername2);
await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("button", { name: "Add collaborator" }).click();
await page.getByLabel("Username:").click();
await page.getByLabel("Username:").fill(collabUsername3);
await page.getByRole("combobox").selectOption("30");
await page.getByRole("button", { name: "Submit" }).click();
await page.goto("/");
await page.getByRole("link", { name: "Documentation" }).click();
await page.getByRole("link", { name: "Categories" }).click();
await page.getByRole("button", { name: "Create category" }).click();
await page.getByLabel("Name:").click();
await page.getByLabel("Name:").fill("Category-10");
await page.getByLabel("Weight:").click();
await page.getByLabel("Weight:").fill("10");
await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("link", { name: "Collaborators" }).click();
await page.getByRole("button", { name: "Add collaborator" }).click();
await page.getByLabel("Username:").click();
await page.getByLabel("Username:").fill(collabUsername);
await page.getByRole("button", { name: "Submit" }).click();
}); });
test.describe.serial(`Permission level: ${permissionLevel}`, () => { for (const permissionLevel of permissionLevels) {
test.beforeEach(async ({ page }) => { test(`Set collaborator permission level to ${permissionLevel}`, async ({ page }) => {
await page.goto("/login"); await page.goto("/login");
await page.getByLabel("Username:").fill(collabUsername); await page.getByLabel("Username:").fill(username);
await page.getByLabel("Password:").fill(password); await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();
});
test("Update website", async ({ page }) => {
await page.getByRole("button", { name: "Update" }).nth(1).click();
await page.getByRole("button", { name: "Submit" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
}
});
test("Delete website", async ({ page }) => {
await page.getByRole("button", { name: "Delete" }).nth(0).click();
await page.getByRole("button", { name: "Delete website" }).click();
await expect(page.getByText("You do not have the required")).toBeVisible();
});
test("Update Global", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.locator("#global").getByRole("button", { name: "Submit" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
}
});
test("Update Header", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.locator("#header").getByRole("button", { name: "Submit" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
}
});
test("Update Home", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.locator("#home").getByRole("button", { name: "Submit" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
}
});
test("Update Footer", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.locator("#footer").getByRole("button", { name: "Submit" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
}
});
test("Create article", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Articles" }).click();
await page.getByRole("button", { name: "Create article" }).click();
await page.getByLabel("Title:").click();
await page.getByLabel("Title:").fill("Article");
await page.getByRole("button", { name: "Submit" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
}
});
test("Update article", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Articles" }).click();
await page.getByRole("link", { name: "Edit" }).nth(0).click();
await page.getByLabel("Description:").click();
await page.getByLabel("Description:").fill("Description");
await page.getByLabel("Author:").click();
await page.getByLabel("Author:").fill("Author");
await page.getByLabel("Main content:").click();
await page.getByLabel("Main content:").fill("## Main content");
await page.getByRole("button", { name: "Submit" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
}
});
test("Delete article", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Articles" }).click();
await page.getByRole("button", { name: "Delete" }).nth(0).click();
await page.getByRole("button", { name: "Delete article" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
}
});
test("Add collaborator", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click(); await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Collaborators" }).click(); await page.getByRole("link", { name: "Collaborators" }).click();
await page.getByRole("button", { name: "Add collaborator" }).click();
await page.getByLabel("Username:").click();
await page await page
.getByLabel("Username:") .locator("li")
.fill(collaborators[permissionLevels.indexOf(permissionLevel)]); .filter({ hasText: collabUsername })
await page.getByRole("button", { name: "Submit" }).click(); .getByRole("button")
.first()
if (permissionLevel === 10) { .click();
await expect(page.getByText("You do not have the required")).toBeVisible(); await page.getByRole("combobox").selectOption(permissionLevel.toString());
}
});
test("Update collaborator", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Collaborators" }).click();
await page.getByRole("button", { name: "Update" }).nth(0).click();
await page.getByRole("combobox").selectOption("20");
await page.getByRole("button", { name: "Update collaborator" }).click(); await page.getByRole("button", { name: "Update collaborator" }).click();
if (permissionLevel === 10) { await page.goto("/");
await expect(page.getByText("You do not have the required")).toBeVisible(); await page.getByRole("link", { name: "Documentation" }).click();
}
});
test("Remove collaborator", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Collaborators" }).click(); await page.getByRole("link", { name: "Collaborators" }).click();
await page.getByRole("button", { name: "Remove" }).nth(0).click();
await page.getByRole("button", { name: "Remove collaborator" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
}
});
test("Create category", async ({ page }) => {
await page.getByRole("link", { name: "Documentation" }).click();
await page.getByRole("link", { name: "Categories" }).click();
await page.getByRole("button", { name: "Create category" }).click();
await page.getByLabel("Name:").click();
await page.getByLabel("Name:").fill("Test");
await page.getByRole("spinbutton", { name: "Weight:" }).click();
await page.getByRole("spinbutton", { name: "Weight:" }).fill("900");
await page.getByRole("button", { name: "Submit" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
}
});
test("Update category", async ({ page }) => {
await page.getByRole("link", { name: "Documentation" }).click();
await page.getByRole("link", { name: "Categories" }).click();
await page.getByRole("button", { name: "Update" }).nth(0).click();
await page.getByRole("spinbutton", { name: "Weight:" }).click();
await page.getByRole("spinbutton", { name: "Weight:" }).fill("500");
await page.getByRole("button", { name: "Update category" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
}
});
test("Delete category", async ({ page }) => {
await page.getByRole("link", { name: "Documentation" }).click();
await page.getByRole("link", { name: "Categories" }).click();
await page.getByRole("button", { name: "Delete" }).nth(0).click();
await page.getByRole("button", { name: "Delete category" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
}
});
test("Publish website", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Publish" }).click();
await page.getByRole("button", { name: "Publish" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
}
});
});
}
test.describe("Delete all accounts", () => {
const allUsers = collaborators.concat(username);
for (const user of allUsers) {
test(`Delete account ${allUsers.indexOf(user)}`, async ({ page }) => {
await page.goto("/login");
await page.getByLabel("Username:").fill(user);
await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("link", { name: "Account" }).click();
await page.getByRole("button", { name: "Delete account" }).click();
await page.getByLabel("Password:").click();
await page.getByLabel("Password:").fill(password);
await page await page
.locator("#delete-account-modal") .locator("li")
.getByRole("button", { name: "Delete account" }) .filter({ hasText: collabUsername })
.getByRole("button")
.first()
.click(); .click();
await page.getByRole("combobox").selectOption(permissionLevel.toString());
await page.getByRole("button", { name: "Update collaborator" }).click();
});
test.describe.serial(`Permission level: ${permissionLevel}`, () => {
test.beforeEach(async ({ page }) => {
await page.goto("/login");
await page.getByLabel("Username:").fill(collabUsername);
await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click();
});
test("Update website", async ({ page }) => {
await page.locator("li").filter({ hasText: "Blog" }).getByRole("button").first().click();
await page.getByRole("button", { name: "Submit" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
} else {
await expect(page.getByText("Successfully updated website")).toBeVisible();
}
});
test("Delete website", async ({ page }) => {
await page.locator("li").filter({ hasText: "Blog" }).getByRole("button").nth(1).click();
await page.getByRole("button", { name: "Delete website" }).click();
await expect(page.getByText("You do not have the required")).toBeVisible();
});
test("Update Global", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.locator("#global").getByRole("button", { name: "Submit" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
} else {
await expect(page.getByText("Successfully updated global")).toBeVisible();
}
});
test("Update Header", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.locator("#header").getByRole("button", { name: "Submit" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
} else {
await expect(page.getByText("Successfully updated header")).toBeVisible();
}
});
test("Update Home", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.locator("#home").getByRole("button", { name: "Submit" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
} else {
await expect(page.getByText("Successfully updated home")).toBeVisible();
}
});
test("Update Footer", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.locator("#footer").getByRole("button", { name: "Submit" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
} else {
await expect(page.getByText("Successfully updated footer")).toBeVisible();
}
});
test("Create article", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Articles" }).click();
await page.getByRole("button", { name: "Create article" }).click();
await page.getByLabel("Title:").click();
await page.getByLabel("Title:").fill(`Article-${permissionLevel}`);
await page.getByRole("button", { name: "Submit" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
} else {
await expect(page.getByText("Successfully created article")).toBeVisible();
}
});
test("Update article", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Articles" }).click();
await page
.locator("li")
.filter({ hasText: `Article-${permissionLevel}` })
.getByRole("link")
.click();
await page.getByLabel("Description:").click();
await page.getByLabel("Description:").fill("Description");
await page.getByLabel("Author:").click();
await page.getByLabel("Author:").fill("Author");
await page.getByLabel("Main content:").click();
await page.getByLabel("Main content:").fill("## Main content");
await page.getByRole("button", { name: "Submit" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
} else {
await expect(page.getByText("Successfully updated article")).toBeVisible();
}
});
test("Delete article", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Articles" }).click();
await page
.locator("li")
.filter({ hasText: `Article-${permissionLevel}` })
.getByRole("button")
.click();
await page.getByRole("button", { name: "Delete article" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
}
if ([20, 30].includes(permissionLevel)) {
await expect(page.getByText("Successfully deleted article")).toBeVisible();
await page.locator("li").filter({ hasText: `Article-10` }).getByRole("button").click();
await page.getByRole("button", { name: "Delete article" }).click();
if (permissionLevel === 20) {
await expect(page.getByText("You do not have the required")).toBeVisible();
} else {
await expect(page.getByText("Successfully deleted article")).toBeVisible();
}
}
});
test("Add collaborator", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Collaborators" }).click();
await page.getByRole("button", { name: "Add collaborator" }).click();
await page.getByLabel("Username:").click();
await page.getByLabel("Username:").fill(collabUsername4);
await page.getByRole("button", { name: "Submit" }).click();
if ([10, 20].includes(permissionLevel)) {
await expect(page.getByText("You do not have the required")).toBeVisible();
} else {
await expect(page.getByText("Successfully added")).toBeVisible();
}
});
test("Update collaborator", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Collaborators" }).click();
await page
.locator("li")
.filter({ hasText: collabUsername2 })
.getByRole("button")
.first()
.click();
await page.getByRole("combobox").selectOption("20");
await page.getByRole("button", { name: "Update collaborator" }).click();
if ([10, 20].includes(permissionLevel)) {
await expect(page.getByText("You do not have the required")).toBeVisible();
} else {
await expect(page.getByText("Successfully updated")).toBeVisible();
await page
.locator("li")
.filter({ hasText: collabUsername2 })
.getByRole("button")
.first()
.click();
await page.getByRole("combobox").selectOption("30");
await page.getByRole("button", { name: "Update collaborator" }).click();
await expect(page.getByText("You do not have the required")).toBeVisible();
}
});
test("Remove collaborator", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Collaborators" }).click();
await page
.locator("li")
.filter({ hasText: collabUsername2 })
.getByRole("button")
.nth(1)
.click();
await page.getByRole("button", { name: "Remove collaborator" }).click();
if ([10, 20].includes(permissionLevel)) {
await expect(page.getByText("You do not have the required")).toBeVisible();
} else {
await expect(page.getByText("Successfully removed")).toBeVisible();
await page
.locator("li")
.filter({ hasText: collabUsername3 })
.getByRole("button")
.nth(1)
.click();
await page.getByRole("button", { name: "Remove collaborator" }).click();
await expect(page.getByText("You do not have the required")).toBeVisible();
}
});
test("Create category", async ({ page }) => {
await page.getByRole("link", { name: "Documentation" }).click();
await page.getByRole("link", { name: "Categories" }).click();
await page.getByRole("button", { name: "Create category" }).click();
await page.getByLabel("Name:").click();
await page.getByLabel("Name:").fill(`Category-${permissionLevel}`);
await page.getByRole("spinbutton", { name: "Weight:" }).click();
await page.getByRole("spinbutton", { name: "Weight:" }).fill(permissionLevel.toString());
await page.getByRole("button", { name: "Submit" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
} else {
await expect(page.getByText("Successfully created category")).toBeVisible();
}
});
test("Update category", async ({ page }) => {
await page.getByRole("link", { name: "Documentation" }).click();
await page.getByRole("link", { name: "Categories" }).click();
await page
.locator("li")
.filter({ hasText: `Category-${permissionLevel}` })
.getByRole("button")
.first()
.click();
await page.getByRole("spinbutton", { name: "Weight:" }).click();
await page
.getByRole("spinbutton", { name: "Weight:" })
.fill((permissionLevel * 2).toString());
await page.getByRole("button", { name: "Update category" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
} else {
await expect(page.getByText("Successfully updated category")).toBeVisible();
}
});
test("Delete category", async ({ page }) => {
await page.getByRole("link", { name: "Documentation" }).click();
await page.getByRole("link", { name: "Categories" }).click();
await page
.locator("li")
.filter({ hasText: `Category-${permissionLevel}` })
.getByRole("button")
.nth(1)
.click();
await page.getByRole("button", { name: "Delete category" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
}
if ([20, 30].includes(permissionLevel)) {
await expect(page.getByText("Successfully deleted category")).toBeVisible();
await page
.locator("li")
.filter({ hasText: "Category-10" })
.getByRole("button")
.nth(1)
.click();
await page.getByRole("button", { name: "Delete category" }).click();
if (permissionLevel === 20) {
await expect(page.getByText("You do not have the required")).toBeVisible();
} else {
await expect(page.getByText("Successfully deleted category")).toBeVisible();
}
}
});
test("Publish website", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Publish" }).click();
await page.getByRole("button", { name: "Publish" }).click();
if (permissionLevel === 10) {
await expect(page.getByText("You do not have the required")).toBeVisible();
} else {
await expect(page.getByText("Successfully published website")).toBeVisible();
}
});
}); });
} }
test("Delete all accounts", async ({ page }) => {
await page.goto("/login");
await page.getByLabel("Username:").fill(username);
await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("link", { name: "Account" }).click();
await page.getByRole("button", { name: "Delete account" }).click();
await page.getByLabel("Password:").click();
await page.getByLabel("Password:").fill(password);
await page
.locator("#delete-account-modal")
.getByRole("button", { name: "Delete account" })
.click();
await page.getByLabel("Username:").fill(collabUsername);
await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("link", { name: "Account" }).click();
await page.getByRole("button", { name: "Delete account" }).click();
await page.getByLabel("Password:").click();
await page.getByLabel("Password:").fill(password);
await page
.locator("#delete-account-modal")
.getByRole("button", { name: "Delete account" })
.click();
await page.getByLabel("Username:").fill(collabUsername2);
await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("link", { name: "Account" }).click();
await page.getByRole("button", { name: "Delete account" }).click();
await page.getByLabel("Password:").click();
await page.getByLabel("Password:").fill(password);
await page
.locator("#delete-account-modal")
.getByRole("button", { name: "Delete account" })
.click();
await page.getByLabel("Username:").fill(collabUsername3);
await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("link", { name: "Account" }).click();
await page.getByRole("button", { name: "Delete account" }).click();
await page.getByLabel("Password:").click();
await page.getByLabel("Password:").fill(password);
await page
.locator("#delete-account-modal")
.getByRole("button", { name: "Delete account" })
.click();
await page.getByLabel("Username:").fill(collabUsername4);
await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("link", { name: "Account" }).click();
await page.getByRole("button", { name: "Delete account" }).click();
await page.getByLabel("Password:").click();
await page.getByLabel("Password:").fill(password);
await page
.locator("#delete-account-modal")
.getByRole("button", { name: "Delete account" })
.click();
});
}); });

View File

@@ -21,212 +21,253 @@ const test = base.extend<{ authenticatedPage: Page }>({
} }
}); });
test("Register", async ({ page }) => { test.describe.serial("Website tests", () => {
await page.goto("/register"); test("Register", async ({ page }) => {
await page.goto("/register");
await page.getByLabel("Username:").click(); await page.getByLabel("Username:").click();
await page.getByLabel("Username:").fill(username); await page.getByLabel("Username:").fill(username);
await page.getByLabel("Password:").click(); await page.getByLabel("Password:").click();
await page.getByLabel("Password:").fill(password); await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();
await page.getByLabel("Username:").click(); await page.getByLabel("Username:").click();
await page.getByLabel("Username:").fill(collabUsername); await page.getByLabel("Username:").fill(collabUsername);
await page.getByLabel("Password:").click(); await page.getByLabel("Password:").click();
await page.getByLabel("Password:").fill(password); await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();
}); });
test("Create websites", async ({ authenticatedPage: page }) => { test("Create websites", async ({ authenticatedPage: page }) => {
await page.getByRole("button", { name: "Create website" }).click(); await page.getByRole("button", { name: "Create website" }).click();
await page.getByLabel("Title:").click(); await page.getByLabel("Title:").click();
await page.getByLabel("Title:").fill("Blog"); await page.getByLabel("Title:").fill("Blog");
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByRole("link", { name: "All websites" })).toBeVisible(); await expect(page.getByRole("link", { name: "All websites" })).toBeVisible();
await expect(page.getByText("Search & Sort & Filter")).toBeVisible(); await expect(page.getByText("Search & Filter")).toBeVisible();
await expect(page.getByText("Blog Type: Blog Created at:")).toBeVisible(); await expect(page.getByText("Blog Type: Blog Created at:")).toBeVisible();
await page.getByRole("button", { name: "Create website" }).click(); await page.getByRole("button", { name: "Create website" }).click();
await page.getByLabel("Type: BlogDocs").selectOption("Docs"); await page.getByLabel("Type: BlogDocs").selectOption("Docs");
await page.getByLabel("Title:").click(); await page.getByLabel("Title:").click();
await page.getByLabel("Title:").fill("Documentation"); await page.getByLabel("Title:").fill("Documentation");
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByRole("link", { name: "All websites" })).toBeVisible(); await expect(page.getByRole("link", { name: "All websites" })).toBeVisible();
await expect(page.getByText("Search & Sort & Filter")).toBeVisible(); await expect(page.getByText("Search & Filter")).toBeVisible();
await expect(page.getByText("Documentation Type: Docs")).toBeVisible(); await expect(page.getByText("Documentation Type: Docs")).toBeVisible();
}); });
test("Update websites", async ({ authenticatedPage: page }) => { test("Update websites", async ({ authenticatedPage: page }) => {
await page.getByRole("button", { name: "Update" }).nth(1).click(); await page.locator("li").filter({ hasText: "Blog" }).getByRole("button").first().click();
await page.getByRole("textbox", { name: "Title" }).click(); await page.getByRole("textbox", { name: "Title" }).click();
await page.getByRole("textbox", { name: "Title" }).fill("Blog updated"); await page.getByRole("textbox", { name: "Title" }).fill("Blog updated");
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByRole("link", { name: "Blog updated" })).toBeVisible(); await expect(page.getByRole("link", { name: "Blog updated" })).toBeVisible();
await page.getByRole("button", { name: "Update" }).first().click(); await page
await page.getByRole("textbox", { name: "Title" }).click(); .locator("li")
await page.getByRole("textbox", { name: "Title" }).fill("Documentation updated"); .filter({ hasText: "Documentation" })
await page.getByRole("button", { name: "Submit" }).click(); .getByRole("button")
await expect(page.getByRole("link", { name: "Documentation updated" })).toBeVisible(); .first()
}); .click();
await page.getByRole("textbox", { name: "Title" }).click();
await page.getByRole("textbox", { name: "Title" }).fill("Documentation updated");
await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByRole("link", { name: "Documentation updated" })).toBeVisible();
});
test.describe("Blog", () => { test.describe.serial("Blog", () => {
test.describe("Update settings", () => { test.describe.serial("Update settings", () => {
test("Global", async ({ authenticatedPage: page }) => { test("Global", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Blog" }).click(); await page.getByRole("link", { name: "Blog" }).click();
await page.getByLabel("Light accent color:").click(); await page.getByLabel("Light accent color:").click();
await page.getByLabel("Light accent color:").fill("#3975a2"); await page.getByLabel("Light accent color:").fill("#3975a2");
await page.getByLabel("Dark accent color:").click(); await page.getByLabel("Dark accent color:").click();
await page.getByLabel("Dark accent color:").fill("#41473e"); await page.getByLabel("Dark accent color:").fill("#41473e");
await page.locator("#global").getByRole("button", { name: "Submit" }).click(); await page.locator("#global").getByRole("button", { name: "Submit" }).click();
await expect(page.getByText("Successfully updated global")).toBeVisible(); await expect(page.getByText("Successfully updated global")).toBeVisible();
await page.getByLabel("Favicon:").click(); await page.getByLabel("Favicon:").click();
await page await page
.getByLabel("Favicon:") .getByLabel("Favicon:")
.setInputFiles(join(__dirname, "sample-files", "archtika-logo-512x512.png")); .setInputFiles(join(__dirname, "sample-files", "archtika-logo-512x512.png"));
await page.locator("#global").getByRole("button", { name: "Submit" }).click(); await page.locator("#global").getByRole("button", { name: "Submit" }).click();
await expect(page.getByText("Successfully updated global")).toBeVisible(); await expect(page.getByText("Successfully updated global")).toBeVisible();
});
test("Header", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByLabel("Logo text:").click();
await page.getByLabel("Logo text:").fill("archtika Blog updated");
await page.locator("#header").getByRole("button", { name: "Submit" }).click();
await expect(page.getByText("Successfully updated header")).toBeVisible();
await page.getByLabel("Logo type: TextImage").selectOption("image");
await page.getByLabel("Logo image:").click();
await page
.getByLabel("Logo image:")
.setInputFiles(join(__dirname, "sample-files", "archtika-logo-512x512.png"));
await page.locator("#header").getByRole("button", { name: "Submit" }).click();
await expect(page.getByText("Successfully updated header")).toBeVisible();
});
test("Home", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByLabel("Main content:").click();
await page.getByLabel("Main content:").press("Control+a");
await page.getByLabel("Main content:").fill("## Some new content comes here");
await expect(page.getByRole("link", { name: "Some new content comes here" })).toBeVisible();
await page.locator("#home").getByRole("button", { name: "Submit" }).click();
await expect(page.getByText("Successfully updated home")).toBeVisible();
});
test("Footer", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByLabel("Additional text:").click();
await page
.getByLabel("Additional text:")
.fill(
"archtika is a free, open, modern, performant and lightweight CMS updated content comes here"
);
await page.locator("#footer").getByRole("button", { name: "Submit" }).click();
await expect(page.getByText("Successfully updated footer")).toBeVisible();
});
}); });
test("Header", async ({ authenticatedPage: page }) => { test.describe.serial("Articles", () => {
await page.getByRole("link", { name: "Blog" }).click(); test("Create article", async ({ authenticatedPage: page }) => {
await page.getByLabel("Logo text:").click(); await page.getByRole("link", { name: "Blog" }).click();
await page.getByLabel("Logo text:").fill("archtika Blog updated"); await page.getByRole("link", { name: "Articles" }).click();
await page.locator("#header").getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Create article" }).click();
await expect(page.getByText("Successfully updated header")).toBeVisible(); await page.getByLabel("Title:").click();
await page.getByLabel("Logo type: TextImage").selectOption("image"); await page.getByLabel("Title:").fill("Test article");
await page.getByLabel("Logo image:").click(); await page.getByRole("button", { name: "Submit" }).click();
await page await expect(page.getByRole("link", { name: "All articles" })).toBeVisible();
.getByLabel("Logo image:") await expect(page.getByText("Search & Filter")).toBeVisible();
.setInputFiles(join(__dirname, "sample-files", "archtika-logo-512x512.png")); await expect(page.getByText("Test article Edit Delete")).toBeVisible();
await page.locator("#header").getByRole("button", { name: "Submit" }).click(); });
await expect(page.getByText("Successfully updated header")).toBeVisible();
test("Update article", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Articles" }).click();
await page.getByRole("link", { name: "Edit" }).click();
await page.getByLabel("Description:").click();
await page.getByLabel("Description:").fill("Sample article description");
await page.getByLabel("Author:").click();
await page.getByLabel("Author:").fill("John Doe");
await page.getByLabel("Main content:").click();
await page
.getByLabel("Main content:")
.fill(
"## Section\n\n### Subsection\n\n## Second section\n\n### Second subsection\n\n#### Sub Sub section"
);
await expect(
page.getByText(
"Table of contents SectionSubsectionSecond sectionSecond subsectionSub Sub"
)
).toBeVisible();
await expect(
page.getByRole("heading", { name: "Section", exact: true }).getByRole("link")
).toBeVisible();
await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByText("Successfully updated article")).toBeVisible();
});
test("Paste image", async ({ authenticatedPage: page, context }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Articles" }).click();
await page.getByRole("link", { name: "Edit" }).click();
await page.getByLabel("Main content:").click();
await context.grantPermissions(["clipboard-read", "clipboard-write"]);
const isMac = platform() === "darwin";
const modifier = isMac ? "Meta" : "Control";
const clipPage = await context.newPage();
await clipPage.goto("https://picsum.photos/400/400.jpg");
await clipPage.keyboard.press(`${modifier}+KeyC`);
await page.bringToFront();
await page.keyboard.press("Enter");
await page.keyboard.press("Enter");
await page.keyboard.press(`${modifier}+KeyV`);
await expect(page.getByText("Successfully uploaded image")).toBeVisible();
});
test("Delete article", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Articles" }).click();
await page.getByRole("button", { name: "Delete" }).click();
await page.getByRole("button", { name: "Delete article" }).click();
await expect(page.getByText("Successfully deleted article")).toBeVisible();
});
}); });
test("Home", async ({ authenticatedPage: page }) => { test.describe.serial("Collaborators", () => {
await page.getByRole("link", { name: "Blog" }).click(); test("Add collaborator", async ({ authenticatedPage: page }) => {
await page.getByLabel("Main content:").click(); await page.getByRole("link", { name: "Blog" }).click();
await page.getByLabel("Main content:").press("Control+a"); await page.getByRole("link", { name: "Collaborators" }).click();
await page.getByLabel("Main content:").fill("## Some new content comes here"); await page.getByRole("button", { name: "Add collaborator" }).click();
await expect(page.getByRole("link", { name: "Some new content comes here" })).toBeVisible(); await page.getByLabel("Username:").click();
await page.locator("#home").getByRole("button", { name: "Submit" }).click(); await page.getByLabel("Username:").fill(collabUsername);
await expect(page.getByText("Successfully updated home")).toBeVisible(); await page.getByRole("button", { name: "Submit" }).click();
}); await expect(page.getByText("Successfully added")).toBeVisible();
});
test("Footer", async ({ authenticatedPage: page }) => { test("Update collaborator", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Blog" }).click(); await page.getByRole("link", { name: "Blog" }).click();
await page.getByLabel("Additional text:").click(); await page.getByRole("link", { name: "Collaborators" }).click();
await page await page.getByRole("button", { name: "Update" }).click();
.getByLabel("Additional text:") await page.getByRole("combobox").selectOption("20");
.fill( await page.getByRole("button", { name: "Update collaborator" }).click();
"archtika is a free, open, modern, performant and lightweight CMS updated content comes here" await expect(page.getByText("Successfully updated")).toBeVisible();
); });
await page.locator("#footer").getByRole("button", { name: "Submit" }).click();
await expect(page.getByText("Successfully updated footer")).toBeVisible(); test("Remove collaborator", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Collaborators" }).click();
await page.getByRole("button", { name: "Remove" }).click();
await page.getByRole("button", { name: "Remove collaborator" }).click();
await expect(page.getByText("Successfully removed")).toBeVisible();
});
}); });
}); });
test.describe.serial("Articles", () => { test.describe.serial("Docs", () => {
test("Create article", async ({ authenticatedPage: page }) => { test.describe.serial("Categories", () => {
await page.getByRole("link", { name: "Blog" }).click(); test("Create category", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Articles" }).click(); await page.getByRole("link", { name: "Documentation" }).click();
await page.getByRole("button", { name: "Create article" }).click(); await page.getByRole("link", { name: "Categories" }).click();
await page.getByLabel("Title:").click(); await page.getByRole("button", { name: "Create category" }).click();
await page.getByLabel("Title:").fill("Test article"); await page.getByLabel("Name:").click();
await page.getByRole("button", { name: "Submit" }).click(); await page.getByLabel("Name:").fill("Category");
await expect(page.getByRole("link", { name: "All articles" })).toBeVisible(); await page.getByLabel("Weight:").click();
await expect(page.getByText("Search & Filter")).toBeVisible(); await page.getByLabel("Weight:").fill("1000");
await expect(page.getByText("Test article Edit Delete")).toBeVisible(); await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByText("Successfully created category")).toBeVisible();
await expect(page.getByRole("link", { name: "All categories" })).toBeVisible();
await expect(page.getByText("Category (1000)")).toBeVisible();
});
test("Update category", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Documentation" }).click();
await page.getByRole("link", { name: "Categories" }).click();
await page.getByRole("button", { name: "Update" }).click();
await page.getByRole("spinbutton", { name: "Weight:" }).click();
await page.getByRole("spinbutton", { name: "Weight:" }).fill("500");
await page.getByRole("button", { name: "Update category" }).click();
await expect(page.getByText("Successfully updated category")).toBeVisible();
await expect(page.getByText("Category (500)")).toBeVisible();
});
test("Delete category", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Documentation" }).click();
await page.getByRole("link", { name: "Categories" }).click();
await page.getByRole("button", { name: "Delete" }).click();
await page.getByRole("button", { name: "Delete category" }).click();
await expect(page.getByText("Successfully deleted category")).toBeVisible();
await expect(page.getByRole("link", { name: "All categories" })).toBeHidden();
});
}); });
test("Update article", async ({ authenticatedPage: page }) => { test("Article", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Articles" }).click();
await page.getByRole("link", { name: "Edit" }).click();
await page.getByLabel("Description:").click();
await page.getByLabel("Description:").fill("Sample article description");
await page.getByLabel("Author:").click();
await page.getByLabel("Author:").fill("John Doe");
await page.getByLabel("Main content:").click();
await page
.getByLabel("Main content:")
.fill(
"## Section\n\n### Subsection\n\n## Second section\n\n### Second subsection\n\n#### Sub Sub section"
);
await expect(
page.getByText("Table of contents SectionSubsectionSecond sectionSecond subsectionSub Sub")
).toBeVisible();
await expect(
page.getByRole("heading", { name: "Section", exact: true }).getByRole("link")
).toBeVisible();
await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByText("Successfully updated article")).toBeVisible();
});
test("Paste image", async ({ authenticatedPage: page, context }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Articles" }).click();
await page.getByRole("link", { name: "Edit" }).click();
await page.getByLabel("Main content:").click();
await context.grantPermissions(["clipboard-read", "clipboard-write"]);
const isMac = platform() === "darwin";
const modifier = isMac ? "Meta" : "Control";
const clipPage = await context.newPage();
await clipPage.goto("https://picsum.photos/400/400.jpg");
await clipPage.keyboard.press(`${modifier}+KeyC`);
await page.bringToFront();
await page.keyboard.press("Enter");
await page.keyboard.press("Enter");
await page.keyboard.press(`${modifier}+KeyV`);
await expect(page.getByText("Successfully uploaded image")).toBeVisible();
});
test("Delete article", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Articles" }).click();
await page.getByRole("button", { name: "Delete" }).click();
await page.getByRole("button", { name: "Delete article" }).click();
await expect(page.getByText("Successfully deleted article")).toBeVisible();
});
});
test.describe.serial("Collaborators", () => {
test("Add collaborator", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Collaborators" }).click();
await page.getByRole("button", { name: "Add collaborator" }).click();
await page.getByLabel("Username:").click();
await page.getByLabel("Username:").fill(collabUsername);
await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByText("Successfully added")).toBeVisible();
});
test("Update collaborator", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Collaborators" }).click();
await page.getByRole("button", { name: "Update" }).click();
await page.getByRole("combobox").selectOption("20");
await page.getByRole("button", { name: "Update collaborator" }).click();
await expect(page.getByText("Successfully updated")).toBeVisible();
});
test("Remove collaborator", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Collaborators" }).click();
await page.getByRole("button", { name: "Remove" }).click();
await page.getByRole("button", { name: "Remove collaborator" }).click();
await expect(page.getByText("Successfully removed")).toBeVisible();
});
});
});
test.describe("Docs", () => {
test.describe.serial("Categories", () => {
test("Create category", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Documentation" }).click(); await page.getByRole("link", { name: "Documentation" }).click();
await page.getByRole("link", { name: "Categories" }).click(); await page.getByRole("link", { name: "Categories" }).click();
await page.getByRole("button", { name: "Create category" }).click(); await page.getByRole("button", { name: "Create category" }).click();
@@ -235,112 +276,82 @@ test.describe("Docs", () => {
await page.getByLabel("Weight:").click(); await page.getByLabel("Weight:").click();
await page.getByLabel("Weight:").fill("1000"); await page.getByLabel("Weight:").fill("1000");
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByText("Successfully created category")).toBeVisible(); await page.getByRole("link", { name: "Articles" }).click();
await expect(page.getByRole("link", { name: "All categories" })).toBeVisible(); await page.getByRole("button", { name: "Create article" }).click();
await expect(page.getByText("Category (1000)")).toBeVisible(); await page.getByLabel("Title:").click();
}); await page.getByLabel("Title:").fill("Article");
test("Update category", async ({ authenticatedPage: page }) => { await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("link", { name: "Documentation" }).click(); await page.getByRole("link", { name: "Edit" }).click();
await page.getByRole("link", { name: "Categories" }).click(); await page.getByLabel("Weight:").click();
await page.getByRole("button", { name: "Update" }).click(); await page.getByLabel("Weight:").fill("1000");
await page.getByRole("spinbutton", { name: "Weight:" }).click(); await page.getByLabel("Title:").click();
await page.getByRole("spinbutton", { name: "Weight:" }).fill("500"); await page.getByLabel("Title:").fill("Article");
await page.getByRole("button", { name: "Update category" }).click(); await page.getByLabel("Description:").click();
await expect(page.getByText("Successfully updated category")).toBeVisible(); await page.getByLabel("Description:").fill("Testing out this article");
await expect(page.getByText("Category (500)")).toBeVisible(); await page.getByLabel("Author:").click();
}); await page.getByLabel("Author:").fill("John Doe");
test("Delete category", async ({ authenticatedPage: page }) => { await page.getByLabel("Main content:").click();
await page.getByRole("link", { name: "Documentation" }).click(); await page
await page.getByRole("link", { name: "Categories" }).click(); .getByLabel("Main content:")
await page.getByRole("button", { name: "Delete" }).click(); .fill(
await page.getByRole("button", { name: "Delete category" }).click(); "## Main content comes in here\n\n### First section\n\n### Second section\n\n## More"
await expect(page.getByText("Successfully deleted category")).toBeVisible(); );
await expect(page.getByRole("link", { name: "All categories" })).toBeHidden(); await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByText("Successfully updated article")).toBeVisible();
await expect(page.getByText("Table of contents Main")).toBeVisible();
await expect(
page.getByRole("heading", { name: "Main content comes in here" }).getByRole("link")
).toBeVisible();
}); });
}); });
test("Article", async ({ authenticatedPage: page }) => { test("Publish websites", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Publish" }).click();
await page.getByRole("button", { name: "Publish" }).click();
await expect(page.getByText("Successfully published website")).toBeVisible();
await expect(page.getByText("Your website is published at")).toBeVisible();
await page.goto("/");
await page.getByRole("link", { name: "Documentation" }).click(); await page.getByRole("link", { name: "Documentation" }).click();
await page.getByRole("link", { name: "Categories" }).click(); await page.getByRole("link", { name: "Publish" }).click();
await page.getByRole("button", { name: "Create category" }).click(); await page.getByRole("button", { name: "Publish" }).click();
await page.getByLabel("Name:").click(); await expect(page.getByText("Successfully published website")).toBeVisible();
await page.getByLabel("Name:").fill("Category"); await expect(page.getByText("Your website is published at")).toBeVisible();
await page.getByLabel("Weight:").click(); });
await page.getByLabel("Weight:").fill("1000");
await page.getByRole("button", { name: "Submit" }).click(); test("Delete websites", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Articles" }).click(); await page.getByRole("button", { name: "Delete" }).nth(1).click();
await page.getByRole("button", { name: "Create article" }).click(); await page.getByRole("button", { name: "Delete website" }).click();
await page.getByLabel("Title:").click(); await expect(page.getByText("Successfully deleted website")).toBeVisible();
await page.getByLabel("Title:").fill("Article");
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Delete" }).click();
await page.getByRole("link", { name: "Edit" }).click(); await page.getByRole("button", { name: "Delete website" }).click();
await page.getByLabel("Weight:").click(); await expect(page.getByText("Successfully deleted website")).toBeVisible();
await page.getByLabel("Weight:").fill("1000");
await page.getByLabel("Title:").click(); await expect(page.getByRole("link", { name: "All websites" })).toBeHidden();
await page.getByLabel("Title:").fill("Article"); });
await page.getByLabel("Description:").click();
await page.getByLabel("Description:").fill("Testing out this article"); test("Delete accounts", async ({ authenticatedPage: page }) => {
await page.getByLabel("Author:").click(); await page.getByRole("link", { name: "Account" }).click();
await page.getByLabel("Author:").fill("John Doe"); await page.getByRole("button", { name: "Delete account" }).click();
await page.getByLabel("Main content:").click(); await page.getByLabel("Password:").click();
await page.getByLabel("Password:").fill(password);
await page await page
.getByLabel("Main content:") .locator("#delete-account-modal")
.fill("## Main content comes in here\n\n### First section\n\n### Second section\n\n## More"); .getByRole("button", { name: "Delete account" })
.click();
await page.getByLabel("Username:").fill(collabUsername);
await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByText("Successfully updated article")).toBeVisible(); await page.getByRole("link", { name: "Account" }).click();
await expect(page.getByText("Table of contents Main")).toBeVisible(); await page.getByRole("button", { name: "Delete account" }).click();
await expect( await page.getByLabel("Password:").click();
page.getByRole("heading", { name: "Main content comes in here" }).getByRole("link") await page.getByLabel("Password:").fill(password);
).toBeVisible(); await page
.locator("#delete-account-modal")
.getByRole("button", { name: "Delete account" })
.click();
}); });
}); });
test("Publish websites", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Publish" }).click();
await page.getByRole("button", { name: "Publish" }).click();
await expect(page.getByText("Successfully published website")).toBeVisible();
await expect(page.getByText("Your website is published at")).toBeVisible();
await page.goto("/");
await page.getByRole("link", { name: "Documentation" }).click();
await page.getByRole("link", { name: "Publish" }).click();
await page.getByRole("button", { name: "Publish" }).click();
await expect(page.getByText("Successfully published website")).toBeVisible();
await expect(page.getByText("Your website is published at")).toBeVisible();
});
test("Delete websites", async ({ authenticatedPage: page }) => {
await page.getByRole("button", { name: "Delete" }).nth(1).click();
await page.getByRole("button", { name: "Delete website" }).click();
await expect(page.getByText("Successfully deleted website")).toBeVisible();
await page.getByRole("button", { name: "Delete" }).click();
await page.getByRole("button", { name: "Delete website" }).click();
await expect(page.getByText("Successfully deleted website")).toBeVisible();
await expect(page.getByRole("link", { name: "All websites" })).toBeHidden();
});
test("Delete accounts", async ({ authenticatedPage: page }) => {
await page.getByRole("link", { name: "Account" }).click();
await page.getByRole("button", { name: "Delete account" }).click();
await page.getByLabel("Password:").click();
await page.getByLabel("Password:").fill(password);
await page
.locator("#delete-account-modal")
.getByRole("button", { name: "Delete account" })
.click();
await page.getByLabel("Username:").fill(collabUsername);
await page.getByLabel("Password:").fill(password);
await page.getByRole("button", { name: "Submit" }).click();
await page.getByRole("link", { name: "Account" }).click();
await page.getByRole("button", { name: "Delete account" }).click();
await page.getByLabel("Password:").click();
await page.getByLabel("Password:").fill(password);
await page
.locator("#delete-account-modal")
.getByRole("button", { name: "Delete account" })
.click();
});