Skip to content

Commit 5d8144a

Browse files
Merge pull request #51 from appwrite/tests-2
feat: improve & update tests
2 parents 33800bc + 6c2937b commit 5d8144a

File tree

11 files changed

+215
-3
lines changed

11 files changed

+215
-3
lines changed

src/lib/components/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export { default as Modal } from './modal.svelte';
22
export { default as Pagination } from './pagination.svelte';
33
export { default as Card } from './card.svelte';
44
export { default as CardGrid } from './cardGrid.svelte';
5-
export { default as InnerModal } from './InnerModal.svelte';
5+
export { default as InnerModal } from './innerModal.svelte';
66
export { default as Tile } from './tile.svelte';
77
export { default as Tiles } from './tiles.svelte';
88
export { default as Back } from './back.svelte';
File renamed without changes.

src/lib/elements/forms/button.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
export let external = false;
99
export let href: string = null;
1010
export let fullWidth = false;
11+
export let ariaLabel: string = null;
1112
//TODO: add option to add aria-label to buttons that are only icons
1213
</script>
1314

@@ -22,7 +23,8 @@
2223
class:is-secondary={secondary}
2324
class:is-text={text}
2425
class:is-danger={danger}
25-
class:is-full-width={fullWidth}>
26+
class:is-full-width={fullWidth}
27+
aria-label={ariaLabel}>
2628
<slot />
2729
</a>
2830
{:else}
@@ -35,7 +37,8 @@
3537
class:is-danger={danger}
3638
class:is-text={text}
3739
class:is-full-width={fullWidth}
38-
type={submit ? 'submit' : 'button'}>
40+
type={submit ? 'submit' : 'button'}
41+
aria-label={ariaLabel}>
3942
<slot />
4043
</button>
4144
{/if}

tests/unit/elements/button.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,37 @@ test('shows button - text', () => {
3232
expect(getByRole('button')).toHaveClass('is-text');
3333
});
3434

35+
test('shows button - danger', () => {
36+
const { getByRole } = render(Button, { danger: true });
37+
38+
expect(getByRole('button')).toHaveClass('is-danger');
39+
});
40+
41+
test('shows button - round', () => {
42+
const { getByRole } = render(Button, { round: true });
43+
44+
expect(getByRole('button')).toHaveClass('is-only-icon');
45+
});
46+
test('shows button - full width', () => {
47+
const { getByRole } = render(Button, { fullWidth: true });
48+
49+
expect(getByRole('button')).toHaveClass('is-full-width');
50+
});
51+
52+
test('shows button - is link', () => {
53+
render(Button, { href: 'https://appwrite.io' });
54+
const link = document.querySelector('a');
55+
56+
expect(link).toHaveAttribute('href', 'https://appwrite.io');
57+
});
58+
test('shows button - is link is external', () => {
59+
render(Button, { href: 'https://appwrite.io', external: true });
60+
const link = document.querySelector('a');
61+
62+
expect(link).toHaveAttribute('target', '_blank');
63+
expect(link).toHaveAttribute('rel', 'noopener noreferrer');
64+
});
65+
3566
test('shows button - on:click', async () => {
3667
const { getByRole, component } = render(Button);
3768
const button = getByRole('button');

tests/unit/elements/inputEmail.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ test('shows email input - placeholder', () => {
4040
expect(getByPlaceholderText('find me')).toBeInTheDocument();
4141
});
4242

43+
test('shows email input - hide label', () => {
44+
render(InputEmail, {
45+
id: 'input',
46+
label: 'label',
47+
showLabel: false
48+
});
49+
50+
const label = document.querySelector('label');
51+
expect(label).toHaveClass('u-hide');
52+
});
53+
54+
test('shows email input - autocomplete', () => {
55+
const { getByLabelText } = render(InputEmail, {
56+
id: 'input',
57+
label: 'input',
58+
autocomplete: true
59+
});
60+
61+
expect(getByLabelText('input')).toHaveAttribute('autocomplete', 'on');
62+
});
63+
4364
test('state', async () => {
4465
const { component, getByLabelText } = render(InputEmail, {
4566
id: 'input',

tests/unit/elements/inputNumber.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,27 @@ test('shows number input - placeholder', () => {
4444
expect(getByPlaceholderText('find me')).toBeInTheDocument();
4545
});
4646

47+
test('shows number input - hide label', () => {
48+
render(InputNumber, {
49+
id: 'input',
50+
label: 'label',
51+
showLabel: false
52+
});
53+
54+
const label = document.querySelector('label');
55+
expect(label).toHaveClass('u-hide');
56+
});
57+
58+
test('shows number input - maxlength', () => {
59+
const { getByLabelText } = render(InputNumber, {
60+
id: 'input',
61+
label: 'input',
62+
maxlength: 2
63+
});
64+
65+
expect(getByLabelText('input')).toHaveAttribute('maxlength', '2');
66+
});
67+
4768
test('state', async () => {
4869
const { component, getByLabelText } = render(InputNumber, { id: 'input', label: 'input' });
4970
const input = getByLabelText('input');

tests/unit/elements/inputPassword.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,57 @@ test('shows password input - placeholder', () => {
5252
expect(getByPlaceholderText('find me')).toBeInTheDocument();
5353
});
5454

55+
test('shows password input - meter', () => {
56+
render(InputPassword, {
57+
id: 'input',
58+
label: 'input',
59+
meter: true
60+
});
61+
62+
const meter = document.querySelector('meter');
63+
expect(meter).toBeInTheDocument();
64+
});
65+
66+
test('shows password input - show password button', () => {
67+
const { getByRole } = render(InputPassword, {
68+
id: 'input',
69+
label: 'input',
70+
showPasswordButton: true
71+
});
72+
73+
expect(getByRole('button')).toBeInTheDocument();
74+
});
75+
76+
test('shows password input - maxlength', () => {
77+
const { getByLabelText } = render(InputPassword, {
78+
id: 'input',
79+
label: 'input',
80+
maxlength: 2
81+
});
82+
83+
expect(getByLabelText('input')).toHaveAttribute('maxlength', '2');
84+
});
85+
test('shows password input - minlength', () => {
86+
const { getByLabelText } = render(InputPassword, {
87+
id: 'input',
88+
label: 'input',
89+
minlength: 2
90+
});
91+
92+
expect(getByLabelText('input')).toHaveAttribute('minlength', '2');
93+
});
94+
95+
test('shows password input - hide label', () => {
96+
render(InputPassword, {
97+
id: 'input',
98+
label: 'label',
99+
showLabel: false
100+
});
101+
102+
const label = document.querySelector('label');
103+
expect(label).toHaveClass('u-hide');
104+
});
105+
55106
test('state', async () => {
56107
const { component, getByLabelText } = render(InputPassword, {
57108
id: 'input',

tests/unit/elements/inputPhone.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,37 @@ test('shows phone input - placeholder', () => {
3939
expect(getByPlaceholderText('find me')).toBeInTheDocument();
4040
});
4141

42+
test('shows phone input - hide label', () => {
43+
render(InputPhone, {
44+
id: 'input',
45+
label: 'label',
46+
showLabel: false
47+
});
48+
49+
const label = document.querySelector('label');
50+
expect(label).toHaveClass('u-hide');
51+
});
52+
53+
test('shows phone input - autocomplete', () => {
54+
const { getByLabelText } = render(InputPhone, {
55+
id: 'input',
56+
label: 'input',
57+
autocomplete: true
58+
});
59+
60+
expect(getByLabelText('input')).toHaveAttribute('autocomplete', 'on');
61+
});
62+
63+
test('shows phone input - maxlength', () => {
64+
const { getByLabelText } = render(InputPhone, {
65+
id: 'input',
66+
label: 'input',
67+
maxlength: 2
68+
});
69+
70+
expect(getByLabelText('input')).toHaveAttribute('maxlength', '2');
71+
});
72+
4273
test('state', async () => {
4374
const { component, getByLabelText } = render(InputPhone, {
4475
id: 'input',

tests/unit/elements/inputSelect.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ test('shows select input - disabled', () => {
6767
expect(getByLabelText('select')).toBeDisabled();
6868
});
6969

70+
test('shows select input - hide label', () => {
71+
render(InputSelect, {
72+
id: 'select',
73+
options,
74+
label: 'label',
75+
showLabel: false
76+
});
77+
78+
const label = document.querySelector('label');
79+
expect(label).toHaveClass('u-hide');
80+
});
81+
7082
test('state', async () => {
7183
const { component, getByLabelText } = render(InputSelect, {
7284
id: 'select',

tests/unit/elements/inputTags.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ test('shows input - autofocus', () => {
1515
expect(getByLabelText('Tags')).toHaveFocus();
1616
});
1717

18+
test('shows input - hide label', () => {
19+
render(InputTags, {
20+
id: 'input',
21+
label: 'label',
22+
showLabel: false
23+
});
24+
25+
const label = document.querySelector('label');
26+
expect(label).toHaveClass('u-hide');
27+
});
28+
1829
test('shows tags', () => {
1930
const { getByText } = render(InputTags, {
2031
id: 'input',

0 commit comments

Comments
 (0)