From 63641f778258c38a5ee81cdf3ee1ab7eb6139ece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Vi=C3=A9not?= Date: Tue, 28 Nov 2023 12:29:34 +0100 Subject: [PATCH] Add unit test for BlobValue showBase64AsExtra prop. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Simon ViƩnot --- src/components/values/BlobValue.vue | 6 ++- tests/unit/values/BlobValue.spec.ts | 57 ++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/components/values/BlobValue.vue b/src/components/values/BlobValue.vue index 1e3c24b84..3ea3d65e9 100644 --- a/src/components/values/BlobValue.vue +++ b/src/components/values/BlobValue.vue @@ -37,11 +37,13 @@ {{ (b64EncodingFound && showBase64AsExtra) ? blobValue : decodedValue }} -
+
Base64: - {{decodedValue }} + + {{decodedValue }} +
diff --git a/tests/unit/values/BlobValue.spec.ts b/tests/unit/values/BlobValue.spec.ts index cd3e11cdb..42d89c2f6 100644 --- a/tests/unit/values/BlobValue.spec.ts +++ b/tests/unit/values/BlobValue.spec.ts @@ -130,8 +130,61 @@ describe("BlobValue.vue", () => { await flushPromises() - expect(wrapper.text()).toBe(BLOB_PLAIN_TEXT) - expect(btoa(wrapper.text())).toBe(BLOB_BASE64) + const blobMain = wrapper.get("#blob-main").text() + expect(blobMain).toBe(BLOB_PLAIN_TEXT) + expect(btoa(blobMain)).toBe(BLOB_BASE64) + + expect(wrapper.find("#blob-extra").exists()).toBe(false) + + wrapper.unmount() + await flushPromises() + }) + + it("should display raw value and base64-decoded value as extra", async () => { + + const wrapper = mount(BlobValue, { + global: { + plugins: [router] + }, + props: { + blobValue: BLOB_BASE64, + base64: true, + showBase64AsExtra: true + }, + }); + + await flushPromises() + + const blobMain = wrapper.get("#blob-main").text() + expect(blobMain).toBe(BLOB_BASE64) + + const blobExtra = wrapper.get("#blob-extra").text() + expect(blobExtra).toBe(BLOB_PLAIN_TEXT) + expect(btoa(blobExtra)).toBe(BLOB_BASE64) + + wrapper.unmount() + await flushPromises() + }) + + it("should display the (unencoded) blob value and ignore the showBase64AsExtra prop", async () => { + + const wrapper = mount(BlobValue, { + global: { + plugins: [router] + }, + props: { + blobValue: BLOB_PLAIN_TEXT, + base64: true, + showBase64AsExtra: true + }, + }); + + await flushPromises() + + const blobMain = wrapper.get("#blob-main").text() + expect(blobMain).toBe(BLOB_PLAIN_TEXT) + + expect(wrapper.find("#blob-extra").exists()).toBe(false) wrapper.unmount() await flushPromises()