Skip to content

Commit 2d31d71

Browse files
authored
feat(dapp): add test to buy a name with different expiration (#1034)
1 parent 6cea259 commit 2d31d71

File tree

2 files changed

+89
-22
lines changed

2 files changed

+89
-22
lines changed

dapp/src/components/dialogs/PurchaseNameDialog.tsx

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export function PurchaseNameDialog({ name, open, setOpen, onCompleted }: Purchas
292292
</div>
293293
</Panel>
294294
{isRegisterWithYearsSupported ? (
295-
<div className="relative">
295+
<div data-testid="purchase-years-select" className="relative">
296296
<Select
297297
options={purchaseOptions}
298298
value={purchaseYears?.toString()}
@@ -331,29 +331,49 @@ export function PurchaseNameDialog({ name, open, setOpen, onCompleted }: Purchas
331331
<div className="flex flex-row gap-x-sm w-full">
332332
{finalPriceIota && fiatPriceResult ? (
333333
<>
334-
<DisplayStats
335-
label="Registration Expires"
336-
value={
337-
<LabelText text={expirationDate} label={`\u00A0`} /> // \u00A0 for alignment
338-
}
339-
/>
340-
<DisplayStats
341-
label="Total Due"
342-
value={
343-
<LabelText
344-
text={finalPriceIota}
345-
label={`($${fiatPriceResult} USD)`}
346-
/>
347-
}
348-
/>
334+
<div
335+
data-testid="registration-expiration"
336+
className="w-full"
337+
>
338+
<DisplayStats
339+
label="Registration Expires"
340+
value={
341+
<LabelText
342+
text={expirationDate}
343+
label={`\u00A0`}
344+
/> // \u00A0 for alignment
345+
}
346+
/>
347+
</div>
348+
<div data-testid="total-due" className="w-full">
349+
<DisplayStats
350+
label="Total Due"
351+
value={
352+
<LabelText
353+
text={finalPriceIota}
354+
label={`($${fiatPriceResult} USD)`}
355+
/>
356+
}
357+
/>
358+
</div>
349359
</>
350360
) : finalPriceIota && !fiatPriceResult ? (
351361
<>
352-
<DisplayStats
353-
label="Registration Expires"
354-
value={expirationDate}
355-
/>
356-
<DisplayStats label="Total Due" value={finalPriceIota} />
362+
<div
363+
data-testid="registration-expiration"
364+
className="w-full"
365+
>
366+
<DisplayStats
367+
label="Registration Expires"
368+
value={expirationDate}
369+
/>
370+
</div>
371+
<div data-testid="total-due" className="w-full">
372+
<DisplayStats
373+
label="Total Due"
374+
value={finalPriceIota}
375+
/>
376+
</div>
357377
</>
358378
) : (
359379
<LoadingIndicator />

dapp/tests/purchase/purchase.spec.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { expect } from '@playwright/test';
88
import { denormalizeName } from '@/lib/utils';
99

1010
import { test } from '../helpers/fixtures';
11-
import { connectWallet, createWallet, requestFaucetTokens } from '../utils';
11+
import { connectWallet, createWallet, generateRandomName, requestFaucetTokens } from '../utils';
1212

1313
test.describe.serial('Purchase Name Tests', () => {
1414
test.beforeAll(async ({ appPage, context, extensionPage, extensionName, sharedState }) => {
@@ -101,4 +101,51 @@ test.describe.serial('Purchase Name Tests', () => {
101101
const nameMessage = namePurchaseCard.getByTestId('name-purchase-card-status-message');
102102
await expect(nameMessage).toContainText('Name is already taken.');
103103
});
104+
105+
test('Buy with a different expiration time', async ({ appPage: page, context }) => {
106+
const YEARS = 5;
107+
// Name bought when initializing localnet with scripts/tests/register-name.ts
108+
const name = generateRandomName('expi');
109+
const denormalizedName = denormalizeName(name);
110+
111+
await page.getByPlaceholder('Search for your IOTA name').click();
112+
await page.getByPlaceholder('Check name availability').fill(denormalizedName);
113+
114+
const namePurchaseCard = page.getByTestId('purchase-name-card');
115+
await expect(namePurchaseCard).toContainText('@' + denormalizedName);
116+
117+
await namePurchaseCard.hover();
118+
await namePurchaseCard.getByRole('button', { name: 'Buy' }).click();
119+
120+
const initialExpirationTime = (
121+
await page.getByTestId('registration-expiration').innerText()
122+
).split('\n')[1];
123+
124+
const select = page.getByTestId('purchase-years-select');
125+
await expect(select).toContainText('1 Year');
126+
await select.click({ timeout: 5_000 });
127+
await page.getByText(`${YEARS} Years`).click({ timeout: 5_000 });
128+
129+
const expirationTime = (
130+
await page.getByTestId('registration-expiration').innerText()
131+
).split('\n')[1];
132+
133+
expect(expirationTime).not.toBe(initialExpirationTime);
134+
const expirationYears = new Date(expirationTime).getFullYear() - new Date().getFullYear();
135+
expect(expirationYears).toBe(YEARS);
136+
137+
await page.getByRole('button', { name: 'Buy' }).click();
138+
139+
const walletConfirmationPage = context.waitForEvent('page');
140+
const walletPopup = await walletConfirmationPage;
141+
142+
await walletPopup.waitForLoadState('domcontentloaded');
143+
const approveBtn = walletPopup.getByRole('button', { name: /^Approve$/i });
144+
await approveBtn.click();
145+
146+
await walletPopup.waitForEvent('close', { timeout: 10_000 });
147+
await expect(page.getByText(/Successfully registered name/i)).toBeVisible({
148+
timeout: 5_000,
149+
});
150+
});
104151
});

0 commit comments

Comments
 (0)