From 4a3b968ee216263841f233455a7ea2fd2628e2cd Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Thu, 1 Jan 2026 20:25:40 -0700 Subject: [PATCH] fix test 40 for adding contacts (though clipboard is still broken) --- src/views/ContactsView.vue | 88 +++++++++++++------------- test-playwright/40-add-contact.spec.ts | 47 ++++++++------ 2 files changed, 71 insertions(+), 64 deletions(-) diff --git a/src/views/ContactsView.vue b/src/views/ContactsView.vue index df9917b600..454b13a657 100644 --- a/src/views/ContactsView.vue +++ b/src/views/ContactsView.vue @@ -843,17 +843,14 @@ export default class ContactsView extends Vue { // Set visibility and get success message const addedMessage = await this.handleContactVisibility(newContact); + // Show success notification + this.notify.success(addedMessage); + // Clear input field this.contactInput = ""; // Handle registration prompt if needed await this.handleRegistrationPrompt(newContact); - - // Show success notification - this.notify.success(addedMessage); - - // Show export data prompt after successful contact addition - await this.showExportDataPrompt(); } catch (err) { this.handleContactAddError(err); } @@ -908,30 +905,35 @@ export default class ContactsView extends Vue { newContact.registered === true // the new contact is already registered ) { // if any of the above are true, we do not want to show the registration prompt + await this.showExportDataPrompt(); return; } - setTimeout(() => { - this.$notify( - { - group: "modal", - type: "confirm", - title: "Register", - text: "Do you want to register them?", - onCancel: async (stopAsking?: boolean) => { - await this.handleRegistrationPromptResponse(stopAsking); - }, - onNo: async (stopAsking?: boolean) => { - await this.handleRegistrationPromptResponse(stopAsking); - }, - onYes: async () => { - await this.register(newContact); - }, - promptToStopAsking: true, + this.$notify( + { + group: "modal", + type: "confirm", + title: "Register", + text: "Do you want to register them?", + onCancel: async (stopAsking?: boolean) => { + await this.handleRegistrationPromptResponse(stopAsking); + // Show export prompt after registration prompt is dismissed + await this.showExportDataPrompt(); }, - -1, - ); - }, 1000); + onNo: async (stopAsking?: boolean) => { + await this.handleRegistrationPromptResponse(stopAsking); + // Show export prompt after registration prompt is dismissed + await this.showExportDataPrompt(); + }, + onYes: async () => { + await this.register(newContact); + // Show export prompt after registration completes + await this.showExportDataPrompt(); + }, + promptToStopAsking: true, + }, + -1, + ); } /** @@ -1338,25 +1340,23 @@ export default class ContactsView extends Vue { * Prompts user to export their contact data as a backup */ private async showExportDataPrompt(): Promise { - setTimeout(() => { - this.$notify( - { - group: "modal", - type: "confirm", - title: NOTIFY_EXPORT_DATA_PROMPT.title, - text: NOTIFY_EXPORT_DATA_PROMPT.message, - onYes: async () => { - await this.exportContactData(); - }, - yesText: "Export Data", - onNo: async () => { - // User chose not to export - no action needed - }, - noText: "Not Now", + this.$notify( + { + group: "modal", + type: "confirm", + title: NOTIFY_EXPORT_DATA_PROMPT.title, + text: NOTIFY_EXPORT_DATA_PROMPT.message, + onYes: async () => { + await this.exportContactData(); }, - -1, - ); - }, 1000); // Small delay to ensure success notification is shown first + yesText: "Export Data", + onNo: async () => { + // User chose not to export - no action needed + }, + noText: "Not Yet", + }, + -1, + ); } /** diff --git a/test-playwright/40-add-contact.spec.ts b/test-playwright/40-add-contact.spec.ts index 34780af29e..770964ab97 100644 --- a/test-playwright/40-add-contact.spec.ts +++ b/test-playwright/40-add-contact.spec.ts @@ -92,12 +92,13 @@ test('Add contact, record gift, confirm gift', async ({ page }) => { await page.goto('./contacts'); await page.getByPlaceholder('URL or DID, Name, Public Key').fill('did:ethr:0x0000694B58C2cC69658993A90D3840C560f2F51F, ' + userName); await page.locator('button > svg.fa-plus').click(); - // Commenting the following lines because user 00 is already registered - // await expect(page.locator('div[role="alert"] span:has-text("No")')).toBeVisible(); - // await page.locator('div[role="alert"] button:has-text("No")').click(); // don't register - await expect(page.locator('div[role="alert"] span:has-text("Success")')).toBeVisible(); + await expect(page.getByRole('alert').filter({ hasText: 'Success' })).toBeVisible(); await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert + await expect(page.locator('div[role="alert"] span:has-text("No")')).toBeVisible(); // register prompt + await page.getByRole('button', { name: 'No', exact: true }).click(); // don't register await expect(page.locator('div[role="alert"] button > svg.fa-xmark')).toBeHidden(); // ensure alert is gone + await expect(page.getByRole('button', { name: 'No, Not Yet', exact: true })).toBeVisible(); // backup prompt + await page.getByRole('button', { name: 'No, Not Yet', exact: true }).click(); // don't backup contacts // Verify added contact await expect(page.locator('li.border-b')).toContainText(userName); @@ -118,10 +119,10 @@ test('Add contact, record gift, confirm gift', async ({ page }) => { await page.goto('./'); await page.getByTestId('closeOnboardingAndFinish').click(); await page.getByRole('button', { name: 'Thank' }).click(); - await expect(page.locator('#sectionGiftedGiver').getByRole('listitem').filter({ hasText: contactName })).toBeVisible(); + await expect(page.locator('#sectionGiftedGiver').getByRole('listitem').filter({ hasText: contactName }).first()).toBeVisible(); // Record something given by new contact - await page.locator('#sectionGiftedGiver').getByRole('listitem').filter({ hasText: contactName }).click(); + await page.locator('#sectionGiftedGiver').getByRole('listitem').filter({ hasText: contactName }).first().click(); await page.getByPlaceholder('What was given').fill(finalTitle); await page.getByRole('spinbutton').fill(randomNonZeroNumber.toString()); await page.getByRole('button', { name: 'Sign & Send' }).click(); @@ -156,7 +157,7 @@ test('Add contact, record gift, confirm gift', async ({ page }) => { // Go to home view and look for gift await page.goto('./'); - // await page.getByTestId('closeOnboardingAndFinish').click(); + await page.getByTestId('closeOnboardingAndFinish').click(); const giftLink = page.locator('li:first-child').filter({ hasText: finalTitle }).locator('[data-testid="circle-info-link"]'); await expect(giftLink).toBeVisible(); await giftLink.click(); @@ -179,11 +180,13 @@ test('Without being registered, add contacts without registration', async ({ pag await page.goto('./contacts'); await page.getByPlaceholder('URL or DID, Name, Public Key').fill('did:ethr:0x111d15564f824D56C7a07b913aA7aDd03382aA39, User #111'); await page.locator('button > svg.fa-plus').click(); - await expect(page.locator('div[role="alert"] span:has-text("Success")')).toBeVisible(); + await expect(page.getByRole('alert').filter({ hasText: 'Success' })).toBeVisible(); await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert - // wait for the alert to disappear, which also ensures that there is no "Register" button waiting - await expect(page.locator('div[role="alert"]')).toBeHidden(); - + await expect(page.getByRole('button', { name: 'No, Not Yet', exact: true })).toBeVisible(); // backup prompt + await page.getByRole('button', { name: 'No, Not Yet', exact: true }).click(); // don't backup contacts + await expect(page.getByRole('button', { name: 'No, Not Yet', exact: true })).toBeHidden(); + // wait for all alerts to disappear + await expect(page.locator('div[role="alert"]')).toHaveCount(0); }); test('Add contact, copy details, delete, and import from paste & from file', async ({ page, context }) => { @@ -193,22 +196,26 @@ test('Add contact, copy details, delete, and import from paste & from file', asy await page.goto('./contacts'); await page.getByPlaceholder('URL or DID, Name, Public Key').fill('did:ethr:0x111d15564f824D56C7a07b913aA7aDd03382aA39, User #111'); await page.locator('button > svg.fa-plus').click(); - await expect(page.locator('div[role="alert"]')).toBeVisible(); - await expect(page.locator('div[role="alert"] span:has-text("No")')).toBeVisible(); - await page.locator('div[role="alert"] button:has-text("No")').click(); // don't register - await expect(page.locator('div[role="alert"] span:has-text("Success")')).toBeVisible(); + await expect(page.locator('div[role="alert"]').first()).toBeVisible(); + await expect(page.getByRole('alert').filter({ hasText: 'Success' })).toBeVisible(); await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert + await expect(page.getByRole('button', { name: 'No', exact: true })).toBeVisible(); + await page.getByRole('button', { name: 'No', exact: true }).click(); // don't register + await expect(page.getByRole('button', { name: 'No, Not Yet', exact: true })).toBeVisible(); // backup prompt + await page.getByRole('button', { name: 'No, Not Yet', exact: true }).click(); // don't backup contacts // wait for the alert to disappear - await expect(page.locator('div[role="alert"]')).toBeHidden(); + await expect(page.locator('div[role="alert"]')).toHaveCount(0); // Add another new contact await page.getByPlaceholder('URL or DID, Name, Public Key').fill('did:ethr:0x222BB77E6Ff3774d34c751f3c1260866357B677b, User #222, asdf1234'); await page.locator('button > svg.fa-plus').click(); - await expect(page.locator('div[role="alert"] span:has-text("No")')).toBeVisible(); - await page.locator('div[role="alert"] button:has-text("No")').click(); // don't register - await expect(page.locator('div[role="alert"] span:has-text("Success")')).toBeVisible(); + await expect(page.getByRole('alert').filter({ hasText: 'Success' })).toBeVisible(); await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert - await expect(page.locator('div[role="alert"]')).toBeHidden(); + await expect(page.getByRole('button', { name: 'No', exact: true })).toBeVisible(); + await page.getByRole('button', { name: 'No', exact: true }).click(); // don't register + await expect(page.getByRole('button', { name: 'No, Not Yet', exact: true })).toBeVisible(); // backup prompt + await page.getByRole('button', { name: 'No, Not Yet', exact: true }).click(); // don't backup contacts + await expect(page.locator('div[role="alert"]')).toHaveCount(0); await expect(page.getByTestId('contactListItem')).toHaveCount(2);