Skip to content

Feed · E2E tests

15 modules · 52 exports · 5 repositories · 3 e2e tests · 1 route

  • SSendou
  • DDev
  • Arrange data setup
  • Act what the user does
  • Assert what is expected

Feed

turning on the new home page shows the feed on the front page

Setup
Arrange
  1. Create friendship post
    await createFriendshipPost(factories);
SSendou
Feed page
Act
  1. Enable as home page
    await feed.enableAsHomePage();
  2. Open the feed page
    await feed.goto();
Assert
  1. heading is visible
    await expect(feed.locators.heading).toBeVisible();
  2. post “/Callie\s+and\s+Marie\s+are now friends/” is visible
    await expect(feed.post(FRIENDSHIP_POST)).toBeVisible();
Source
test("turning on the new home page shows the feed on the front page", async ({
	page,
	factories,
}) => {
	await createFriendshipPost(factories);

	await impersonate(page);
	const feed = new FeedPage(page);
	await feed.enableAsHomePage();
	await feed.goto();

	await expect(feed.locators.heading).toBeVisible();
	await expect(feed.post(FRIENDSHIP_POST)).toBeVisible();
})

a comment and a reaction on a post are saved

Setup
Arrange
  1. Create friendship post
    await createFriendshipPost(factories);
  2. Grant user Sendou preferences new home page true
    await factories.UserFactory.grant(ADMIN_ID, {
    	preferences: { newHomePage: true },
    });
SSendou
Feed page
Act
  1. Open the feed page
    await feed.goto();
  2. Open post “/Callie\s+and\s+Marie\s+are now friends/” → post
    const post = await feed.openPost(FRIENDSHIP_POST);

1comments

SSendou
Assert
  1. post.locators.noCommentsText is visible
    await expect(post.locators.noCommentsText).toBeVisible();
Act
  1. Comment “Congrats you two!”
    await post.comment("Congrats you two!");
  2. Reload
    await post.reload();
Assert
  1. post.locators.comments count is 1
    await expect(post.locators.comments).toHaveCount(1);
  2. post.locators.comments contains “Congrats you two!”
    await expect(post.locators.comments).toContainText("Congrats you two!");

2reacts and takes the reaction back

SSendou
Act
  1. Toggle reaction
    await post.toggleReaction();
  2. Reload
    await post.reload();
Assert
  1. post.locators.reactButton has “aria-pressed” = “true”
    await expect(post.locators.reactButton).toHaveAttribute(
    	"aria-pressed",
    	"true",
    );
  2. post.locators.reactButton reads “1”
    await expect(post.locators.reactButton).toHaveText("1");
Act
  1. Toggle reaction
    await post.toggleReaction();
  2. Reload
    await post.reload();
Assert
  1. post.locators.reactButton has “aria-pressed” = “false”
    await expect(post.locators.reactButton).toHaveAttribute(
    	"aria-pressed",
    	"false",
    );
Source
test("a comment and a reaction on a post are saved", async ({
	page,
	factories,
}) => {
	await createFriendshipPost(factories);
	await factories.UserFactory.grant(ADMIN_ID, {
		preferences: { newHomePage: true },
	});

	await impersonate(page);
	const feed = new FeedPage(page);
	await feed.goto();
	const post = await feed.openPost(FRIENDSHIP_POST);

	await test.step("comments", async () => {
		await expect(post.locators.noCommentsText).toBeVisible();
		await post.comment("Congrats you two!");
		await post.reload();

		await expect(post.locators.comments).toHaveCount(1);
		await expect(post.locators.comments).toContainText("Congrats you two!");
	});

	await test.step("reacts and takes the reaction back", async () => {
		await post.toggleReaction();
		await post.reload();
		await expect(post.locators.reactButton).toHaveAttribute(
			"aria-pressed",
			"true",
		);
		await expect(post.locators.reactButton).toHaveText("1");

		await post.toggleReaction();
		await post.reload();
		await expect(post.locators.reactButton).toHaveAttribute(
			"aria-pressed",
			"false",
		);
	});
})

a share link shows the post to someone it isn't in the feed of

Setup
Arrange
  1. Create friendship post
    await createFriendshipPost(factories);
  2. Create dev user
    await factories.UserFactory.createDev();
  3. Grant user Sendou preferences new home page true
    await factories.UserFactory.grant(ADMIN_ID, {
    	preferences: { newHomePage: true },
    });
SSendou
Feed page
Act
  1. Open the feed page
    await feed.goto();
  2. Copy share link → shareLink
    const shareLink = await (
    	await feed.openPost(FRIENDSHIP_POST)
    ).copyShareLink();
DDev
Feed post page
Act
  1. Go to via share link shareLink
    await post.gotoViaShareLink(shareLink);
Assert
  1. post contains “/Callie\s+and\s+Marie\s+are now friends/”
    await expect(post.locators.post).toContainText(FRIENDSHIP_POST);
Source
test("a share link shows the post to someone it isn't in the feed of", async ({
	page,
	factories,
}) => {
	await createFriendshipPost(factories);
	await factories.UserFactory.createDev();
	await factories.UserFactory.grant(ADMIN_ID, {
		preferences: { newHomePage: true },
	});

	await impersonate(page);
	const feed = new FeedPage(page);
	await feed.goto();
	const shareLink = await (
		await feed.openPost(FRIENDSHIP_POST)
	).copyShareLink();

	await impersonate(page, DEV_TEST_ID);
	const post = new FeedPostPage(page);
	await post.gotoViaShareLink(shareLink);

	await expect(post.locators.post).toContainText(FRIENDSHIP_POST);
})