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

Commit

Permalink
feat: discover to search page (fix pr 9496) (#9545)
Browse files Browse the repository at this point in the history
* feat: move discover to search page (#9496)

* feat: show text Recently updated profiles if no search input

* feat: implement discover people logic in search page

* feat: remove discover page and navbar link

* feat: update text for Discover section

* feat: remove test for discover page

---------

Co-authored-by: Eddie Jaoude <[email protected]>

* fix: failing search test

---------

Co-authored-by: Sansar Maske <[email protected]>
  • Loading branch information
eddiejaoude and sansarmaske authored Oct 20, 2023
1 parent e2038b4 commit 921f6d4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 141 deletions.
4 changes: 0 additions & 4 deletions components/navbar/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ export default function Navbar() {
name: "Repos",
url: "/repos",
},
{
name: "Discover",
url: "/discover",
},
{
name: "Pricing",
url: "/pricing",
Expand Down
48 changes: 0 additions & 48 deletions pages/discover.js

This file was deleted.

2 changes: 1 addition & 1 deletion pages/pricing.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export default function Premium({ user }) {
{
name: "Discover",
description:
"See a list of all those BioDrop Profiles which have been recently updated",
"See a list of all those BioDrop Profiles which have been recently updated on the Search Page",
tiers: { Free: true, Premium: true },
},
// {
Expand Down
21 changes: 9 additions & 12 deletions pages/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Badge from "@components/Badge";
import logger from "@config/logger";
import Input from "@components/form/Input";
import { getTags } from "./api/discover/tags";
import { getProfiles } from "./api/profiles";
import { getProfiles } from "./api/discover/profiles";
import Pagination from "@components/Pagination";
import {
cleanSearchInput,
Expand All @@ -28,13 +28,8 @@ async function fetchUsersByKeyword(keyword) {
return searchData.users || [];
}

async function fetchRandomUsers() {
async function fetchRecentlyUpdatedUsers() {
const users = await getProfiles();

if (users.length > 9) {
return users.sort(() => 0.5 - Math.random()).slice(0, 9);
}

return users;
}

Expand All @@ -53,14 +48,14 @@ export async function getServerSideProps(context) {
let serverProps = {
tags: [],
filteredUsers: [],
randUsers: [],
recentlyUpdatedUsers: [],
};

try {
if (keyword) {
serverProps.filteredUsers = await fetchUsersByKeyword(keyword);
} else {
serverProps.randUsers = await fetchRandomUsers();
serverProps.recentlyUpdatedUsers = await fetchRecentlyUpdatedUsers();
}
} catch (e) {
logger.error(e, "ERROR fetching users");
Expand All @@ -74,13 +69,13 @@ export async function getServerSideProps(context) {
}

export default function Search({
data: { tags, randUsers, filteredUsers },
data: { tags, recentlyUpdatedUsers, filteredUsers },
BASE_URL,
}) {
const router = useRouter();
const { username, keyword, userSearchParam } = router.query;
const [notFound, setNotFound] = useState();
const [users, setUsers] = useState(keyword ? filteredUsers : randUsers);
const [users, setUsers] = useState(keyword ? filteredUsers : recentlyUpdatedUsers);
const [inputValue, setInputValue] = useState(
username || keyword || userSearchParam || "",
);
Expand All @@ -102,7 +97,7 @@ export default function Search({
useEffect(() => {
if (!inputValue) {
//Setting the users as null when the input field is empty
setUsers(randUsers);
setUsers(recentlyUpdatedUsers);
//Removing the not found field when the input field is empty
setNotFound();
router.replace(
Expand Down Expand Up @@ -244,6 +239,8 @@ export default function Search({
/>
</Badge>

{!inputValue && <h2 className="mt-10 mb-4 text-2xl font-bold">Recently updated profiles</h2>}

{notFound && <Alert type="error" message={notFound} />}
<ul
role="list"
Expand Down
47 changes: 0 additions & 47 deletions tests/discover.spec.js

This file was deleted.

38 changes: 9 additions & 29 deletions tests/search.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test("Search page has random results when no search term used", async ({
await page.goto("/search");

const input = page.locator("[name='keyword']");
await input.type("");
await input.fill("");

await expect(page.locator("main li")).toHaveCount(defaultUsers);
});
Expand All @@ -66,24 +66,22 @@ test("Search page shows results after typing 3 characters", async ({
await expect(page.locator("main li")).toContainText(["aka"]);
});

test("Search term persistence", async ({ page }) => {
test("Search term persistence after navigating back", async ({ page }) => {
// 1. Perform search
await page.goto("/search");
const input = page.locator("[name='keyword']");
const searchTerm = "eddiejaoude"; // Store the search term
const searchTerm = "eddiejaoude";
await input.fill(searchTerm);

// 2. Click on the searched profile
const profileLinkSelector = 'a[href="/eddiejaoude"]';
const profileLink = page.locator(profileLinkSelector);

await profileLink.click();
// 2. Navigate to profile
await expect(page).toHaveURL("/search?userSearchParam=eddiejaoude");
await page.waitForLoadState("networkidle");
await page.locator("h3:has-text('eddiejaoude')").click();
await page.waitForLoadState("networkidle");

// 3. Check if the profile is displayed
const profileHeader = page.locator("h1");
const profileHeaderText = await profileHeader.innerText();
expect(profileHeaderText).toContain("Eddie Jaoude");
await expect(page).toHaveURL("/eddiejaoude");
await expect(page.locator("h1")).toHaveText("Eddie Jaoude");

// 4. Go back and check that search term is still here
await page.goBack();
Expand All @@ -94,24 +92,6 @@ test("Search term persistence", async ({ page }) => {
expect(inputFieldValue).toBe(searchTerm);
});

test("After search click profile", async ({ page }) => {
// 1. Perform search
await page.goto("/search");
const input = page.locator("[name='keyword']");
await input.type("eddiejaoude");

// 2. Click on the searched profile
const profileLinkSelector = 'a[href="/eddiejaoude"]';
const profileLink = page.locator(profileLinkSelector);
await profileLink.click();
await page.waitForLoadState("networkidle");

// 3. Check if the profile is displayed
const profileHeader = page.locator("h1");
const profileHeaderText = await profileHeader.innerText();
await expect(profileHeaderText).toContain("Eddie Jaoude");
});

test("find the profile after providing concise name", async ({ page }) => {
// 1. Start from the homepage
await page.goto("/");
Expand Down

0 comments on commit 921f6d4

Please sign in to comment.