Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions front-end/tests/hashtag.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { test, expect } from "@playwright/test";

test.describe("hashtag view", () => {
test("should only make one fetch request when navigating to a hashtag", async ({ page }) => {
let fetchCount = 0;
page.on("request", (request) => {
if (
request.url().includes(":3000/hashtag/do") &&
request.resourceType() === "fetch"
) {
fetchCount++;
}
});
// When I navigate to the hashtag
await page.goto("/#/hashtag/do");
// And I wait a reasonable time for any additional requests
await page.waitForTimeout(200);

// Then the number of fetch requests should be 1
expect(fetchCount).toEqual(1);
});
});
5 changes: 4 additions & 1 deletion front-end/views/hashtag.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import {createHeading} from "../components/heading.mjs";
function hashtagView(hashtag) {
destroy();

apiService.getBloomsByHashtag(hashtag);
const normalized = hashtag.startsWith("#") ? hashtag : `#${hashtag}`;
if(normalized !== state.currentHashtag){
apiService.getBloomsByHashtag(hashtag);
}

renderOne(
state.isLoggedIn,
Expand Down