You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							164 lines
						
					
					
						
							7.8 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							164 lines
						
					
					
						
							7.8 KiB
						
					
					
				
								import { test, expect, Page } from '@playwright/test';
							 | 
						|
								import { importUser, importUserFromAccount } from './testUtils';
							 | 
						|
								
							 | 
						|
								test('Record an offer', async ({ page }) => {
							 | 
						|
								  test.setTimeout(60000);
							 | 
						|
								
							 | 
						|
								  // Generate a random string of 3 characters, skipping the "0." at the beginning
							 | 
						|
								  const randomString = Math.random().toString(36).substring(2, 5);
							 | 
						|
								  // Standard title prefix
							 | 
						|
								  const description = `Offering of ${randomString}`;
							 | 
						|
								  const updatedDescription = `Updated ${description}`;
							 | 
						|
								  const randomNonZeroNumber = Math.floor(Math.random() * 998) + 1;
							 | 
						|
								
							 | 
						|
								  // Switch to user 0
							 | 
						|
								  // await importUser(page);
							 | 
						|
								  // Become User Zero
							 | 
						|
								  await importUserFromAccount(page, "00");
							 | 
						|
								  // Select a project
							 | 
						|
								  await page.goto('./discover');
							 | 
						|
								  await page.getByTestId('closeOnboardingAndFinish').click();
							 | 
						|
								  await page.locator('ul#listDiscoverResults li:nth-child(1)').click();
							 | 
						|
								  // Record an offer
							 | 
						|
								  await page.locator('button', { hasText: 'Edit' }).isVisible(); // since the 'edit' takes longer to show, wait for that (lest the click miss)
							 | 
						|
								  await page.getByTestId('offerButton').click();
							 | 
						|
								  await page.getByTestId('inputDescription').fill(description);
							 | 
						|
								  await page.getByTestId('inputOfferAmount').locator('input').fill(randomNonZeroNumber.toString());
							 | 
						|
								  expect(page.getByRole('button', { name: 'Sign & Send' }));
							 | 
						|
								  await page.getByRole('button', { name: 'Sign & Send' }).click();
							 | 
						|
								  await page.getByRole('alert').filter({ hasText: 'Success' }).getByRole('button').click(); // dismiss info alert
							 | 
						|
								  // go to the offer and check the values
							 | 
						|
								  await page.goto('./projects');
							 | 
						|
								  await page.getByRole('link', { name: 'Offers', exact: true }).click();
							 | 
						|
								  await page.locator('li').filter({ hasText: description }).locator('a').first().click();
							 | 
						|
								  await expect(page.getByRole('heading', { name: 'Verifiable Claim Details' })).toBeVisible();
							 | 
						|
								  await expect(page.getByText(description, { exact: true })).toBeVisible();
							 | 
						|
								  await expect(page.getByText('Offered to a bigger plan')).toBeVisible();
							 | 
						|
								  const serverPagePromise = page.waitForEvent('popup');
							 | 
						|
								  // expand the Details section to see the extended details
							 | 
						|
								  await page.getByRole('heading', { name: 'Details', exact: true }).click();
							 | 
						|
								  await page.getByRole('link', { name: 'View on the Public Server' }).click();
							 | 
						|
								  const serverPage = await serverPagePromise;
							 | 
						|
								  await expect(serverPage.getByText(description)).toBeVisible();
							 | 
						|
								  await expect(serverPage.getByText('did:none:HIDDEN')).toBeVisible();
							 | 
						|
								  // Now update that offer
							 | 
						|
								
							 | 
						|
								  // find the edit page and check the old values again
							 | 
						|
								  await page.goto('./projects');
							 | 
						|
								  await page.getByRole('link', { name: 'Offers', exact: true }).click();
							 | 
						|
								  await page.locator('li').filter({ hasText: description }).locator('a').first().click();
							 | 
						|
								  await page.getByTestId('editClaimButton').click();
							 | 
						|
								  await page.locator('heading', { hasText: 'What is offered' }).isVisible();
							 | 
						|
								  const itemDesc = await page.getByTestId('itemDescription');
							 | 
						|
								  await expect(itemDesc).toHaveValue(description);
							 | 
						|
								  const amount = await page.getByTestId('inputOfferAmount');
							 | 
						|
								  await expect(amount).toHaveValue(randomNonZeroNumber.toString());
							 | 
						|
								  // update the values
							 | 
						|
								  await itemDesc.fill(updatedDescription);
							 | 
						|
								  await amount.fill(String(randomNonZeroNumber + 1));
							 | 
						|
								  await page.getByRole('button', { name: 'Sign & Send' }).click();
							 | 
						|
								  await page.getByRole('alert').filter({ hasText: 'Success' }).getByRole('button').click(); // dismiss info alert
							 | 
						|
								  // go to the offer claim again and check the updated values
							 | 
						|
								  await page.goto('./projects');
							 | 
						|
								  await page.getByRole('link', { name: 'Offers', exact: true }).click();
							 | 
						|
								  await page.locator('li').filter({ hasText: description }).locator('a').first().click();
							 | 
						|
								  const newItemDesc = page.getByTestId('description');
							 | 
						|
								  await expect(newItemDesc).toHaveText(updatedDescription);
							 | 
						|
								  // go to edit page
							 | 
						|
								  await page.getByTestId('editClaimButton').click();
							 | 
						|
								  const newAmount = page.getByTestId('inputOfferAmount');
							 | 
						|
								  await expect(newAmount).toHaveValue((randomNonZeroNumber + 1).toString());
							 | 
						|
								  // go to the home page and check that the offer is shown as new
							 | 
						|
								  await page.goto('./');
							 | 
						|
								  const offerNumElem = page.getByTestId('newOffersToUserProjectsActivityNumber');
							 | 
						|
								  // extract the number and check that it's greater than 0 or "50+"
							 | 
						|
								  const offerNumText = await offerNumElem.textContent();
							 | 
						|
								  if (offerNumText === null) {
							 | 
						|
								    throw new Error('Expected Activity Number greater than 0 but got null.');
							 | 
						|
								  } else if (offerNumText === '50+') {
							 | 
						|
								    // we're OK
							 | 
						|
								  } else if (parseInt(offerNumText) > 0) {
							 | 
						|
								    // we're OK
							 | 
						|
								  } else {
							 | 
						|
								    throw new Error(`Expected Activity Number of greater than 0 but got ${offerNumText}.`);
							 | 
						|
								  }
							 | 
						|
								
							 | 
						|
								  // click on the number of new offers to go to the list page
							 | 
						|
								  await offerNumElem.click();
							 | 
						|
								  await expect(page.getByText('New Offers To Your Projects', { exact: true })).toBeVisible();
							 | 
						|
								  // get the icon child of the showOffersToUserProjects
							 | 
						|
								  await page.getByTestId('showOffersToUserProjects').locator('div > svg.fa-chevron-right').click();
							 | 
						|
								  await expect(page.getByText(description)).toBeVisible();
							 | 
						|
								});
							 | 
						|
								
							 | 
						|
								test('Affirm delivery of an offer', async ({ page }) => {
							 | 
						|
								  // go to the home page and check that the offer is shown as new
							 | 
						|
								  // await importUser(page);
							 | 
						|
								
							 | 
						|
								  await importUserFromAccount(page, "00");
							 | 
						|
								  await page.goto('./');
							 | 
						|
								  await page.getByTestId('closeOnboardingAndFinish').click();
							 | 
						|
								  // Wait for dialog to be hidden or removed - try multiple approaches
							 | 
						|
								  try {
							 | 
						|
								    // First try: wait for overlay to disappear
							 | 
						|
								    await page.waitForFunction(() => {
							 | 
						|
								      return document.querySelector('.dialog-overlay') === null;
							 | 
						|
								    }, { timeout: 5000 });
							 | 
						|
								  } catch (error) {
							 | 
						|
								    // Check if page is still available before second attempt
							 | 
						|
								    try {
							 | 
						|
								      await page.waitForLoadState('domcontentloaded', { timeout: 2000 });
							 | 
						|
								      // Second try: wait for dialog to be hidden
							 | 
						|
								      await page.waitForFunction(() => {
							 | 
						|
								        const overlay = document.querySelector('.dialog-overlay') as HTMLElement;
							 | 
						|
								        return overlay && overlay.style.display === 'none';
							 | 
						|
								      }, { timeout: 5000 });
							 | 
						|
								    } catch (pageError) {
							 | 
						|
								      // If page is closed, just continue - the dialog is gone anyway
							 | 
						|
								      console.log('Page closed during dialog wait, continuing...');
							 | 
						|
								    }
							 | 
						|
								  }
							 | 
						|
								  // Check if page is still available before proceeding
							 | 
						|
								  try {
							 | 
						|
								    await page.waitForLoadState('domcontentloaded', { timeout: 2000 });
							 | 
						|
								  } catch (error) {
							 | 
						|
								    // If page is closed, we can't continue - this is a real error
							 | 
						|
								    throw new Error('Page closed unexpectedly during test');
							 | 
						|
								  }
							 | 
						|
								  // Force close any remaining dialog overlay
							 | 
						|
								  try {
							 | 
						|
								    await page.evaluate(() => {
							 | 
						|
								      const overlay = document.querySelector('.dialog-overlay') as HTMLElement;
							 | 
						|
								      if (overlay) {
							 | 
						|
								        overlay.style.display = 'none';
							 | 
						|
								        overlay.remove();
							 | 
						|
								      }
							 | 
						|
								    });
							 | 
						|
								  } catch (error) {
							 | 
						|
								    console.log('Could not force close dialog, continuing...');
							 | 
						|
								  }
							 | 
						|
								  const offerNumElem = page.getByTestId('newOffersToUserProjectsActivityNumber');
							 | 
						|
								  await expect(offerNumElem).toBeVisible();
							 | 
						|
								
							 | 
						|
								  // click on the number of new offers to go to the list page
							 | 
						|
								  await offerNumElem.click();
							 | 
						|
								  
							 | 
						|
								  // get the link that comes after the showOffersToUserProjects and click it
							 | 
						|
								  await page.getByTestId('showOffersToUserProjects').locator('a').click();
							 | 
						|
								
							 | 
						|
								  // get the first item of the list and click on the icon with file-lines
							 | 
						|
								  const firstItem = page.getByTestId('listRecentOffersToUserProjects').locator('li').first();
							 | 
						|
								  await expect(firstItem).toBeVisible();
							 | 
						|
								  await firstItem.locator('svg.fa-file-lines').click();
							 | 
						|
								  await expect(page.getByText('Verifiable Claim Details', { exact: true })).toBeVisible();
							 | 
						|
								
							 | 
						|
								  // click on the 'Affirm Delivery' button
							 | 
						|
								  await page.getByRole('button', { name: 'Affirm Delivery' }).click();
							 | 
						|
								  // fill our offer info and submit
							 | 
						|
								  await page.getByPlaceholder('What was given').fill('Whatever the offer says');
							 | 
						|
								  await page.getByRole('spinbutton').fill('2');
							 | 
						|
								  await page.getByRole('button', { name: 'Sign & Send' }).click();
							 | 
						|
								  await expect(page.getByText('That gift was recorded.')).toBeVisible();
							 | 
						|
								  await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert
							 | 
						|
								});
							 | 
						|
								
							 | 
						|
								
							 |