From fb84f01147f105199b9e6b613131e2e60f53ece2 Mon Sep 17 00:00:00 2001 From: Allan Lasser Date: Tue, 23 Apr 2024 09:45:23 -0400 Subject: [PATCH 1/4] Tests AddOnListItem --- src/lib/components/addons/AddOnListItem.svelte | 6 +----- src/lib/components/addons/tests/AddOnListItem.test.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 src/lib/components/addons/tests/AddOnListItem.test.ts diff --git a/src/lib/components/addons/AddOnListItem.svelte b/src/lib/components/addons/AddOnListItem.svelte index ba011a294..b0813f800 100644 --- a/src/lib/components/addons/AddOnListItem.svelte +++ b/src/lib/components/addons/AddOnListItem.svelte @@ -4,7 +4,6 @@ import { _ } from "svelte-i18n"; import AddOnPin from "@/addons/AddOnPin.svelte"; - import AddOnPopularity from "@/addons/Popularity.svelte"; import PremiumBadge from "@/premium-credits/PremiumBadge.svelte"; export let addon: AddOnListItem; @@ -35,11 +34,8 @@ >

{/if} - {#if addon.usage} - - {/if} {#if isPremium} - + {/if} diff --git a/src/lib/components/addons/tests/AddOnListItem.test.ts b/src/lib/components/addons/tests/AddOnListItem.test.ts new file mode 100644 index 000000000..1e11f79d4 --- /dev/null +++ b/src/lib/components/addons/tests/AddOnListItem.test.ts @@ -0,0 +1,11 @@ +import { test, expect } from "vitest"; +import { render } from "@testing-library/svelte"; +import AddOnListItem from "../AddOnListItem.svelte"; +import { addon, premiumAddon } from "@/test/fixtures/addons"; + +test("AddOnListItem", () => { + const result = render(AddOnListItem, { addon }); + expect(result.getByRole("heading")).toHaveTextContent(addon.name); + const premium = render(AddOnListItem, { addon: premiumAddon }); + expect(premium.getByRole("status")).toBeInTheDocument(); +}); From 69c76c36ee0856b94c34713ff755eded6c8edf1a Mon Sep 17 00:00:00 2001 From: Allan Lasser Date: Tue, 23 Apr 2024 09:47:47 -0400 Subject: [PATCH 2/4] Improve test case --- src/lib/components/addons/tests/AddOnListItem.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/components/addons/tests/AddOnListItem.test.ts b/src/lib/components/addons/tests/AddOnListItem.test.ts index 1e11f79d4..c8f19b013 100644 --- a/src/lib/components/addons/tests/AddOnListItem.test.ts +++ b/src/lib/components/addons/tests/AddOnListItem.test.ts @@ -7,5 +7,5 @@ test("AddOnListItem", () => { const result = render(AddOnListItem, { addon }); expect(result.getByRole("heading")).toHaveTextContent(addon.name); const premium = render(AddOnListItem, { addon: premiumAddon }); - expect(premium.getByRole("status")).toBeInTheDocument(); + expect(premium.getByRole("status")).toHaveTextContent("Premium"); }); From 90690f21ba5ef50b255d76b8aabdc11b3f562c6c Mon Sep 17 00:00:00 2001 From: Allan Lasser Date: Tue, 23 Apr 2024 09:52:38 -0400 Subject: [PATCH 3/4] Snapshot testing --- .../addons/tests/AddOnListItem.test.ts | 2 + .../__snapshots__/AddOnListItem.test.ts.snap | 315 ++++++++++++++++++ 2 files changed, 317 insertions(+) create mode 100644 src/lib/components/addons/tests/__snapshots__/AddOnListItem.test.ts.snap diff --git a/src/lib/components/addons/tests/AddOnListItem.test.ts b/src/lib/components/addons/tests/AddOnListItem.test.ts index c8f19b013..b3a1c2d7e 100644 --- a/src/lib/components/addons/tests/AddOnListItem.test.ts +++ b/src/lib/components/addons/tests/AddOnListItem.test.ts @@ -6,6 +6,8 @@ import { addon, premiumAddon } from "@/test/fixtures/addons"; test("AddOnListItem", () => { const result = render(AddOnListItem, { addon }); expect(result.getByRole("heading")).toHaveTextContent(addon.name); + expect(result.container).toMatchSnapshot(); const premium = render(AddOnListItem, { addon: premiumAddon }); expect(premium.getByRole("status")).toHaveTextContent("Premium"); + expect(premium.container).toMatchSnapshot(); }); diff --git a/src/lib/components/addons/tests/__snapshots__/AddOnListItem.test.ts.snap b/src/lib/components/addons/tests/__snapshots__/AddOnListItem.test.ts.snap new file mode 100644 index 000000000..b716b20e9 --- /dev/null +++ b/src/lib/components/addons/tests/__snapshots__/AddOnListItem.test.ts.snap @@ -0,0 +1,315 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AddOnListItem 1`] = ` + +
+ +
+ + +
+ This will update document information for all documents in your current search. Please be sure you have edit access to these documents before running this add-on. +
+
+ + +
+ +`; + +exports[`AddOnListItem 2`] = ` + +
+ +
+ + +
+ This will update document information for all documents in your current search. Please be sure you have edit access to these documents before running this add-on. +
+
+ + +
+
+ +
+ + +
+

+ This Add-On uses Azure’s Document Intelligence API to OCR documents. The document(s) must be public to be processed. This Add-On uses 1 AI Credit per page. +

+
+
+ + +
+ +`; From 692a99eca1d21d96856901aa52094bdd87ded605 Mon Sep 17 00:00:00 2001 From: Allan Lasser Date: Tue, 23 Apr 2024 09:55:38 -0400 Subject: [PATCH 4/4] Tests AddOnsNavigation --- .../components/addons/AddOnsNavigation.svelte | 1 - .../addons/tests/AddOnsNavigation.test.ts | 8 + .../AddOnsNavigation.test.ts.snap | 245 ++++++++++++++++++ 3 files changed, 253 insertions(+), 1 deletion(-) create mode 100644 src/lib/components/addons/tests/AddOnsNavigation.test.ts create mode 100644 src/lib/components/addons/tests/__snapshots__/AddOnsNavigation.test.ts.snap diff --git a/src/lib/components/addons/AddOnsNavigation.svelte b/src/lib/components/addons/AddOnsNavigation.svelte index a2f7285e6..ab5490e21 100644 --- a/src/lib/components/addons/AddOnsNavigation.svelte +++ b/src/lib/components/addons/AddOnsNavigation.svelte @@ -58,7 +58,6 @@ href={`/app/add-ons?category=${key}`} active={active === key} > - {label} {/each} diff --git a/src/lib/components/addons/tests/AddOnsNavigation.test.ts b/src/lib/components/addons/tests/AddOnsNavigation.test.ts new file mode 100644 index 000000000..d258cb1e5 --- /dev/null +++ b/src/lib/components/addons/tests/AddOnsNavigation.test.ts @@ -0,0 +1,8 @@ +import { test, expect } from "vitest"; +import { render } from "@testing-library/svelte"; +import AddOnsNavigation from "../AddOnsNavigation.svelte"; + +test("AddOnsNavigation", () => { + const result = render(AddOnsNavigation); + expect(result.container).toMatchSnapshot(); +}); diff --git a/src/lib/components/addons/tests/__snapshots__/AddOnsNavigation.test.ts.snap b/src/lib/components/addons/tests/__snapshots__/AddOnsNavigation.test.ts.snap new file mode 100644 index 000000000..f950b0b0e --- /dev/null +++ b/src/lib/components/addons/tests/__snapshots__/AddOnsNavigation.test.ts.snap @@ -0,0 +1,245 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AddOnsNavigation 1`] = ` + +
+
+
+

+ Browse Add-Ons +

+ +

+ Free automations, shortcuts and power-ups from the DocumentCloud community +

+
+ + + + +
+
+ + Collections + + + +
+ + + AI + + + + + + Analyze + + + + + + Bulk + + + + + + Export + + + + + + Extract + + + + + + File + + + + + + Monitor + + + + + +
+ +
+ + +
+ +`;