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

Commit

Permalink
feat: discover page for recently updated profiles (#8615)
Browse files Browse the repository at this point in the history
* feat: discover page for recently updated profiles

* fix: discover profile page title

* test: discover page test
  • Loading branch information
eddiejaoude authored Aug 12, 2023
1 parent 8cd34ac commit d8f43f9
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 1 deletion.
4 changes: 4 additions & 0 deletions components/navbar/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ export default function Navbar() {
name: "Repos",
url: "/repos",
},
{
name: "Discover",
url: "/discover",
},
];

const authControls = () => (
Expand Down
2 changes: 1 addition & 1 deletion pages/admin/profiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function getServerSideProps(context) {
};
}

export default function USERS({ profiles }) {
export default function Users({ profiles }) {
return (
<>
<PageHead
Expand Down
33 changes: 33 additions & 0 deletions pages/api/discover/profiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import connectMongo from "@config/mongo";
import logger from "@config/logger";
import { Profile } from "@models/index";

export default async function handler(req, res) {
if (req.method != "GET") {
return res
.status(400)
.json({ error: "Invalid request: GET request required" });
}

const profiles = await getProfiles();

res.status(200).json(profiles);
}
export async function getProfiles() {
await connectMongo();

let profiles = [];
try {
profiles = await Profile.find(
{ name: { $exists: true }, isEnabled: true },
["_id", "bio", "name", "username", "avatar", "tags", "updatedAt"]
)
.sort({ updatedAt: -1 })
.limit(9);
} catch (e) {
logger.error(e, "failed loading profiles");
return profiles;
}

return JSON.parse(JSON.stringify(profiles));
}
48 changes: 48 additions & 0 deletions pages/discover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { clientEnv } from "@config/schemas/clientSchema";

import logger from "@config/logger";
import Page from "@components/Page";
import PageHead from "@components/PageHead";
import { getProfiles } from "./api/discover/profiles";

import UserHorizontal from "@components/user/UserHorizontal";

export async function getServerSideProps() {
let profiles = [];
try {
profiles = await getProfiles();
} catch (e) {
logger.error(e, "get users failed");
}
return {
props: {
profiles,
BASE_URL: clientEnv.NEXT_PUBLIC_BASE_URL,
},
};
}

export default function Discover({ profiles }) {
return (
<>
<PageHead
title="Discover recently updated Profiles on LinkFree"
description="Discover recently updated Profiles on LinkFree"
/>
<Page>
<h1 className="text-4xl mb-4 font-bold">Recently updated Profiles</h1>

<ul
role="list"
className="grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3"
>
{profiles.map((profile) => (
<li key={profile.username}>
<UserHorizontal profile={profile} />
</li>
))}
</ul>
</Page>
</>
);
}
46 changes: 46 additions & 0 deletions tests/discover.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// @ts-check
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";

test("Discover has title", async ({ page }) => {
await page.goto("/discover");
await expect(page).toHaveTitle(/Discover/);
});

test("Navigate to the Discover page", async ({ page }) => {
await page.goto("/");
await page
.getByRole("navigation")
.getByRole("link", { name: "Discover" })
.click();
await expect(page.locator("h1")).toHaveText("Recently updated Profiles");
});

test("Discover shows Profiles", async ({ page }) => {
await page.goto("/search");
await expect(page.locator("main li")).toHaveCount(9);
});

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

test("should pass axe wcag accessibility tests (light)", async ({ page }) => {
await page.goto("/discover");
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 ({ page }) => {
await page.goto("/discover");
const accessibilityScanResults = await new AxeBuilder({ page })
.withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"])
.analyze();
expect(accessibilityScanResults.violations).toEqual([]);
});
});

0 comments on commit d8f43f9

Please sign in to comment.