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
23 changes: 23 additions & 0 deletions front-end/tests/hashtag.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { test, expect } from "@playwright/test";

test("should not make infinite hashtag endpoint requests", async ({ page }) => {
// ===== ARRANGE
const requests = [];
page.on("request", (request) => {
if (
request.url().includes(":3000/hashtag/do") &&
request.resourceType() === "fetch"
) {
requests.push(request);
}
});
// ====== ACT
// 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);

// ====== ASSERT
// Then the number of requests should be 1
expect(requests.length).toEqual(1);
});
18 changes: 11 additions & 7 deletions front-end/views/hashtag.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {renderOne, renderEach, destroy} from "../lib/render.mjs";
import { renderOne, renderEach, destroy } from "../lib/render.mjs";
import {
state,
apiService,
Expand All @@ -7,17 +7,21 @@ import {
getTimelineContainer,
getHeadingContainer,
} from "../index.mjs";
import {createLogin, handleLogin} from "../components/login.mjs";
import {createLogout, handleLogout} from "../components/logout.mjs";
import {createBloom} from "../components/bloom.mjs";
import {createHeading} from "../components/heading.mjs";
import { createLogin, handleLogin } from "../components/login.mjs";
import { createLogout, handleLogout } from "../components/logout.mjs";
import { createBloom } from "../components/bloom.mjs";
import { createHeading } from "../components/heading.mjs";

// Hashtag view: show all tweets containing this tag

function hashtagView(hashtag) {
destroy();

apiService.getBloomsByHashtag(hashtag);
// Check that hashtag starts with hash to make right comparison with state
const hashtagWithHash = hashtag.startsWith("#") ? hashtag : `#${hashtag}`;
if (state.currentHashtag !== hashtagWithHash) {
apiService.getBloomsByHashtag(hashtag);
}

renderOne(
state.isLoggedIn,
Expand Down Expand Up @@ -52,4 +56,4 @@ function hashtagView(hashtag) {
);
}

export {hashtagView};
export { hashtagView };