forked from json-editor/json-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request json-editor#1136 from germanbisurgi/feature/autoco…
…mplete-test Fix for autocomplete (json-editor#1124) + test
- Loading branch information
Showing
4 changed files
with
93 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* global Feature Scenario */ | ||
|
||
var assert = require('assert') | ||
|
||
Feature('autocomplete') | ||
|
||
Scenario('autocomplete should work @autocomplete', async (I) => { | ||
I.amOnPage('autocomplete.html') | ||
I.waitForElement('.je-ready', 10) | ||
I.fillField('root', 'ir') | ||
I.waitForText('iran', 10, '.autocomplete-result-list') | ||
I.waitForText('iraq', 10, '.autocomplete-result-list') | ||
I.click('iraq', '.autocomplete-result:nth-child(2)') | ||
I.wait(1) | ||
assert.equal(await I.grabValueFrom('.value'), '"iraq"') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"/> | ||
<title>Autocomplete</title> | ||
<link rel="stylesheet" id="theme-link" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"> | ||
<link rel="stylesheet" id="iconlib-link" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css"> | ||
<script src="https://unpkg.com/@trevoreyre/autocomplete-js"></script> | ||
<script src="../../dist/jsoneditor.js"></script> | ||
</head> | ||
<body> | ||
|
||
<div class="container"> | ||
<textarea class="value form-control" rows="10"></textarea> | ||
<div class='json-editor-container'></div> | ||
</div> | ||
|
||
|
||
<script> | ||
window.addEventListener('load', function () { | ||
var jsonEditorContainer = document.querySelector('.json-editor-container') | ||
var value = document.querySelector('.value') | ||
|
||
JSONEditor.defaults.callbacks = { | ||
'autocomplete': { | ||
'search': function (editor, input) { | ||
var countries = [ | ||
'germany', | ||
'iran', | ||
'iraq', | ||
'spain' | ||
] | ||
|
||
if (input.length < 1) { return [] } | ||
|
||
return countries.filter(country => { | ||
return country.toLowerCase().startsWith(input.toLowerCase()) | ||
}) | ||
} | ||
} | ||
} | ||
|
||
var schema = { | ||
'title': 'Test', | ||
'type': 'string', | ||
'format': 'autocomplete', | ||
'options': { | ||
'autocomplete': { | ||
'search': 'search', | ||
'autoSelect': true | ||
} | ||
} | ||
} | ||
|
||
var editor = new JSONEditor(jsonEditorContainer, { | ||
schema: schema, | ||
theme: 'bootstrap4', | ||
required_by_default: true, | ||
show_errors: 'always' | ||
}) | ||
|
||
editor.on('change', function () { | ||
value.value = JSON.stringify(editor.getValue()) | ||
}) | ||
}) | ||
</script> | ||
|
||
</body> | ||
</html> |