diff --git a/front-end/tests/hashtag.spec.mjs b/front-end/tests/hashtag.spec.mjs new file mode 100644 index 0000000..303c47c --- /dev/null +++ b/front-end/tests/hashtag.spec.mjs @@ -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); + }); +}); \ No newline at end of file diff --git a/front-end/views/hashtag.mjs b/front-end/views/hashtag.mjs index 7b7e996..2275170 100644 --- a/front-end/views/hashtag.mjs +++ b/front-end/views/hashtag.mjs @@ -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,