Skip to content

Commit

Permalink
simplify e2e tests dealing with durationType date
Browse files Browse the repository at this point in the history
  • Loading branch information
storywithoutend committed Sep 3, 2024
1 parent bc5960b commit 43b68f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 59 deletions.
24 changes: 3 additions & 21 deletions e2e/specs/stateless/extendNames.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,19 +359,10 @@ test('should be able to extend a name by a month', async ({

await test.step('should set and render a date properly', async () => {
const expiryTimestamp = await profilePage.getExpiryTimestamp()
const expiryTime = (await profilePage.getExpiryTimestamp()) / 1000
const expiryTime = expiryTimestamp / 1000
const calendar = page.getByTestId('calendar')
const monthLater = await page.evaluate((ts) => {
const expiryDate = new Date(ts)
// Get the new month's last day
const getEndDayOfMonth = new Date(
expiryDate.getFullYear(),
(expiryDate.getMonth() + 2) % 12,
0,
).getDate()
if (expiryDate.getDate() > getEndDayOfMonth) {
expiryDate.setDate(getEndDayOfMonth)
}
expiryDate.setMonth(expiryDate.getMonth() + 1)
return expiryDate
}, expiryTimestamp)
Expand All @@ -386,7 +377,7 @@ test('should be able to extend a name by a month', async ({
await expect(extendNamesModal.getInvoiceExtensionFee).toContainText('0.0003')
await expect(extendNamesModal.getInvoiceTransactionFee).toContainText('0.0001')
await expect(extendNamesModal.getInvoiceTotal).toContainText('0.0004')
await expect(page.getByText('1 month extension', { exact: true })).toBeVisible()
await expect(page.getByText(/1 month .* extension/)).toBeVisible()
})

await test.step('should extend', async () => {
Expand Down Expand Up @@ -518,15 +509,6 @@ test('should be able to extend a name in grace period by a month', async ({
const calendar = page.getByTestId('calendar')
const monthLater = await page.evaluate((ts) => {
const expiryDate = new Date(ts)
// Get the new month's last day
const getEndDayOfMonth = new Date(
expiryDate.getFullYear(),
(expiryDate.getMonth() + 2) % 12,
0,
).getDate()
if (expiryDate.getDate() > getEndDayOfMonth) {
expiryDate.setDate(getEndDayOfMonth)
}
expiryDate.setMonth(expiryDate.getMonth() + 1)
return expiryDate
}, expiryTimestamp)
Expand All @@ -541,7 +523,7 @@ test('should be able to extend a name in grace period by a month', async ({
await expect(extendNamesModal.getInvoiceExtensionFee).toContainText('0.0003')
await expect(extendNamesModal.getInvoiceTransactionFee).toContainText('0.0001')
await expect(extendNamesModal.getInvoiceTotal).toContainText('0.0004')
await expect(page.getByText('1 month extension', { exact: true })).toBeVisible()
await expect(page.getByText(/1 month .* extension/)).toBeVisible()
})

await test.step('should extend', async () => {
Expand Down
40 changes: 2 additions & 38 deletions e2e/specs/stateless/registerName.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,6 @@ test('should allow registering with a specific date', async ({ page, login, make
const twoYearsAndHalfLater = await page.evaluate((timestamp) => {
const _date = new Date(timestamp)
_date.setFullYear(_date.getFullYear() + 2)
// Get the new month's last day
const getEndDayOfMonth = new Date(
_date.getFullYear(),
(_date.getMonth() + 7) % 12,
0,
).getDate()
if (_date.getDate() > getEndDayOfMonth) {
_date.setDate(getEndDayOfMonth)
}
_date.setMonth(_date.getMonth() + 6)
return _date
}, browserTime * 1000)
Expand Down Expand Up @@ -381,15 +372,6 @@ test('should allow registering a premium name with a specific date', async ({
const twoYearsAndHalfLater = await page.evaluate((timestamp) => {
const _date = new Date(timestamp)
_date.setFullYear(_date.getFullYear() + 2)
// Get the new month's last day
const getEndDayOfMonth = new Date(
_date.getFullYear(),
(_date.getMonth() + 7) % 12,
0,
).getDate()
if (_date.getDate() > getEndDayOfMonth) {
_date.setDate(getEndDayOfMonth)
}
_date.setMonth(_date.getMonth() + 6)
return _date
}, browserTime * 1000)
Expand Down Expand Up @@ -460,15 +442,6 @@ test('should allow registering a premium name for two months', async ({
await test.step('should set a date', async () => {
const twoMonthsLater = await page.evaluate((timestamp) => {
const _date = new Date(timestamp)
// Get the new month's last day
const getEndDayOfMonth = new Date(
_date.getFullYear(),
(_date.getMonth() + 3) % 12,
0,
).getDate()
if (_date.getDate() > getEndDayOfMonth) {
_date.setDate(getEndDayOfMonth)
}
_date.setMonth(_date.getMonth() + 2)
return _date
}, browserTime * 1000)
Expand All @@ -477,7 +450,7 @@ test('should allow registering a premium name for two months', async ({

await expect(page.getByTestId('calendar-date')).toHaveValue(dateToDateInput(twoMonthsLater))

expect(page.getByText('2 months registration', { exact: true })).toBeVisible()
expect(page.getByText(/2 months .* registration/)).toBeVisible()
})

await page.getByTestId('payment-choice-ethereum').click()
Expand Down Expand Up @@ -620,23 +593,14 @@ test('should allow normal registration for a month', async ({
await test.step('should set a date', async () => {
const oneMonthLater = await page.evaluate((timestamp) => {
const _date = new Date(timestamp)
// Get the new month's last day
const getEndDayOfMonth = new Date(
_date.getFullYear(),
(_date.getMonth() + 2) % 12,
0,
).getDate()
if (_date.getDate() > getEndDayOfMonth) {
_date.setDate(getEndDayOfMonth)
}
_date.setMonth(_date.getMonth() + 1)
return _date
}, browserTime * 1000)

await calendar.fill(dateToDateInput(oneMonthLater))

await expect(page.getByTestId('calendar-date')).toHaveValue(dateToDateInput(oneMonthLater))
await expect(page.getByText('1 month registration', { exact: true })).toBeVisible()
await expect(page.getByText(/1 month .* registration/)).toBeVisible()
})

// should have payment choice ethereum checked and show primary name setting as checked
Expand Down

0 comments on commit 43b68f0

Please sign in to comment.