Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

fix(get-val): call autocompleteInstance.val instead ac.autocomplete.getVal #919

Merged
merged 2 commits into from
Oct 28, 2019
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: 5 additions & 1 deletion src/places.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,17 @@ export default function places(options) {
.querySelector(`.${prefix}-input`)
.addEventListener('input', inputListener);

const autocompleteIsomorphicMethods = ['open', 'close', 'getVal'];
const autocompleteIsomorphicMethods = ['open', 'close'];
autocompleteIsomorphicMethods.forEach(methodName => {
placesInstance[methodName] = (...args) => {
autocompleteInstance.autocomplete[methodName](...args);
};
});

placesInstance.getVal = () => {
return autocompleteInstance.val();
};

placesInstance.destroy = (...args) => {
autocompleteContainer
.querySelector(`.${prefix}-input`)
Expand Down
13 changes: 6 additions & 7 deletions src/places.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,13 @@ describe('places', () => {
expect(autocomplete.__instance.autocomplete.destroy).toHaveBeenCalled();
});

it('has a getVal method', () => {
placesInstance.getVal();
expect(autocomplete.__instance.val).toHaveBeenCalled();
});

it('has all autocomplete methods', () => {
const autocompleteMethods = [
'open',
'close',
'getVal',
'setVal',
'destroy',
];
const autocompleteMethods = ['open', 'close', 'setVal', 'destroy'];
autocompleteMethods.forEach(methodName => {
placesInstance[methodName]('hello');
expect(
Expand Down
60 changes: 60 additions & 0 deletions test/e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,26 @@ describe('releases', () => {
expect(allMatching).toBeTruthy();
});

it('getVal returns the value of the input', async () => {
const pendingXHR = new PendingXHR(page);
await page.focus('#search-box');
const query = `55 rue d'Amsterd`;
await page.keyboard.type(query);

// Places should send a query per character typed
expect(pendingXHR.pendingXhrCount()).toEqual(query.length);

await pendingXHR.waitForAllXhrFinished();

// Places suggestion dropdown should have has many suggestions as there are hits
await page.$eval('.ap-suggestion', $suggestion => {
$suggestion.click();
});

const value = await page.evaluate(`window.placesAutocomplete.getVal()`);
expect(value).toMatch(`55 Rue d'Amsterdam`);
});

it('exposes a working configure method', async () => {
const pendingXHR = new PendingXHR(page);
// Places instance should have a .configure method
Expand Down Expand Up @@ -514,6 +534,26 @@ describe('releases', () => {
expect(allMatching).toBeTruthy();
});

it('getVal returns the value of the input', async () => {
const pendingXHR = new PendingXHR(page);
await page.focus('#search-box');
const query = `55 rue d'Amsterd`;
await page.keyboard.type(query);

// Places should send a query per character typed
expect(pendingXHR.pendingXhrCount()).toEqual(query.length);

await pendingXHR.waitForAllXhrFinished();

// Places suggestion dropdown should have has many suggestions as there are hits
await page.$eval('.ap-suggestion', $suggestion => {
$suggestion.click();
});

const value = await page.evaluate(`window.placesAutocomplete.getVal()`);
expect(value).toMatch(`55 Rue d'Amsterdam`);
});

it('exposes a working configure method', async () => {
const pendingXHR = new PendingXHR(page);
// Places instance should have a .configure method
Expand Down Expand Up @@ -666,6 +706,26 @@ describe('releases', () => {
expect(allMatching).toBeTruthy();
});

it('getVal returns the value of the input', async () => {
const pendingXHR = new PendingXHR(page);
await page.focus('#search-box');
const query = `55 rue d'Amsterd`;
await page.keyboard.type(query);

// Places should send a query per character typed
expect(pendingXHR.pendingXhrCount()).toEqual(query.length);

await pendingXHR.waitForAllXhrFinished();

// Places suggestion dropdown should have has many suggestions as there are hits
await page.$eval('.ap-suggestion', $suggestion => {
$suggestion.click();
});

const value = await page.evaluate(`window.placesAutocomplete.getVal()`);
expect(value).toMatch(`55 Rue d'Amsterdam`);
});

it('exposes a working configure method', async () => {
const pendingXHR = new PendingXHR(page);
// Places instance should have a .configure method
Expand Down
Loading