-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1245 from rainlanguage/1225-filtering-by-connecte…
…d-wallet Create CheckboxMyItemsOnly.svelte
- Loading branch information
Showing
13 changed files
with
174 additions
and
26 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
packages/ui-components/src/__tests__/CheckboxMyItemsOnly.test.ts
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,54 @@ | ||
import { render, fireEvent, screen } from '@testing-library/svelte'; | ||
import { get, writable, type Writable } from 'svelte/store'; | ||
import { beforeEach, expect, test, describe } from 'vitest'; | ||
import CheckboxMyItemsOnly from '../lib/components/CheckboxMyItemsOnly.svelte'; | ||
|
||
describe('CheckboxMyItemsOnly', () => { | ||
let showMyItemsOnly: Writable<boolean>; | ||
let context: 'orders' | 'vaults'; | ||
let signerAddress: Writable<string | null> | undefined; | ||
beforeEach(() => { | ||
showMyItemsOnly = writable(true); | ||
context = 'orders'; | ||
}); | ||
|
||
test('renders correctly on orders page', () => { | ||
render(CheckboxMyItemsOnly, { | ||
props: { | ||
showMyItemsOnly, | ||
context, | ||
signerAddress | ||
} | ||
}); | ||
expect(screen.getByText('Only show my orders')).toBeInTheDocument(); | ||
}); | ||
test('renders correctly on vaults page', () => { | ||
render(CheckboxMyItemsOnly, { | ||
props: { | ||
showMyItemsOnly, | ||
context: 'vaults', | ||
signerAddress | ||
} | ||
}); | ||
expect(screen.getByText('Only show my vaults')).toBeInTheDocument(); | ||
}); | ||
|
||
test('toggles store value when clicked', async () => { | ||
render(CheckboxMyItemsOnly, { | ||
props: { | ||
showMyItemsOnly, | ||
context, | ||
signerAddress | ||
} | ||
}); | ||
|
||
const checkbox = screen.getByRole('checkbox'); | ||
expect(get(showMyItemsOnly)).toBe(true); | ||
|
||
await fireEvent.click(checkbox); | ||
expect(get(showMyItemsOnly)).toBe(false); | ||
// | ||
await fireEvent.click(checkbox); | ||
expect(get(showMyItemsOnly)).toBe(true); | ||
}); | ||
}); |
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
27 changes: 27 additions & 0 deletions
27
packages/ui-components/src/lib/components/CheckboxMyItemsOnly.svelte
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,27 @@ | ||
<script lang="ts"> | ||
import { Checkbox, Label } from 'flowbite-svelte'; | ||
import type { Writable } from 'svelte/store'; | ||
export let showMyItemsOnly: Writable<boolean>; | ||
export let context: 'orders' | 'vaults'; | ||
export let signerAddress: Writable<string | null> | undefined; | ||
function handleShowMyItemsChange() { | ||
$showMyItemsOnly = !$showMyItemsOnly; | ||
} | ||
</script> | ||
|
||
<div data-testid="show-my-items-checkbox" class="flex items-center gap-x-2"> | ||
<Label | ||
for="show-my-items" | ||
class="cursor-pointer whitespace-nowrap text-sm font-medium text-gray-900 dark:text-gray-300" | ||
> | ||
Only show my {context} | ||
</Label> | ||
<Checkbox | ||
id="show-my-items" | ||
checked={$showMyItemsOnly} | ||
on:change={handleShowMyItemsChange} | ||
disabled={!$signerAddress} | ||
/> | ||
</div> |
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
4 changes: 2 additions & 2 deletions
4
packages/ui-components/src/lib/components/dropdown/DropdownOrderListAccounts.svelte
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
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
Oops, something went wrong.