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.
		
		
		
		
		
			
		
			
				
					
					
						
							144 lines
						
					
					
						
							5.3 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							144 lines
						
					
					
						
							5.3 KiB
						
					
					
				| /** | |
|  * @file Gift Recording Test Suite | |
|  * @description Tests TimeSafari's core gift recording functionality, ensuring proper creation, | |
|  * validation, and verification of gift records | |
|  *  | |
|  * This test verifies: | |
|  * 1. Gift Creation | |
|  *    - Random gift title generation | |
|  *    - Random non-zero amount assignment | |
|  *    - Proper recording and signing | |
|  *  | |
|  * 2. Gift Verification | |
|  *    - Gift appears in home view | |
|  *    - Details match input data | |
|  *    - Verifiable claim details accessible | |
|  *  | |
|  * 3. Public Verification | |
|  *    - Gift viewable on public server | |
|  *    - Claim details properly exposed | |
|  *  | |
|  * Test Flow: | |
|  * 1. Data Generation | |
|  *    - Generate random 4-char string for unique gift ID | |
|  *    - Generate random amount (1-99) | |
|  *    - Combine with standard "Gift" prefix | |
|  *  | |
|  * 2. Gift Recording | |
|  *    - Import User 00 (test account) | |
|  *    - Navigate to home | |
|  *    - Close onboarding dialog | |
|  *    - Select recipient | |
|  *    - Fill gift details | |
|  *    - Sign and submit | |
|  *  | |
|  * 3. Verification | |
|  *    - Check success notification | |
|  *    - Refresh home view | |
|  *    - Locate gift in list | |
|  *    - Verify gift details | |
|  *    - Check public server view | |
|  *  | |
|  * Test Data: | |
|  * - Gift Title: "Gift [4-char-random]" | |
|  * - Amount: Random 1-99 | |
|  * - Recipient: "Unnamed/Unknown" | |
|  *  | |
|  * Key Selectors: | |
|  * - Gift title: '[data-testid="giftTitle"]' | |
|  * - Amount input: 'input[type="number"]' | |
|  * - Submit button: 'button[name="Sign & Send"]' | |
|  * - Success alert: 'div[role="alert"]' | |
|  * - Details section: 'h2[name="Details"]' | |
|  *  | |
|  * Alert Handling: | |
|  * - Closes onboarding dialog | |
|  * - Verifies success message | |
|  * - Dismisses info alerts | |
|  *  | |
|  * State Requirements: | |
|  * - Clean database state | |
|  * - User 00 imported | |
|  * - Available API rate limits | |
|  *  | |
|  * Related Files: | |
|  * - Gift recording view: src/views/RecordGiftView.vue | |
|  * - JWT creation: sw_scripts/safari-notifications.js | |
|  * - Endorser API: src/libs/endorserServer.ts | |
|  *  | |
|  * @see Documentation in usage-guide.md for gift recording workflows | |
|  * @requires @playwright/test | |
|  * @requires ./testUtils - For user management utilities | |
|  *  | |
|  * @example Basic gift recording | |
|  * ```typescript | |
|  * await page.getByPlaceholder('What was given').fill('Gift abc123'); | |
|  * await page.getByRole('spinbutton').fill('42'); | |
|  * await page.getByRole('button', { name: 'Sign & Send' }).click(); | |
|  * await expect(page.getByText('That gift was recorded.')).toBeVisible(); | |
|  * ``` | |
|  */ | |
| import { test, expect } from '@playwright/test'; | |
| import { UNNAMED_ENTITY_NAME } from '../src/constants/entities'; | |
| import { importUser, retryWaitForLoadState, retryWaitForSelector, retryClick, getNetworkIdleTimeout, getElementWaitTimeout } from './testUtils'; | |
| 
 | |
| test('Record something given', async ({ page }) => { | |
|   // Generate a random string of a few characters | |
|   const randomString = Math.random().toString(36).substring(2, 6); | |
| 
 | |
|   // Generate a random non-zero single-digit number | |
|   const randomNonZeroNumber = Math.floor(Math.random() * 99) + 1; | |
| 
 | |
|   // Standard title prefix | |
|   const standardTitle = 'Gift '; | |
| 
 | |
|   // Combine title prefix with the random string | |
|   const finalTitle = standardTitle + randomString; | |
| 
 | |
|   // Import user 00 | |
|   await importUser(page, '00'); | |
| 
 | |
|   // Record something given | |
|   await page.goto('./'); | |
|   await page.getByTestId('closeOnboardingAndFinish').click(); | |
|    | |
|   // Simple dialog handling - just wait for it to be gone | |
|   await page.waitForFunction(() => { | |
|     return !document.querySelector('.dialog-overlay'); | |
|   }, { timeout: 5000 }); | |
|    | |
|   await page.getByRole('button', { name: 'Person' }).click(); | |
|       await page.getByRole('listitem').filter({ hasText: UNNAMED_ENTITY_NAME }).locator('svg').click(); | |
|   await page.getByPlaceholder('What was given').fill(finalTitle); | |
|   await page.getByRole('spinbutton').fill(randomNonZeroNumber.toString()); | |
|   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 | |
|  | |
|   // Refresh home view and check gift | |
|   await page.goto('./'); | |
|    | |
|   // Use adaptive timeout and retry logic for load-sensitive operations | |
|   await retryWaitForLoadState(page, 'networkidle', { timeout: getNetworkIdleTimeout() }); | |
|    | |
|   // Resilient approach - verify the gift appears in activity feed | |
|   await retryWaitForLoadState(page, 'networkidle', { timeout: getNetworkIdleTimeout() }); | |
|    | |
|   // Wait for activity items and verify our gift appears | |
|   await retryWaitForSelector(page, 'ul#listLatestActivity li', { timeout: getElementWaitTimeout() }); | |
|    | |
|   // Verify the gift we just recorded appears in the activity feed | |
|   await expect(page.getByText(finalTitle, { exact: false })).toBeVisible(); | |
|    | |
|   // Click the specific gift item | |
|   const item = page.locator('li:first-child').filter({ hasText: finalTitle }); | |
|   await retryClick(page, item.locator('[data-testid="circle-info-link"]')); | |
|   await expect(page.getByRole('heading', { name: 'Verifiable Claim Details' })).toBeVisible(); | |
|   // Verify we're viewing the specific gift we recorded | |
|   await expect(page.getByText(finalTitle, { exact: false })).toBeVisible(); | |
|   const page1Promise = 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 page1 = await page1Promise; | |
| }); |