Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/autocomplete-core/src/types/AutocompletePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ export type AutocompletePlugin<
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/plugins/#param-data
*/
data?: TData;
/**
* A name to identify the plugin.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/plugins/#param-name
*/
name?: string;
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import insightsClient from 'search-insights';

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

describe('createAlgoliaInsightsPlugin', () => {
test('has a name', () => {
const plugin = createAlgoliaInsightsPlugin({ insightsClient });

expect(plugin.name).toBe('aa.algoliaInsightsPlugin');
});

test.todo('tests');
});
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export function createAlgoliaInsightsPlugin({
}, 0);

return {
name: 'aa.algoliaInsightsPlugin',
subscribe({ setContext, onSelect, onActive }) {
setContext({ algoliaInsightsPlugin: { insights } });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
import { createSearchClient } from '../../../../test/utils';
import { createQuerySuggestionsPlugin } from '../createQuerySuggestionsPlugin';

const searchClient = createSearchClient();

describe('createQuerySuggestionsPlugin', () => {
test('has a name', () => {
const plugin = createQuerySuggestionsPlugin({
searchClient,
indexName: 'indexName',
});

expect(plugin.name).toBe('aa.querySuggestionsPlugin');
});

test.todo('adds a source');

test.todo('fills the input with the query item key');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export function createQuerySuggestionsPlugin<
undefined
> {
return {
name: 'aa.querySuggestionsPlugin',
getSources({ query, setQuery, refresh, state }) {
function onTapAhead(item: TItem) {
setQuery(`${item.query} `);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createLocalStorageRecentSearchesPlugin } from '../createLocalStorageRecentSearchesPlugin';

describe('createLocalStorageRecentSearchesPlugin', () => {
test('has a name', () => {
const plugin = createLocalStorageRecentSearchesPlugin({
key: 'autocomplete',
});

expect(plugin.name).toBe('aa.localStorageRecentSearchesPlugin');
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import { noop } from '@algolia/autocomplete-shared';

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

describe('createRecentSearchesPlugin', () => {
test('has a name', () => {
const plugin = createRecentSearchesPlugin({
storage: { onAdd: noop, onRemove: noop, getAll: () => [] },
});

expect(plugin.name).toBe('aa.recentSearchesPlugin');
});

test.todo('saves the query on select');

test.todo('does not save the query on select without item input value');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ export function createLocalStorageRecentSearchesPlugin<
search,
});

return createRecentSearchesPlugin({
const recentSearchesPlugin = createRecentSearchesPlugin({
transformSource,
storage,
subscribe,
});

return {
...recentSearchesPlugin,
name: 'aa.localStorageRecentSearchesPlugin',
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export function createRecentSearchesPlugin<TItem extends RecentSearchesItem>({
const lastItemsRef = createRef<MaybePromise<TItem[]>>([]);

return {
name: 'aa.recentSearchesPlugin',
subscribe: subscribe ?? getDefaultSubcribe(store),
onSubmit({ state }) {
const { query } = state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ beforeEach(() => {
});

describe('createTagsPlugin', () => {
test('has a name', () => {
const tagsPlugin = createTagsPlugin();

expect(tagsPlugin.name).toBe('aa.tagsPlugin');
});

test('adds a tags source', async () => {
const container = document.createElement('div');
const panelContainer = document.createElement('div');
Expand Down
1 change: 1 addition & 0 deletions packages/autocomplete-plugin-tags/src/createTagsPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export function createTagsPlugin<
const tagsApi = { setTags: tags.set, addTags: tags.add };

return {
name: 'aa.tagsPlugin',
subscribe(params) {
const { setContext, onSelect, setIsOpen, refresh } = params;
const subscribers = getTagsSubscribers();
Expand Down