From 9b86af85088c6c385cb857e2178f06b9a3185ac4 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sun, 15 Sep 2024 19:53:12 -0600 Subject: [PATCH] fix alert when looking at one's own activity --- CHANGELOG.md | 7 ++ src/views/DIDView.vue | 117 +++++++++++++++----------- test-playwright/00-noid-tests.spec.ts | 18 +++- test-playwright/testUtils.ts | 22 ++++- 4 files changed, 113 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be22c567b..37313acab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.?] +### Added +- Separate 'isRegistered' flag for each account +### Fixed +- Alert when looking at one's own activity if not in contacts. + + ## [0.3.25] - 2024.08.30 - dcbe02d877aecb4cdef2643d90e6595d246a9f82 ### Added - "Ideas" now jumps directly to giving prompt or contact list. diff --git a/src/views/DIDView.vue b/src/views/DIDView.vue index 7f2a5fe03..e3dbaefea 100644 --- a/src/views/DIDView.vue +++ b/src/views/DIDView.vue @@ -19,14 +19,17 @@ -
+

- {{ contact?.name || "(no name)" }} + {{ contactFromDid?.name || "(no name)" }}

- +
@@ -63,17 +69,21 @@
@@ -94,13 +104,13 @@
-
+
Auto-Generated Icon
+
+ +
+

+ {{ isMyDid ? "You" : "(no name)" }} +

+
+
+

Edit Name

@@ -222,7 +241,8 @@ v-if="!isLoading && claims.length === 0" class="flex justify-center mt-4" > - They are in no claims visible to you. + You have no claims yet. + They are in no claims visible to you.
@@ -270,15 +290,15 @@ export default class DIDView extends Vue { yaml = yaml; activeDid = ""; - allMyDids: Array = []; apiServer = ""; claims: Array> = []; - contact: Contact; + contactFromDid?: Contact; contactEdit = false; - contactNewName?: string; + contactNewName: string = ""; contactYaml = ""; hitEnd = false; isLoading = false; + isMyDid = false; searchBox: { name: string; bbox: BoundingBox } | null = null; showDidDetails = false; showLargeIdenticonId?: string; @@ -295,32 +315,23 @@ export default class DIDView extends Vue { this.apiServer = settings.apiServer || ""; const pathParam = window.location.pathname.substring("/did/".length); - let theContact: Contact | undefined; if (pathParam) { this.viewingDid = decodeURIComponent(pathParam); - theContact = await db.contacts.get(this.viewingDid); - } - if (theContact) { - this.contact = theContact; - } else { - this.$notify( - { - group: "alert", - type: "danger", - title: "Error", - text: "No valid claim ID was provided.", - }, - -1, - ); - return; + this.contactFromDid = await db.contacts.get(this.viewingDid); + if (this.contactFromDid) { + this.contactYaml = yaml.dump(this.contactFromDid); + } + await this.loadClaimsAbout(); + + await accountsDB.open(); + const allAccounts = await accountsDB.accounts.toArray(); + for (const account of allAccounts) { + if (account.did === this.viewingDid) { + this.isMyDid = true; + break; + } + } } - - this.contactYaml = yaml.dump(this.contact); - await this.loadClaimsAbout(); - - await accountsDB.open(); - const allAccounts = await accountsDB.accounts.toArray(); - this.allMyDids = allAccounts.map((acc) => acc.did); } /** @@ -376,7 +387,7 @@ export default class DIDView extends Vue { title: "Register", text: "Are you sure you want to register " + - libsUtil.nameForContact(this.contact, false) + + libsUtil.nameForContact(this.contactFromDid, false) + (contact.registered ? " -- especially since they are already marked as registered" : "") + @@ -557,9 +568,21 @@ export default class DIDView extends Vue { } private async onClickSaveName(newName: string) { - this.contact.name = newName; + if (!this.contactFromDid) { + this.$notify( + { + group: "alert", + type: "danger", + title: "Not A Contact", + text: "First add this on the contact page, then you can edit here.", + }, + 5000, + ); + return; + } + this.contactFromDid.name = newName; return db.contacts - .update(this.contact.did, { name: newName }) + .update(this.contactFromDid.did, { name: newName }) .then(() => (this.contactEdit = false)); } diff --git a/test-playwright/00-noid-tests.spec.ts b/test-playwright/00-noid-tests.spec.ts index 4d623dfeb..447b47c4c 100644 --- a/test-playwright/00-noid-tests.spec.ts +++ b/test-playwright/00-noid-tests.spec.ts @@ -1,5 +1,5 @@ import { test, expect } from '@playwright/test'; -import { generateEthrUser, importUser } from './testUtils'; +import { deleteContact, generateEthrUser, importUser } from './testUtils'; test('Check activity feed', async ({ page }) => { // Load app homepage @@ -123,4 +123,20 @@ test('Check User 0 can register a random person', async ({ page }) => { // now ensure that alert goes away await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss alert await expect(page.getByText('That gift was recorded.')).toBeHidden(); + + // now delete the contact to test that pages still do reasonable things + await deleteContact(page, newDid); + // go the activity page for this new person + await page.goto('./did/' + encodeURIComponent(newDid)); + let error; + try { + await page.waitForSelector('div[role="alert"]', { timeout: 2000 }); + error = new Error('Error alert should not show.'); + } catch (error) { + // success + } finally { + if (error) { + throw error; + } + } }); diff --git a/test-playwright/testUtils.ts b/test-playwright/testUtils.ts index 4eef394bd..090ae2011 100644 --- a/test-playwright/testUtils.ts +++ b/test-playwright/testUtils.ts @@ -40,6 +40,22 @@ export async function switchToUser(page: Page, did: string): Promise { await page.getByRole('code', { name: did }).click(); } +function createContactName(did: string): string { + return "User " + did.slice(11, 14); +} + +export async function deleteContact(page: Page, did: string): Promise { + await page.goto('./contacts'); + const contactName = createContactName(did); + // go to the detail page for this contact + await page.locator(`li[data-testid="contactListItem"] h2:has-text("${contactName}") + a`).click(); + // delete the contact + await page.locator('button > svg.fa-trash-can').click(); + await page.locator('div[role="alert"] button:has-text("Yes")').click(); + // for some reason, .isHidden() (without expect) doesn't work + await expect(page.locator('div[role="alert"] button:has-text("Yes")')).toBeHidden(); +} + // Generate a new random user and register them. // Note that this makes 000 the active user. Use switchToUser to switch to this DID. export async function generateEthrUser(page: Page): Promise { @@ -55,10 +71,10 @@ export async function generateEthrUser(page: Page): Promise { await importUser(page, '000'); // switch to user 000 await page.goto('./contacts'); - const threeChars = newDid.slice(11, 14); - await page.getByPlaceholder('URL or DID, Name, Public Key').fill(`${newDid}, User ${threeChars}`); + const contactName = createContactName(newDid); + await page.getByPlaceholder('URL or DID, Name, Public Key').fill(`${newDid}, ${contactName}`); await page.locator('button > svg.fa-plus').click(); - await page.locator('li', { hasText: threeChars }).click(); + await page.locator('li', { hasText: contactName }).click(); // register them await page.locator('div[role="alert"] button:has-text("Yes")').click(); // wait for it to disappear because the next steps may depend on alerts being gone