Skip to content

Commit

Permalink
Merge branch 'refactor/move-modal-animation-to-css' into refactor/con…
Browse files Browse the repository at this point in the history
…vert-to-swaps-naming-changes
  • Loading branch information
enesozturk authored Apr 23, 2024
2 parents e467e52 + 3c470fc commit ca982fc
Show file tree
Hide file tree
Showing 13 changed files with 562 additions and 444 deletions.
3 changes: 2 additions & 1 deletion Dockerfile.canary
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM node:20-bookworm
RUN apt update && apt install -y awscli

WORKDIR /src

Expand All @@ -12,4 +13,4 @@ RUN npm run playwright:install

ENV TIMING_LOGS=true

CMD ["npm", "run", "playwright:test:canary"]
CMD ["bash", "./docker-canary.sh"]
7 changes: 7 additions & 0 deletions apps/laboratory/docker-canary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Not adding `set -e` so that S3 upload happens regardless

npm run playwright:test:canary

destination="s3://$TEST_RESULTS_BUCKET/web3modal-canary/$(date --iso-8601=seconds)/test-results/"
echo "Uploading test results to $destination"
aws s3 cp ./test-results/ $destination --recursive
4 changes: 2 additions & 2 deletions apps/laboratory/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export default defineConfig<ModalFixture>({
/* Take a screenshot when the test fails */
screenshot: 'only-on-failure',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
/* Collect trace regardless so we can debug latency regressions. See https://playwright.dev/docs/trace-viewer */
trace: 'on',

video: 'retain-on-failure'
},
Expand Down
9 changes: 9 additions & 0 deletions apps/laboratory/tests/email.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ testMEmail('it should disconnect correctly', async ({ modalPage, modalValidator
await modalPage.disconnect()
await modalValidator.expectDisconnected()
})

testMEmail('it should update email', async ({ modalPage }) => {
const mailsacApiKey = process.env['MAILSAC_API_KEY']
if (!mailsacApiKey) {
throw new Error('MAILSAC_API_KEY is not set')
}

await modalPage.updateEmail(mailsacApiKey)
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import { ModalWalletPage } from '../pages/ModalWalletPage'
import { ModalWalletValidator } from '../validators/ModalWalletValidator'
import type { ModalPage } from '../pages/ModalPage'

const mailsacApiKey = process.env['MAILSAC_API_KEY']
if (!mailsacApiKey) {
throw new Error('MAILSAC_API_KEY is not set')
}

// Test Modal + Smart Account
export const testModalSmartAccount = base.extend<ModalFixture & { slowModalPage: ModalPage }>({
library: ['wagmi', { option: true }],
Expand All @@ -18,6 +13,10 @@ export const testModalSmartAccount = base.extend<ModalFixture & { slowModalPage:
const modalPage = new ModalWalletPage(page, library)
await modalPage.load()

const mailsacApiKey = process.env['MAILSAC_API_KEY']
if (!mailsacApiKey) {
throw new Error('MAILSAC_API_KEY is not set')
}
const email = new Email(mailsacApiKey)
const tempEmail = email.getEmailAddressToUse(testInfo.parallelIndex)

Expand Down
69 changes: 61 additions & 8 deletions apps/laboratory/tests/shared/pages/ModalPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class ModalPage {

private readonly connectButton: Locator
private readonly url: string
private emailAddress = ''

constructor(
public readonly page: Page,
Expand Down Expand Up @@ -61,6 +62,8 @@ export class ModalPage {
): Promise<void> {
await this.load()

this.emailAddress = emailAddress

const email = new Email(mailsacApiKey)

await email.deleteAllMessages(emailAddress)
Expand Down Expand Up @@ -90,9 +93,11 @@ export class ModalPage {
otp = email.getOtpCodeFromBody(emailBody)
}
}
if (otp.replace(' ', '').length !== 6) {

if (otp === '') {
otp = email.getOtpCodeFromBody(emailBody)
}

await this.enterOTP(otp)
}

Expand All @@ -114,16 +119,15 @@ export class ModalPage {
})
}

async enterOTP(otp: string) {
await expect(this.page.getByText('Confirm Email')).toBeVisible({
async enterOTP(otp: string, headerTitle = 'Confirm Email') {
await expect(this.page.getByText(headerTitle)).toBeVisible({
timeout: 10_000
})
await expect(this.page.getByText('Enter the code we sent')).toBeVisible({
timeout: 10_000
})

const splitted = otp.split('')
// Remove empy space in OTP code 111 111
splitted.splice(3, 1)

// eslint-disable-next-line no-plusplus
for (let i = 0; i < splitted.length; i++) {
Expand All @@ -143,18 +147,18 @@ export class ModalPage {
await input.fill(digit)
}

await expect(this.page.getByText('Confirm Email')).not.toBeVisible()
await expect(this.page.getByText(headerTitle)).not.toBeVisible()
}

async disconnect() {
const accountBtn = this.page.getByTestId('account-button')
await expect(accountBtn, 'Account button should be visible').toBeVisible()
await expect(accountBtn, 'Account button should be enabled').toBeEnabled()
await accountBtn.click({ force: true })
await accountBtn.click()
const disconnectBtn = this.page.getByTestId('disconnect-button')
await expect(disconnectBtn, 'Disconnect button should be visible').toBeVisible()
await expect(disconnectBtn, 'Disconnect button should be enabled').toBeEnabled()
await disconnectBtn.click({ force: true })
await disconnectBtn.click()
}

async sign() {
Expand Down Expand Up @@ -207,9 +211,14 @@ export class ModalPage {
}

async switchNetwork(network: string) {
const switchNetworkButton = this.page.getByTestId('w3m-account-select-network')
await this.page.getByTestId('account-button').click()
await this.page.getByTestId('w3m-account-select-network').click()
await this.page.getByTestId(`w3m-network-switch-${network}`).click()
await expect(switchNetworkButton, `Switched network should include ${network}`).toContainText(
network,
{ timeout: 5000 }
)
}

async clickWalletDeeplink() {
Expand All @@ -227,4 +236,48 @@ export class ModalPage {
// Wait for the modal fade out animation
await this.page.waitForTimeout(300)
}

async updateEmail(mailsacApiKey: string) {
const email = new Email(mailsacApiKey)
const newEmailAddress = email.getEmailAddressToUse(1)

await this.page.getByTestId('account-button').click()
await this.page.getByTestId('w3m-account-email-update').click()
await this.page.getByTestId('wui-email-input').locator('input').focus()
await this.page.getByTestId('wui-email-input').locator('input').fill(newEmailAddress)

// Clear messages before putting new email
await email.deleteAllMessages(this.emailAddress)
await this.page.getByTestId('wui-email-input').locator('input').press('Enter')

// Wait until the next screen appears
await expect(this.page.getByText('Enter the code we sent')).toBeVisible({
timeout: 10_000
})
const confirmCurrentEmail = await this.page.getByText('Confirm Current Email').isVisible()
if (confirmCurrentEmail) {
await this.updateOtpFlow(this.emailAddress, mailsacApiKey, 'Confirm Current Email')
}

await this.updateOtpFlow(newEmailAddress, mailsacApiKey, 'Confirm New Email')

expect(
this.page.getByTestId('w3m-account-email-update'),
`Expected to go to the account screen after the update`
).toBeVisible()
}

async updateOtpFlow(emailAddress: string, mailsacApiKey: string, headerTitle: string) {
const email = new Email(mailsacApiKey)

const messageId = await email.getLatestMessageId(emailAddress)

if (!messageId) {
throw new Error('No messageId found')
}
const emailBody = await email.getEmailBody(emailAddress, messageId)
const otp = email.getOtpCodeFromBody(emailBody)

await this.enterOTP(otp, headerTitle)
}
}
13 changes: 9 additions & 4 deletions apps/laboratory/tests/shared/pages/ModalWalletPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,27 @@ export class ModalWalletPage extends ModalPage {
}

override async switchNetwork(network: string) {
const switchNetworkButton = this.page.getByTestId('account-switch-network-button')
await this.page.getByTestId('account-switch-network-button').click()
await this.page.getByTestId(`w3m-network-switch-${network}`).click()
await this.page.waitForTimeout(2000)
await expect(switchNetworkButton, `Switched network should include ${network}`).toContainText(
network,
{ timeout: 5000 }
)
}

async togglePreferredAccountType() {
await this.page.getByTestId('account-toggle-preferred-account-type').click()
await this.page.waitForTimeout(2500)
await this.page.waitForTimeout(1000)
}

override async disconnect(): Promise<void> {
this.openSettings()
const disconnectBtn = this.page.getByTestId('disconnect-button')
await expect(disconnectBtn, 'Disconnect button should be visible').toBeVisible()
await expect(disconnectBtn, 'Disconnect button should be enabled').toBeEnabled()
await disconnectBtn.click({ force: true })
await disconnectBtn.click()
await this.page.getByTestId('connect-button').waitFor({ state: 'visible', timeout: 5000 })
await this.page.waitForTimeout(2000)
}

async getAddress(): Promise<string> {
Expand Down
3 changes: 2 additions & 1 deletion apps/laboratory/tests/shared/utils/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export class Email {
getOtpCodeFromBody(body: string): string {
const match = body.match(OTP_CODE_REGEX)
if (match) {
return match[0]
// Remove empty space in OTP code 111 111
return match[0].replace(' ', '')
}

throw new Error(`No code found in email: ${body}`)
Expand Down
1 change: 0 additions & 1 deletion apps/laboratory/tests/smart-account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ testModalSmartAccount(
await walletModalPage.openSettings()
await walletModalPage.togglePreferredAccountType()
await walletModalPage.disconnect()
await walletModalPage.page.waitForTimeout(1500)

await walletModalPage.emailFlow(
email.getEmailAddressToUse(parallelIndex, NOT_ENABLED_DOMAIN),
Expand Down
Loading

0 comments on commit ca982fc

Please sign in to comment.