Skip to content

Commit 1e34338

Browse files
committed
Merge branch 'fork/O-Bots/main'
# Conflicts: # tests/e2e/utils/contextManager.ts # tests/e2e/web/pages/app.ts # tests/e2e/web/pages/peoplePage.ts # tests/e2e/web/specs/signIn.spec.ts
2 parents 31e05aa + 6991840 commit 1e34338

5 files changed

Lines changed: 108 additions & 68 deletions

File tree

playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ export default defineConfig({
6565
],
6666
timeout: 120000,
6767
expect: {
68-
timeout: 120000,
68+
timeout: 60000,
6969
},
7070
})

tests/e2e/utils/contextManager.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ export class ContextManager {
1414
if (existing) await existing.page.context().close()
1515

1616
const context = await this.browser.newContext()
17-
const page = await context.newPage()
18-
const app = new App(page)
19-
this.contexts.set(name, app)
20-
return app
17+
try {
18+
const page = await context.newPage()
19+
const app = new App(page, false)
20+
this.contexts.set(name, app)
21+
return app
22+
} catch (error) {
23+
await context.close()
24+
throw error
25+
}
2126
}
2227

2328
getContext(name: string): App | undefined {
@@ -26,7 +31,11 @@ export class ContextManager {
2631

2732
async closeAll(): Promise<void> {
2833
for (const app of this.contexts.values()) {
29-
await app.page.context().close()
34+
try {
35+
await app.page.context().close()
36+
} catch {
37+
// context may already be closed
38+
}
3039
}
3140
this.contexts.clear()
3241
}

tests/e2e/web/pages/app.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ export class App {
2828
readonly people: PeoplePage
2929
readonly notifs: NotificationPage
3030
readonly messages: MessagesPage
31-
readonly contextManager: ContextManager
31+
readonly contextManager: ContextManager | undefined
3232
readonly context: BrowserContext
3333

34-
constructor(public readonly page: Page) {
34+
constructor(
35+
public readonly page: Page,
36+
createContextManager = true,
37+
) {
3538
this.auth = new AuthPage(page)
3639
this.compatibility = new CompatibilityPage(page)
3740
this.home = new HomePage(page)
@@ -46,9 +49,11 @@ export class App {
4649
this.messages = new MessagesPage(page)
4750
this.context = page.context()
4851

49-
const browser = page.context().browser()
50-
if (!browser) throw new Error('Could not get Browser from page.context().browser()')
51-
this.contextManager = new ContextManager(browser)
52+
if (createContextManager) {
53+
const browser = page.context().browser()
54+
if (!browser) throw new Error('Could not get Browser from page.context().browser()')
55+
this.contextManager = new ContextManager(browser)
56+
}
5257
}
5358

5459
async deleteProfileFromSettings() {

tests/e2e/web/pages/peoplePage.ts

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import {expect, Locator, Page} from '@playwright/test'
22
import {
3+
CannabisTuple,
34
ConnectionTypeTuple,
4-
EducationTuple,
55
DietTuple,
6-
PsychedelicsTuple,
7-
CannabisTuple,
6+
EducationTuple,
7+
InterestedInGenderTuple,
88
LanguageTuple,
9+
LastActiveTuple,
10+
PersonalityKey,
911
PoliticalTuple,
12+
PsychedelicsTuple,
1013
ReligionTuple,
11-
PersonalityKey,
12-
LastActiveTuple,
13-
InterestedInGenderTuple,
1414
} from 'common/choices'
15+
1516
import {MinMaxNumbers} from '../utils/accountInformation'
1617

1718
export type BackgroundFilter = {
@@ -459,22 +460,7 @@ export class PeoplePage {
459460
if (totalResults === 0) throw Error('No profiles found')
460461
const chosenProfileNumber = Math.floor(Math.random() * totalResults)
461462
const chosenProfile = await this.profileResults.nth(chosenProfileNumber)
462-
const profileName = await chosenProfile.getByTestId('people-profile-name').textContent()
463-
const ageGender = await chosenProfile.getByTestId('people-profile-age-gender').textContent()
464-
const seekingInfo = await chosenProfile.getByTestId('people-profile-seeking').textContent()
465-
const hideProfile = await chosenProfile.getByTestId('hide-profile-button')
466-
const starProfile = await chosenProfile.getByTestId('star-profile-button')
467-
const messageProfile = await chosenProfile.getByTestId('message-profile-button')
468-
469-
return {
470-
profile: chosenProfile ?? '',
471-
name: profileName ?? '',
472-
ageGender: ageGender ?? '',
473-
seeking: seekingInfo ?? '',
474-
hide: hideProfile ?? '',
475-
star: starProfile ?? '',
476-
message: messageProfile ?? '',
477-
}
463+
return chosenProfile
478464
}
479465

480466
async verifyProfileCount(totalProfiles: string) {
@@ -512,7 +498,8 @@ export class PeoplePage {
512498
}
513499
}
514500

515-
async verifySavedPerson(displayName: string) {
501+
async verifySavedPerson(displayName: string | null | undefined) {
502+
if (!displayName) throw new Error('No display name provided')
516503
await expect(this.savedPeopleHeading).toBeVisible()
517504
await this.page.waitForTimeout(1000)
518505
const isThereSavedPeople = (await this.savedPeopleList.count()) > 0
@@ -530,3 +517,27 @@ export class PeoplePage {
530517
}
531518
}
532519
}
520+
521+
export async function getCardName(profile: Locator) {
522+
return await profile.getByTestId('people-profile-name').textContent()
523+
}
524+
525+
export async function getCardAgeGender(profile: Locator) {
526+
return await profile.getByTestId('people-profile-age-gender').textContent()
527+
}
528+
529+
export async function getCardSeekingInfo(profile: Locator) {
530+
return await profile.getByTestId('people-profile-seeking').textContent()
531+
}
532+
533+
export async function getCardHide(profile: Locator) {
534+
return await profile.getByTestId('hide-profile-button')
535+
}
536+
537+
export async function getCardStar(profile: Locator) {
538+
return await profile.getByTestId('star-profile-button')
539+
}
540+
541+
export async function getCardMessage(profile: Locator) {
542+
return await profile.getByTestId('message-profile-button')
543+
}

tests/e2e/web/specs/signIn.spec.ts

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {sleep} from 'common/util/time'
22

33
import {TEST_USER_DISPLAY_NAME} from '../../utils/seedDatabase'
44
import {expect, test} from '../fixtures/signInFixture'
5+
import {getCardAgeGender, getCardName, getCardSeekingInfo, getCardStar} from '../pages/peoplePage'
56

67
test.describe('when given valid input', () => {
78
test('should be able to sign in to an available account', async ({
@@ -17,11 +18,13 @@ test.describe('when given valid input', () => {
1718
await app.signinWithEmail(account)
1819
await app.home.clickPeopleLink()
1920
const profile = await app.people.getProfileInfo()
20-
await expect(profile.star).toBeVisible()
21-
await profile.star.click()
21+
const star = await getCardStar(profile)
22+
const name = await getCardName(profile)
23+
await expect(star).toBeVisible()
24+
await star.click()
2225
await sleep(1000)
2326
await app.people.clickSavedPeopleButton()
24-
await app.people.verifySavedPerson(profile.name)
27+
await app.people.verifySavedPerson(name)
2528
})
2629

2730
test.describe('the applied filter should', () => {
@@ -42,9 +45,10 @@ test.describe('when given valid input', () => {
4245
Number(filteredProfiles?.split(' ')[0]),
4346
)
4447

45-
const results = await app.people.getProfileInfo()
46-
if (!results) return
47-
await expect(results.seeking).toContain('Collaboration')
48+
const profile = await app.people.getProfileInfo()
49+
if (!profile) throw new Error('No profile found')
50+
const seeking = await getCardSeekingInfo(profile)
51+
await expect(seeking).toContain('Collaboration')
4852
})
4953

5054
/**
@@ -57,17 +61,19 @@ test.describe('when given valid input', () => {
5761
await app.people.setDisplayFilter({filters: {Age: true}})
5862

5963
const totalProfiles = await app.people.profileCountLocator.textContent()
60-
const profileResults = await app.people.getProfileInfo()
61-
const profileAge = parseInt(profileResults.ageGender.match(/\d+/)?.[0] ?? '0')
64+
const profile = await app.people.getProfileInfo()
65+
const ageGender = await getCardAgeGender(profile)
66+
if (!ageGender) throw new Error('Age not found')
67+
const profileAge = parseInt(ageGender.match(/\d+/)?.[0] ?? '0')
6268
const age = profileAge <= 60 ? profileAge : 60
63-
console.log(profileResults, age)
69+
console.log(profile, age)
6470

6571
await app.people.setAgeRangeFilter({min: String(age), max: String(age)})
6672

67-
const filterdProfiles = await app.people.profileCountLocator.textContent()
73+
const filteredProfiles = await app.people.profileCountLocator.textContent()
6874

69-
if (!totalProfiles || !filterdProfiles) return
70-
await expect(parseInt(totalProfiles)).not.toEqual(parseInt(filterdProfiles))
75+
if (!totalProfiles || !filteredProfiles) return
76+
await expect(parseInt(totalProfiles)).not.toEqual(parseInt(filteredProfiles))
7177
})
7278

7379
test('show profiles with the correct gender', async ({app, signedOutAccount: account}) => {
@@ -185,36 +191,41 @@ test.describe('when given valid input', () => {
185191
await app.home.clickPeopleLink()
186192
await app.people.useSearch(TEST_USER_DISPLAY_NAME)
187193
await sleep(1000)
188-
const results = await app.people.getProfileInfo()
189-
console.log(results)
190-
const hideProfileButton = await results.profile.getByRole('button', {
194+
const profile = await app.people.getProfileInfo()
195+
if (!profile) throw new Error('Profile not found')
196+
const name = await getCardName(profile)
197+
console.log(profile)
198+
const hideProfileButton = profile.getByRole('button', {
191199
name: 'Hide this profile',
192200
})
193201
await expect(hideProfileButton).toBeVisible()
194202
await hideProfileButton.click()
195203
await expect(
196-
app.page.getByText(`You won't see ${results.name} in your search results anymore.`),
204+
app.page.getByText(`You won't see ${name} in your search results anymore.`),
197205
).toBeVisible()
198206
})
199207

200208
test('should be reversible using undo', async ({app, signedOutAccount: account}) => {
201209
await app.signinWithEmail(account)
202210
await app.home.clickPeopleLink()
203-
const results = await app.people.getProfileInfo()
204-
if (!results) return
205-
const hideProfileButton = await results.profile.getByRole('button', {
211+
await app.people.useSearch(TEST_USER_DISPLAY_NAME)
212+
await sleep(1000)
213+
const profile = await app.people.getProfileInfo()
214+
if (!profile) throw new Error('Profile not found')
215+
const name = await getCardName(profile)
216+
const hideProfileButton = profile.getByRole('button', {
206217
name: 'Hide this profile',
207218
})
208219
await expect(hideProfileButton).toBeVisible()
209220
await hideProfileButton.click()
210-
const hideProfileMessage = await app.page.getByText(
211-
`You won't see ${results.name} in your search results anymore.`,
221+
const hideProfileMessage = app.page.getByText(
222+
`You won't see ${name} in your search results anymore.`,
212223
)
213224
await expect(hideProfileMessage).toBeVisible()
214225
await app.people.page.getByRole('button', {name: 'Undo'}).click()
215226
await expect(hideProfileMessage).not.toBeVisible()
216-
const profile = await app.people.page.getByRole('heading', {name: `${results.name}`})
217-
await expect(profile).toBeVisible()
227+
const undoProfile = app.people.page.getByRole('heading', {name: `${name}`})
228+
await expect(undoProfile).toBeVisible()
218229
})
219230

220231
test('should be reversible using manage hidden profiles feature in settings', async ({
@@ -223,25 +234,29 @@ test.describe('when given valid input', () => {
223234
}) => {
224235
await app.signinWithEmail(account)
225236
await app.home.clickPeopleLink()
226-
const results = await app.people.getProfileInfo()
227-
if (!results) return
228-
const hideProfileButton = await results.profile.getByRole('button', {
237+
await app.people.useSearch(TEST_USER_DISPLAY_NAME)
238+
await sleep(1000)
239+
const profile = await app.people.getProfileInfo()
240+
if (!profile) throw new Error('Profile not found')
241+
const name = await getCardName(profile)
242+
if (!name) throw new Error('Name not found')
243+
const hideProfileButton = profile.getByRole('button', {
229244
name: 'Hide this profile',
230245
})
231246
await expect(hideProfileButton).toBeVisible()
232247
await hideProfileButton.click()
233-
const hideProfileMessage = await app.page.getByText(
234-
`You won't see ${results.name} in your search results anymore.`,
248+
const hideProfileMessage = app.page.getByText(
249+
`You won't see ${name} in your search results anymore.`,
235250
)
236251
await expect(hideProfileMessage).toBeVisible()
237252
await app.home.clickSettingsLink()
238253
await app.settings.clickManageHiddenProfilesButton()
239-
await app.settings.verifyHiddenProfiles([results.name])
240-
await app.settings.unhideProfiles(results.name)
254+
await app.settings.verifyHiddenProfiles([name])
255+
await app.settings.unhideProfiles(name)
241256
await app.settings.clickCloseButton()
242257
await app.home.clickPeopleLink()
243-
const profile = await app.people.page.getByRole('heading', {name: `${results.name}`})
244-
await expect(profile).toBeVisible()
258+
const undoProfile = app.people.page.getByRole('heading', {name: `${name}`})
259+
await expect(undoProfile).toBeVisible()
245260
})
246261
})
247262

@@ -252,7 +267,7 @@ test.describe('when given valid input', () => {
252267
signedInAccount: sender,
253268
signedOutAccount: receiver,
254269
}) => {
255-
const receiverApp = await app.contextManager.createContext()
270+
const receiverApp = await app.contextManager!.createContext()
256271
await receiverApp.signinWithEmail(receiver)
257272

258273
await app.home.clickMessagesLink()
@@ -269,7 +284,7 @@ test.describe('when given valid input', () => {
269284
signedInAccount: sender,
270285
signedOutAccount: receiver,
271286
}) => {
272-
const receiverApp = await app.contextManager.createContext()
287+
const receiverApp = await app.contextManager!.createContext()
273288
await receiverApp.signinWithEmail(receiver)
274289

275290
// To pass the min character limit for message intro (250 chars)

0 commit comments

Comments
 (0)