Skip to content

Commit

Permalink
fix tests for exporting
Browse files Browse the repository at this point in the history
  • Loading branch information
vitormv committed Jan 20, 2024
1 parent b06a2fc commit 09f40af
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
5 changes: 2 additions & 3 deletions package.json
Expand Up @@ -9,9 +9,8 @@
"preview": "vite preview",
"test": "vitest --environment=jsdom",
"check": "svelte-check --tsconfig ./tsconfig.json",
"lint": "tsc --noemit && eslint --cache --cache-location node_modules/.eslintcache .",
"format": "prettier --write .",
"deploy": "yarn build && bash ./cli/gh-pages-deploy.sh && git checkout -"
"lint": "eslint --cache --cache-location node_modules/.eslintcache . && yarn check",
"format": "prettier --write ."
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^3.0.1",
Expand Down
32 changes: 17 additions & 15 deletions src/components/ExportOptions.svelte
Expand Up @@ -26,6 +26,20 @@
permalinkInputEl.select();
navigator.clipboard.writeText(permalinkInputEl.value);
}
function onToggleColorsOnly(e: Event) {
exportColorsOnly = (e.currentTarget as HTMLInputElement)?.checked;
}
function onToggleInheritBgColor(e: Event) {
const isChecked = (e.currentTarget as HTMLInputElement)?.checked;
colorsStore.updateColor('bg', isChecked ? '' : initialColors.bg);
}
function onToggleInheritFgColor(e: Event) {
const isChecked = (e.currentTarget as HTMLInputElement)?.checked;
colorsStore.updateColor('fg', isChecked ? '' : initialColors.fg);
}
</script>

<button class="export btn btn-primary" on:click={() => (isModalOpen = true)}>
Expand All @@ -39,28 +53,16 @@

<div class="content">
<div class="row-url-export" style="justify-content: space-between;">
<Checkbox
checked={exportColorsOnly}
label="Colors only?"
on:change={(e) => {
exportColorsOnly = e.currentTarget?.checked;
}}
/>
<Checkbox checked={exportColorsOnly} label="Colors only?" on:change={onToggleColorsOnly} />
<Checkbox
checked={!$colorsStore.colors.bg}
label="Use terminal bg"
on:change={(e) => {
const isChecked = e.currentTarget?.checked;
colorsStore.updateColor('bg', isChecked ? '' : initialColors.bg);
}}
on:change={onToggleInheritBgColor}
/>
<Checkbox
checked={!$colorsStore.colors.fg}
label="Use terminal fg"
on:change={(e) => {
const isChecked = e.currentTarget?.checked;
colorsStore.updateColor('fg', isChecked ? '' : initialColors.fg);
}}
on:change={onToggleInheritFgColor}
/>
</div>
<div class="row-url-export">
Expand Down
19 changes: 16 additions & 3 deletions src/data/export/exportToUrlHash.test.ts
@@ -1,6 +1,6 @@
import { expect, it, describe } from 'vitest';

import type { ThemeOptions } from '~/data/options.store';
import { initialOptions, type ThemeOptions } from '~/data/options.store';
import type { ColorValues } from '~/data/colors.store';
import { importFromUrlHash } from '~/data/import/importFromUrlHash';
import { exportToUrlHash } from '~/data/export/exportToUrlHash';
Expand Down Expand Up @@ -49,8 +49,8 @@ const sampleColorOptions: ColorValues = {
};

describe('exportToUrlHash()', () => {
it('should be able to encode and decode url hash to same object', () => {
const urlOutput = exportToUrlHash(sampleThemeOptions, sampleColorOptions);
it('should be able to encode and decode url hash to same object when exporting all options', () => {
const urlOutput = exportToUrlHash(sampleThemeOptions, sampleColorOptions, false);

const url = new URL(urlOutput);

Expand All @@ -61,4 +61,17 @@ describe('exportToUrlHash()', () => {
colors: sampleColorOptions,
});
});

it('should be able to encode and decode url hash to same object when exporting colorsOnly', () => {
const urlOutput = exportToUrlHash(sampleThemeOptions, sampleColorOptions, true);

const url = new URL(urlOutput);

const imported = importFromUrlHash(url.hash.substring(1));

expect(imported).toEqual({
themeOptions: initialOptions, // ignores provided options and uses default
colors: sampleColorOptions,
});
});
});

0 comments on commit 09f40af

Please sign in to comment.