Skip to content

Commit

Permalink
Add unit test for BlobValue showBase64AsExtra prop.
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Viénot <[email protected]>
  • Loading branch information
svienot committed Nov 28, 2023
1 parent 6a86f25 commit 63641f7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/components/values/BlobValue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
<span id="blob-main">
{{ (b64EncodingFound && showBase64AsExtra) ? blobValue : decodedValue }}
</span>
<div v-if="b64EncodingFound && showBase64AsExtra" id="blob-extra" class="h-is-extra-text h-is-text-size-3 mt-1">
<div v-if="b64EncodingFound && showBase64AsExtra" class="h-is-extra-text h-is-text-size-3 mt-1">
<span class="has-text-grey">
Base64:
</span>
{{decodedValue }}
<span id="blob-extra">
{{decodedValue }}
</span>
</div>
</div>
</template>
Expand Down
57 changes: 55 additions & 2 deletions tests/unit/values/BlobValue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 63641f7

Please sign in to comment.