Skip to content

Commit

Permalink
feat(core): rename highlight to active
Browse files Browse the repository at this point in the history
BREAKING CHANGE
  • Loading branch information
francoischalifour committed Dec 15, 2020
1 parent a52241c commit 1c1b951
Show file tree
Hide file tree
Showing 50 changed files with 258 additions and 260 deletions.
2 changes: 1 addition & 1 deletion examples/react-renderer/src/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function Autocomplete(
context: {},
isOpen: false,
query: '',
selectedItemId: null,
activeItemId: null,
status: 'idle',
});
const autocomplete = React.useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('completion', () => {
});
});

test('does not set completion when no selectedItemId', () => {
test('does not set completion when no activeItemId', () => {
const onStateChange = jest.fn();
const { inputElement } = createPlayground(createAutocomplete, {
openOnFocus: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('createAutocomplete', () => {
setContext: expect.any(Function),
setIsOpen: expect.any(Function),
setQuery: expect.any(Function),
setSelectedItemId: expect.any(Function),
setActiveItemId: expect.any(Function),
setStatus: expect.any(Function),
});
});
Expand All @@ -29,13 +29,13 @@ describe('createAutocomplete', () => {

expect(plugin.subscribe).toHaveBeenCalledTimes(1);
expect(plugin.subscribe).toHaveBeenLastCalledWith({
onHighlight: expect.any(Function),
onActive: expect.any(Function),
onSelect: expect.any(Function),
setCollections: expect.any(Function),
setContext: expect.any(Function),
setIsOpen: expect.any(Function),
setQuery: expect.any(Function),
setSelectedItemId: expect.any(Function),
setActiveItemId: expect.any(Function),
setStatus: expect.any(Function),
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import userEvent from '@testing-library/user-event';

import { createAutocomplete } from '../createAutocomplete';

describe('defaultSelectedItemId', () => {
test('selects unset defaultSelectedItemId on open (onInput)', () => {
describe('defaultActiveItemId', () => {
test('selects unset defaultActiveItemId on open (onInput)', () => {
const onStateChange = jest.fn();
const autocomplete = createAutocomplete({
openOnFocus: true,
Expand All @@ -20,17 +20,17 @@ describe('defaultSelectedItemId', () => {
expect(onStateChange).toHaveBeenLastCalledWith({
prevState: expect.anything(),
state: expect.objectContaining({
selectedItemId: null,
activeItemId: null,
}),
});
});

test('selects provided defaultSelectedItemId on open (onInput)', () => {
test('selects provided defaultActiveItemId on open (onInput)', () => {
const onStateChange = jest.fn();
const autocomplete = createAutocomplete({
openOnFocus: true,
onStateChange,
defaultSelectedItemId: 0,
defaultActiveItemId: 0,
});
const inputElement = document.createElement('input');
const inputProps = autocomplete.getInputProps({ inputElement });
Expand All @@ -42,17 +42,17 @@ describe('defaultSelectedItemId', () => {
expect(onStateChange).toHaveBeenLastCalledWith({
prevState: expect.anything(),
state: expect.objectContaining({
selectedItemId: 0,
activeItemId: 0,
}),
});
});

test('selects defaultSelectedItemId with openOnFocus on reset', () => {
test('selects defaultActiveItemId with openOnFocus on reset', () => {
const onStateChange = jest.fn();
const autocomplete = createAutocomplete({
openOnFocus: true,
onStateChange,
defaultSelectedItemId: 0,
defaultActiveItemId: 0,
});
const formElement = document.createElement('form');
const inputElement = document.createElement('input');
Expand All @@ -63,23 +63,23 @@ describe('defaultSelectedItemId', () => {
document.body.appendChild(formElement);
formElement.appendChild(inputElement);

autocomplete.setSelectedItemId(null);
autocomplete.setActiveItemId(null);
formElement.reset();

expect(onStateChange).toHaveBeenLastCalledWith({
prevState: expect.anything(),
state: expect.objectContaining({
selectedItemId: 0,
activeItemId: 0,
}),
});
});

test('selects defaultSelectedItemId on focus', () => {
test('selects defaultActiveItemId on focus', () => {
const onStateChange = jest.fn();
const { getInputProps } = createAutocomplete({
openOnFocus: true,
onStateChange,
defaultSelectedItemId: 0,
defaultActiveItemId: 0,
});
const inputElement = document.createElement('input');
const inputProps = getInputProps({ inputElement });
Expand All @@ -91,19 +91,19 @@ describe('defaultSelectedItemId', () => {
expect(onStateChange).toHaveBeenLastCalledWith({
prevState: expect.anything(),
state: expect.objectContaining({
selectedItemId: 0,
activeItemId: 0,
}),
});
});

test('selects defaultSelectedItemId when ArrowDown on the last', () => {
test('selects defaultActiveItemId when ArrowDown on the last', () => {
const onStateChange = jest.fn();
const { getInputProps } = createAutocomplete({
openOnFocus: true,
onStateChange,
defaultSelectedItemId: 0,
defaultActiveItemId: 0,
initialState: {
selectedItemId: 1,
activeItemId: 1,
},
});
const inputElement = document.createElement('input');
Expand All @@ -117,19 +117,19 @@ describe('defaultSelectedItemId', () => {
expect(onStateChange).toHaveBeenLastCalledWith({
prevState: expect.anything(),
state: expect.objectContaining({
selectedItemId: 0,
activeItemId: 0,
}),
});
});

test('selects defaultSelectedItemId when ArrowUp on the first', () => {
test('selects defaultActiveItemId when ArrowUp on the first', () => {
const onStateChange = jest.fn();
const { getInputProps } = createAutocomplete({
openOnFocus: true,
onStateChange,
defaultSelectedItemId: 0,
defaultActiveItemId: 0,
initialState: {
selectedItemId: 1,
activeItemId: 1,
},
});
const inputElement = document.createElement('input');
Expand All @@ -143,7 +143,7 @@ describe('defaultSelectedItemId', () => {
expect(onStateChange).toHaveBeenLastCalledWith({
prevState: expect.anything(),
state: expect.objectContaining({
selectedItemId: 0,
activeItemId: 0,
}),
});
});
Expand Down
20 changes: 10 additions & 10 deletions packages/autocomplete-core/src/__tests__/getFormProps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ describe('getFormProps', () => {
});
});

test('sets the selectedItemId to null', () => {
test('sets the activeItemId to null', () => {
const onStateChange = jest.fn();
const { getFormProps, inputElement } = createPlayground(
createAutocomplete,
{
onStateChange,
initialState: {
selectedItemId: 0,
activeItemId: 0,
},
}
);
Expand All @@ -146,7 +146,7 @@ describe('getFormProps', () => {
expect(onStateChange).toHaveBeenLastCalledWith({
prevState: expect.anything(),
state: expect.objectContaining({
selectedItemId: null,
activeItemId: null,
}),
});
});
Expand Down Expand Up @@ -264,14 +264,14 @@ describe('getFormProps', () => {
});
});

test('sets the selectedItemId to null without openOnFocus', () => {
test('sets the activeItemId to null without openOnFocus', () => {
const onStateChange = jest.fn();
const { getFormProps, inputElement } = createPlayground(
createAutocomplete,
{
onStateChange,
initialState: {
selectedItemId: 0,
activeItemId: 0,
},
}
);
Expand All @@ -282,21 +282,21 @@ describe('getFormProps', () => {
expect(onStateChange).toHaveBeenLastCalledWith({
prevState: expect.anything(),
state: expect.objectContaining({
selectedItemId: null,
activeItemId: null,
}),
});
});

test('sets the selectedItemId to defaultSelectedItemId with openOnFocus', () => {
test('sets the activeItemId to defaultActiveItemId with openOnFocus', () => {
const onStateChange = jest.fn();
const { getFormProps, inputElement } = createPlayground(
createAutocomplete,
{
defaultSelectedItemId: 0,
defaultActiveItemId: 0,
openOnFocus: true,
onStateChange,
initialState: {
selectedItemId: null,
activeItemId: null,
},
}
);
Expand All @@ -307,7 +307,7 @@ describe('getFormProps', () => {
expect(onStateChange).toHaveBeenLastCalledWith({
prevState: expect.anything(),
state: expect.objectContaining({
selectedItemId: 0,
activeItemId: 0,
}),
});
});
Expand Down

0 comments on commit 1c1b951

Please sign in to comment.