-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: David Czachor <[email protected]> Co-Authored-By: Christopher McGale <[email protected]> Co-Authored-By: Gerrie Swart <[email protected]>
- Loading branch information
1 parent
d05879c
commit f928b54
Showing
6 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Base64Decode } from '../../../src/utilities/Base64Decode' | ||
|
||
describe('Base64 Decoder', () => { | ||
beforeEach(() => { | ||
cy.visit('/tools/base-64-decode') | ||
}) | ||
|
||
const text: string = 'Rm9vYmFy' | ||
|
||
it('should allow the user to enter text to decode', () => { | ||
cy.get('textarea[aria-label="input-to-decode"]').type(text) | ||
}) | ||
|
||
it('should display the decoded text', () => { | ||
cy.get('textarea[aria-label="input-to-decode"]').type(text) | ||
cy.get('button[aria-label="decode-text"]').click() | ||
const decodedText: string = Base64Decode(text) | ||
cy.get('textarea[aria-label="decoded-text"]').should('have.value', decodedText) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function Base64Decode(encodedString: string): string { | ||
return atob(encodedString) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<template> | ||
<div class=""> | ||
<div class="bg-white shadow rounded p-5"> | ||
<div class="flex justify-evenly w-4/5"> | ||
<textarea aria-label="input-to-decode" v-model="stringToDecode" type="text" placeholder="String to decode" rows="5" | ||
class="w-full p-2"></textarea> | ||
<button aria-label="decode-text" class="bg-indigo-600 text-white text-sm leading-6 font-medium mx-4 rounded-lg w-28" type="button" | ||
@click="decode">Decode | ||
</button> | ||
</div> | ||
<textarea aria-label="decoded-text" :value="decodedString" readonly rows="30" | ||
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" | ||
placeholder="Decoded String"></textarea> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { ref } from 'vue' | ||
import { Base64Decode } from '@/utilities/Base64Decode' | ||
const stringToDecode = ref<string>('') | ||
const decodedString = ref<string>('') | ||
function decode() { | ||
try { | ||
decodedString.value = Base64Decode(stringToDecode.value) | ||
} catch (e: any) { | ||
alert(e.message) | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { Base64Decode } from '@/utilities/Base64Decode' | ||
|
||
describe('Base64Encode', () => { | ||
it('should decode to string', () => { | ||
const input: string = 'Rm9vYmFy' | ||
|
||
const expectedOutput = 'Foobar' | ||
|
||
expect(Base64Decode(input)).toEqual(expectedOutput) | ||
}) | ||
|
||
it('can handle empty string', function () { | ||
const input: string = '' | ||
|
||
expect(Base64Decode(input)).toEqual('') | ||
}) | ||
}) |