Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
fix: protected pages tests (#8145)
Browse files Browse the repository at this point in the history
* fix: protected pages tests

* fix: admin tests
  • Loading branch information
eddiejaoude committed Jul 12, 2023
1 parent 66b4d52 commit 7422eee
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ NEXTAUTH_URL="http://localhost:3000"
LINKFREE_API_SECRET="development"
GITHUB_API_TOKEN=""
RANDOM_USERS="eddiejaoude,sarajaoude"
ADMIN_USERS="eddiejaoude,SaraJaoude"
ADMIN_USERS="eddiejaoude,SaraJaoude,_test-admin-user"
6 changes: 4 additions & 2 deletions pages/404.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ export default function Page404() {
<Page>
<div className="grid min-h-full place-items-center px-6 py-24 sm:py-32 lg:px-8">
<div className="text-center">
<p className="text-base font-semibold text-secondary-high">404</p>
<p className="text-base font-semibold text-primary-high dark:text-primary-low">
404
</p>
<h1 className="mt-4 text-3xl font-bold tracking-tight text-primary-high dark:text-primary-low sm:text-5xl">
Page not found
</h1>
<p className="m-6 text-base leading-7 text-primary-medium dark:text-primary-medium-low">
<p className="m-6 text-base leading-7 text-primary-high dark:text-primary-low">
Sorry, we could not find the page you are looking for.
</p>
<Image
Expand Down
5 changes: 2 additions & 3 deletions pages/account/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function getServerSideProps(context) {
if (!session) {
return {
redirect: {
destination: "/",
destination: "/auth/signin",
permanent: false,
},
};
Expand Down Expand Up @@ -115,9 +115,8 @@ export default function Statistics({ data, profile, progress, BASE_URL }) {
/>

<Page>

<Navigation />

<UserMini
BASE_URL={BASE_URL}
username={profile.username}
Expand Down
2 changes: 1 addition & 1 deletion pages/admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function getServerSideProps(context) {
if (!serverEnv.ADMIN_USERS.includes(username)) {
return {
redirect: {
destination: "/auth/signin",
destination: "/404",
permanent: false,
},
};
Expand Down
4 changes: 2 additions & 2 deletions tests/404.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test.describe("accessibility tests (light)", () => {
test.use({ colorScheme: "light" });

test("should pass axe wcag accessibility tests", async ({ page }) => {
await page.goto("/events");
await page.goto("/404");
const accessibilityScanResults = await new AxeBuilder({ page })
.withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"])
.analyze();
Expand All @@ -23,7 +23,7 @@ test.describe("accessibility tests (dark)", () => {
test.use({ colorScheme: "dark" });

test("should pass axe wcag accessibility tests (dark)", async ({ page }) => {
await page.goto("/events");
await page.goto("/404");
const accessibilityScanResults = await new AxeBuilder({ page })
.withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"])
.analyze();
Expand Down
62 changes: 62 additions & 0 deletions tests/admin/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
import { login, logout } from "../setup/auth";

test("Guest user cannot access admin statistics", async ({ browser }) => {
// fixture: make sure user is not logged in
const context = await logout(browser);
const page = await context.newPage();
await page.goto("/admin");
await expect(page).toHaveURL(/auth\/signin/);
});

test("Logged in user cannot access admin statistics", async ({ browser }) => {
// fixture: make sure user is not logged in
const context = await login(browser);
const page = await context.newPage();
await page.goto("/admin");
await expect(page).toHaveURL(/404/);
});

test("Admin user can access dashboard", async ({ browser }) => {
// fixture: make sure user is logged in
const context = await login(browser, {
id: "66666666",
name: "Automated Test Admin User",
email: "test-admin-user@test.com",
username: "_test-admin-user",
});
const page = await context.newPage();
await page.goto("/admin");
await expect(page).toHaveURL(/admin/);
});

test.describe("accessibility tests (light)", () => {
test.use({ colorScheme: "light" });

test("should pass axe wcag accessibility tests", async ({ browser }) => {
const context = await login(browser);
const page = await context.newPage();
await page.goto("/admin");
const accessibilityScanResults = await new AxeBuilder({ page })
.withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"])
.analyze();
expect(accessibilityScanResults.violations).toEqual([]);
});
});

test.describe("accessibility tests (dark)", () => {
test.use({ colorScheme: "dark" });

test("should pass axe wcag accessibility tests (dark)", async ({
browser,
}) => {
const context = await login(browser);
const page = await context.newPage();
await page.goto("/admin");
const accessibilityScanResults = await new AxeBuilder({ page })
.withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"])
.analyze();
expect(accessibilityScanResults.violations).toEqual([]);
});
});
18 changes: 14 additions & 4 deletions tests/manage/events.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
import { login } from "../setup/auth";
import { login, logout } from "../setup/auth";

test("Logged in user can access dashboard", async ({ browser }) => {
test("Guest user cannot access manage events", async ({ browser }) => {
// fixture: make sure user is not logged in
const context = await logout(browser);
const page = await context.newPage();
await page.goto("/account/manage/events");
await expect(page).toHaveURL(/auth\/signin/);
});

test("Logged in user can access manage events", async ({ browser }) => {
// fixture: make sure user is logged in
const context = await login(browser);
const page = await context.newPage();
Expand All @@ -27,7 +35,9 @@ test.describe("accessibility tests (light)", () => {
test.describe("accessibility tests (dark)", () => {
test.use({ colorScheme: "dark" });

test("should pass axe wcag accessibility tests (dark)", async ({ browser }) => {
test("should pass axe wcag accessibility tests (dark)", async ({
browser,
}) => {
const context = await login(browser);
const page = await context.newPage();
await page.goto("/account/manage/events");
Expand All @@ -36,4 +46,4 @@ test.describe("accessibility tests (dark)", () => {
.analyze();
expect(accessibilityScanResults.violations).toEqual([]);
});
});
});
18 changes: 14 additions & 4 deletions tests/manage/links.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
import { login } from "../setup/auth";
import { login, logout } from "../setup/auth";

test("Logged in user can access dashboard", async ({ browser }) => {
test("Guest user cannot access manage links", async ({ browser }) => {
// fixture: make sure user is not logged in
const context = await logout(browser);
const page = await context.newPage();
await page.goto("/account/manage/links");
await expect(page).toHaveURL(/auth\/signin/);
});

test("Logged in user can access manage links", async ({ browser }) => {
// fixture: make sure user is logged in
const context = await login(browser);
const page = await context.newPage();
Expand All @@ -27,7 +35,9 @@ test.describe("accessibility tests (light)", () => {
test.describe("accessibility tests (dark)", () => {
test.use({ colorScheme: "dark" });

test("should pass axe wcag accessibility tests (dark)", async ({ browser }) => {
test("should pass axe wcag accessibility tests (dark)", async ({
browser,
}) => {
const context = await login(browser);
const page = await context.newPage();
await page.goto("/account/manage/links");
Expand All @@ -36,4 +46,4 @@ test.describe("accessibility tests (dark)", () => {
.analyze();
expect(accessibilityScanResults.violations).toEqual([]);
});
});
});
18 changes: 14 additions & 4 deletions tests/manage/milestones.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
import { login } from "../setup/auth";
import { login, logout } from "../setup/auth";

test("Logged in user can access dashboard", async ({ browser }) => {
test("Guest user cannot access manage milestones", async ({ browser }) => {
// fixture: make sure user is not logged in
const context = await logout(browser);
const page = await context.newPage();
await page.goto("/account/manage/milestones");
await expect(page).toHaveURL(/auth\/signin/);
});

test("Logged in user can access manage milestones", async ({ browser }) => {
// fixture: make sure user is logged in
const context = await login(browser);
const page = await context.newPage();
Expand All @@ -27,7 +35,9 @@ test.describe("accessibility tests (light)", () => {
test.describe("accessibility tests (dark)", () => {
test.use({ colorScheme: "dark" });

test("should pass axe wcag accessibility tests (dark)", async ({ browser }) => {
test("should pass axe wcag accessibility tests (dark)", async ({
browser,
}) => {
const context = await login(browser);
const page = await context.newPage();
await page.goto("/account/manage/milestones");
Expand All @@ -36,4 +46,4 @@ test.describe("accessibility tests (dark)", () => {
.analyze();
expect(accessibilityScanResults.violations).toEqual([]);
});
});
});
18 changes: 14 additions & 4 deletions tests/manage/profile.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
import { login } from "../setup/auth";
import { login, logout } from "../setup/auth";

test("Logged in user can access dashboard", async ({ browser }) => {
test("Guest user cannot access manage profile", async ({ browser }) => {
// fixture: make sure user is not logged in
const context = await logout(browser);
const page = await context.newPage();
await page.goto("/account/manage/profile");
await expect(page).toHaveURL(/auth\/signin/);
});

test("Logged in user can access manage profile", async ({ browser }) => {
// fixture: make sure user is logged in
const context = await login(browser);
const page = await context.newPage();
Expand All @@ -27,7 +35,9 @@ test.describe("accessibility tests (light)", () => {
test.describe("accessibility tests (dark)", () => {
test.use({ colorScheme: "dark" });

test("should pass axe wcag accessibility tests (dark)", async ({ browser }) => {
test("should pass axe wcag accessibility tests (dark)", async ({
browser,
}) => {
const context = await login(browser);
const page = await context.newPage();
await page.goto("/account/manage/profile");
Expand All @@ -36,4 +46,4 @@ test.describe("accessibility tests (dark)", () => {
.analyze();
expect(accessibilityScanResults.violations).toEqual([]);
});
});
});
49 changes: 49 additions & 0 deletions tests/manage/statistics.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
import { login, logout } from "../setup/auth";

test("Guest user cannot access statistics", async ({ browser }) => {
// fixture: make sure user is not logged in
const context = await logout(browser);
const page = await context.newPage();
await page.goto("/account/statistics");
await expect(page).toHaveURL(/auth\/signin/);
});

test("Logged in user can access statistics", async ({ browser }) => {
// fixture: make sure user is logged in
const context = await login(browser);
const page = await context.newPage();
await page.goto("/account/statistics");
await expect(page).toHaveURL(/account\/statistics/);
});

test.describe("accessibility tests (light)", () => {
test.use({ colorScheme: "light" });

test("should pass axe wcag accessibility tests", async ({ browser }) => {
const context = await login(browser);
const page = await context.newPage();
await page.goto("/account/manage/events");
const accessibilityScanResults = await new AxeBuilder({ page })
.withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"])
.analyze();
expect(accessibilityScanResults.violations).toEqual([]);
});
});

test.describe("accessibility tests (dark)", () => {
test.use({ colorScheme: "dark" });

test("should pass axe wcag accessibility tests (dark)", async ({
browser,
}) => {
const context = await login(browser);
const page = await context.newPage();
await page.goto("/account/manage/events");
const accessibilityScanResults = await new AxeBuilder({ page })
.withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"])
.analyze();
expect(accessibilityScanResults.violations).toEqual([]);
});
});
18 changes: 14 additions & 4 deletions tests/manage/testimonials.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
import { login } from "../setup/auth";
import { login, logout } from "../setup/auth";

test("Logged in user can access dashboard", async ({ browser }) => {
test("Guest user cannot access manage testimonials", async ({ browser }) => {
// fixture: make sure user is not logged in
const context = await logout(browser);
const page = await context.newPage();
await page.goto("/account/manage/testimonials");
await expect(page).toHaveURL(/auth\/signin/);
});

test("Logged in user can access manage testimonials", async ({ browser }) => {
// fixture: make sure user is logged in
const context = await login(browser);
const page = await context.newPage();
Expand All @@ -27,7 +35,9 @@ test.describe("accessibility tests (light)", () => {
test.describe("accessibility tests (dark)", () => {
test.use({ colorScheme: "dark" });

test("should pass axe wcag accessibility tests (dark)", async ({ browser }) => {
test("should pass axe wcag accessibility tests (dark)", async ({
browser,
}) => {
const context = await login(browser);
const page = await context.newPage();
await page.goto("/account/manage/testimonials");
Expand All @@ -36,4 +46,4 @@ test.describe("accessibility tests (dark)", () => {
.analyze();
expect(accessibilityScanResults.violations).toEqual([]);
});
});
});
Loading

0 comments on commit 7422eee

Please sign in to comment.