From 106bbab7609e28d61d3e46f18d61641a91863060 Mon Sep 17 00:00:00 2001 From: Charlie Drage Date: Thu, 19 Dec 2024 09:40:12 -0500 Subject: [PATCH] chore: add telemetry for examples (#1098) * chore: add telemetry for examples ### What does this PR do? Adds telemetry for building as well as pulling examples ### Screenshot / video of UI N/A ### What issues does this PR fix or reference? Closes https://github.com/podman-desktop/extension-bootc/issues/1047 ### How to test this PR? Functions on example should work as normal. Signed-off-by: Charlie Drage * chore: update test Signed-off-by: Charlie Drage --------- Signed-off-by: Charlie Drage --- packages/frontend/src/lib/ExampleCard.spec.ts | 6 ++++++ packages/frontend/src/lib/ExampleCard.svelte | 2 ++ 2 files changed, 8 insertions(+) diff --git a/packages/frontend/src/lib/ExampleCard.spec.ts b/packages/frontend/src/lib/ExampleCard.spec.ts index 042749c4..ca13a244 100644 --- a/packages/frontend/src/lib/ExampleCard.spec.ts +++ b/packages/frontend/src/lib/ExampleCard.spec.ts @@ -30,6 +30,7 @@ vi.mock('../api/client', () => { bootcClient: { pullImage: vi.fn(), openLink: vi.fn(), + telemetryLogUsage: vi.fn(), }, }; }); @@ -90,10 +91,13 @@ test('pullImage function is called when Pull image button is clicked', async () // Find and click the "Pull image" button const pullButton = screen.getByTitle('Pull image'); + await fireEvent.click(pullButton); // Ensure bootcClient.pullImage is called with the correct image name expect(bootcClient.pullImage).toHaveBeenCalledWith('quay.io/example/example1'); + + expect(bootcClient.telemetryLogUsage).toHaveBeenCalled(); }); test('Build image button is displayed if example is pulled', async () => { @@ -112,4 +116,6 @@ test('Build image button is displayed if example is pulled', async () => { // Ensure the router.goto is called with the correct path expect(router.goto).toHaveBeenCalledWith('/disk-images/build/quay.io%2Fexample%2Fexample1/latest'); + + expect(bootcClient.telemetryLogUsage).toHaveBeenCalled(); }); diff --git a/packages/frontend/src/lib/ExampleCard.svelte b/packages/frontend/src/lib/ExampleCard.svelte index bd56a255..83c302be 100644 --- a/packages/frontend/src/lib/ExampleCard.svelte +++ b/packages/frontend/src/lib/ExampleCard.svelte @@ -22,12 +22,14 @@ async function openURL(): Promise { async function pullImage(): Promise { if (example.image) { pullInProgress = true; + bootcClient.telemetryLogUsage('example-pull-image', { image: example.image }); bootcClient.pullImage(example.image); } } async function gotoBuild(): Promise { if (example.image && example.tag) { + bootcClient.telemetryLogUsage('example-build-image', { image: example.image }); router.goto(`/disk-images/build/${encodeURIComponent(example.image)}/${encodeURIComponent(example.tag)}`); } }