Skip to content

Commit 57481d1

Browse files
committed
Refactor test cases for note images and notes to streamline data creation and improve assertions
1 parent bbc20b3 commit 57481d1

3 files changed

Lines changed: 10 additions & 21 deletions

File tree

tests/e2e/note-images.test.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ test('Users can edit note image', async ({ page, login }) => {
6464

6565
const note = await prisma.note.create({
6666
select: { id: true },
67-
data: {
68-
...createNoteWithImage(),
69-
ownerId: user.id,
70-
},
67+
data: { ...createNoteWithImage(), ownerId: user.id },
7168
})
7269
await page.goto(`/users/${user.username}/notes/${note.id}`)
7370

@@ -90,10 +87,7 @@ test('Users can delete note image', async ({ page, login }) => {
9087

9188
const note = await prisma.note.create({
9289
select: { id: true, title: true },
93-
data: {
94-
...createNoteWithImage(),
95-
ownerId: user.id,
96-
},
90+
data: { ...createNoteWithImage(), ownerId: user.id },
9791
})
9892
await page.goto(`/users/${user.username}/notes/${note.id}`)
9993

@@ -109,8 +103,8 @@ test('Users can delete note image', async ({ page, login }) => {
109103
await page.getByRole('button', { name: 'remove image' }).click()
110104
await page.getByRole('button', { name: 'submit' }).click()
111105
await expect(page).toHaveURL(`/users/${user.username}/notes/${note.id}`)
112-
const countAfter = await images.count()
113-
expect(countAfter).toEqual(countBefore - 1)
106+
const countAfter = images
107+
await expect(countAfter).toHaveCount(countBefore - 1)
114108
})
115109

116110
function createNote() {

tests/e2e/notes.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,10 @@ test('Users can delete notes', async ({ page, login }) => {
6262
page.getByText('Your note has been deleted.', { exact: true }),
6363
).toBeVisible()
6464
await expect(page).toHaveURL(`/users/${user.username}/notes`)
65-
const countAfter = await noteLinks.count()
66-
expect(countAfter).toEqual(countBefore - 1)
65+
const countAfter = noteLinks
66+
await expect(countAfter).toHaveCount(countBefore - 1)
6767
})
6868

6969
function createNote() {
70-
return {
71-
title: faker.lorem.words(3),
72-
content: faker.lorem.paragraphs(3),
73-
}
70+
return { title: faker.lorem.words(3), content: faker.lorem.paragraphs(3) }
7471
}

tests/e2e/settings-profile.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ test('Users can update their password', async ({ page, login }) => {
4545
expect(
4646
await verifyUserPassword({ username }, oldPassword),
4747
'Old password still works',
48-
).toEqual(null)
48+
).toBeNull()
4949
expect(
5050
await verifyUserPassword({ username }, newPassword),
5151
'New password does not work',
@@ -56,9 +56,7 @@ test('Users can update their profile photo', async ({ page, login }) => {
5656
const user = await login()
5757
await page.goto('/settings/profile')
5858

59-
const beforeSrc = await page
60-
.getByRole('img', { name: user.name ?? user.username })
61-
.getAttribute('src')
59+
const beforeSrc = page.getByRole('img', { name: user.name ?? user.username })
6260

6361
await page.getByRole('link', { name: /change profile photo/i }).click()
6462

@@ -79,7 +77,7 @@ test('Users can update their profile photo', async ({ page, login }) => {
7977
.getByRole('img', { name: user.name ?? user.username })
8078
.getAttribute('src')
8179

82-
expect(beforeSrc).not.toEqual(afterSrc)
80+
expect(beforeSrc).not.toBe(afterSrc)
8381
})
8482

8583
test('Users can change their email address', async ({ page, login }) => {

0 commit comments

Comments
 (0)