@@ -8,7 +8,7 @@ import { expect } from '@playwright/test';
88import { denormalizeName } from '@/lib/utils' ;
99
1010import { test } from '../helpers/fixtures' ;
11- import { connectWallet , createWallet , requestFaucetTokens } from '../utils' ;
11+ import { connectWallet , createWallet , generateRandomName , requestFaucetTokens } from '../utils' ;
1212
1313test . 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 : / ^ A p p r o v e $ / i } ) ;
144+ await approveBtn . click ( ) ;
145+
146+ await walletPopup . waitForEvent ( 'close' , { timeout : 10_000 } ) ;
147+ await expect ( page . getByText ( / S u c c e s s f u l l y r e g i s t e r e d n a m e / i) ) . toBeVisible ( {
148+ timeout : 5_000 ,
149+ } ) ;
150+ } ) ;
104151} ) ;
0 commit comments