Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dhayab committed Sep 26, 2023
1 parent ee60791 commit 10cc1c9
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 22 deletions.
17 changes: 14 additions & 3 deletions packages/autocomplete-core/src/__tests__/getInputProps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,21 @@ describe('getInputProps', () => {
test('returns aria-controls with list ID when panel is open', () => {
const { getInputProps, inputElement } = createPlayground(
createAutocomplete,
{ id: 'autocomplete', initialState: { isOpen: true } }
{
id: 'autocomplete',
initialState: {
isOpen: true,
collections: [
createCollection({
source: { sourceId: 'testSource' },
}),
],
},
}
);
const inputProps = getInputProps({ inputElement });

expect(inputProps['aria-controls']).toEqual('autocomplete-list');
expect(inputProps['aria-controls']).toEqual('autocomplete-testSource-list');
});

test('returns aria-labelledby with label ID', () => {
Expand Down Expand Up @@ -669,14 +679,15 @@ describe('getInputProps', () => {
initialState: {
collections: [
createCollection({
source: { sourceId: 'testSource' },
items: [{ label: '1' }],
}),
],
},
...props,
});
const item = document.createElement('div');
item.setAttribute('id', 'autocomplete-item-0');
item.setAttribute('id', 'autocomplete-testSource-item-0');
document.body.appendChild(item);

return { ...playground, item };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('getItemProps', () => {
...defaultItemProps,
});

expect(itemProps.id).toEqual('autocomplete-item-0');
expect(itemProps.id).toEqual('autocomplete-testSource-item-0');
});

test('returns the role to option', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createCollection } from '../../../../test/utils';
import { createAutocomplete } from '../createAutocomplete';

describe('getRootProps', () => {
Expand Down Expand Up @@ -60,11 +61,16 @@ describe('getRootProps', () => {
id: 'autocomplete',
initialState: {
isOpen: true,
collections: [
createCollection({
source: { sourceId: 'testSource' },
}),
],
},
});
const rootProps = autocomplete.getRootProps({});

expect(rootProps['aria-owns']).toEqual('autocomplete-list');
expect(rootProps['aria-owns']).toEqual('autocomplete-testSource-list');
});

test('returns label id in aria-labelledby', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ export function getAutocompleteElementId(
) {
return [autocompleteInstanceId, source?.sourceId, elementId]
.filter(Boolean)
.join('-');
.join('-')
.replace(/\s/g, '');
}
2 changes: 1 addition & 1 deletion packages/autocomplete-js/src/__tests__/detached.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('detached', () => {
});

const firstItem = document.querySelector<HTMLLIElement>(
'#autocomplete-0-item-0'
'#autocomplete-testSource-item-0'
)!;

// Select the first item
Expand Down
6 changes: 3 additions & 3 deletions packages/autocomplete-js/src/__tests__/renderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,15 @@ describe('renderer', () => {
data-autocomplete-source-id="testSource"
>
<ul
aria-labelledby="autocomplete-0-0-label"
aria-labelledby="autocomplete-0-label"
class="aa-List"
id="autocomplete-0-0-list"
id="autocomplete-0-testSource-list"
role="listbox"
>
<li
aria-selected="false"
class="aa-Item"
id="autocomplete-0-0-item-0"
id="autocomplete-0-testSource-item-0"
role="option"
>
1
Expand Down
24 changes: 12 additions & 12 deletions packages/autocomplete-js/src/__tests__/templates.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ describe('templates', () => {
expect(within(panelContainer).getByRole('listbox'))
.toMatchInlineSnapshot(`
<ul
aria-labelledby="autocomplete-0-0-label"
aria-labelledby="autocomplete-0-label"
class="aa-List"
id="autocomplete-0-0-list"
id="autocomplete-0-testSource-list"
role="listbox"
>
<li
aria-selected="false"
class="aa-Item"
id="autocomplete-0-0-item-0"
id="autocomplete-0-testSource-item-0"
role="option"
>
<div
Expand Down Expand Up @@ -208,15 +208,15 @@ describe('templates', () => {
expect(within(panelContainer).getByRole('listbox'))
.toMatchInlineSnapshot(`
<ul
aria-labelledby="autocomplete-0-0-label"
aria-labelledby="autocomplete-0-label"
class="aa-List"
id="autocomplete-0-0-list"
id="autocomplete-0-testSource-list"
role="listbox"
>
<li
aria-selected="false"
class="aa-Item"
id="autocomplete-0-0-item-0"
id="autocomplete-0-testSource-item-0"
role="option"
>
<div
Expand Down Expand Up @@ -343,15 +343,15 @@ describe('templates', () => {
</header>
</div>
<ul
aria-labelledby="autocomplete-0-0-label"
aria-labelledby="autocomplete-0-label"
class="aa-List"
id="autocomplete-0-0-list"
id="autocomplete-0-testSource-list"
role="listbox"
>
<li
aria-selected="false"
class="aa-Item"
id="autocomplete-0-0-item-0"
id="autocomplete-0-testSource-item-0"
role="option"
>
<div
Expand Down Expand Up @@ -507,15 +507,15 @@ describe('templates', () => {
</header>
</div>
<ul
aria-labelledby="autocomplete-0-0-label"
aria-labelledby="autocomplete-0-label"
class="aa-List"
id="autocomplete-0-0-list"
id="autocomplete-0-testSource-list"
role="listbox"
>
<li
aria-selected="false"
class="aa-Item"
id="autocomplete-0-0-item-0"
id="autocomplete-0-testSource-item-0"
role="option"
>
div
Expand Down

0 comments on commit 10cc1c9

Please sign in to comment.