Skip to content

Commit

Permalink
fix(provider): improve ordering of suggestions (#156)
Browse files Browse the repository at this point in the history
* fix(provider): improve ordering of suggestions

Fixes #143

* test(providers): updated tests for ordering changes

* fix(providers): assign to prop, dont check equality
  • Loading branch information
longton95 committed Jul 15, 2019
1 parent b499d45 commit 59bb539
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 56 deletions.
17 changes: 5 additions & 12 deletions lib/providers/autoCompleteHelper.js
Expand Up @@ -24,18 +24,7 @@ export default {
let aStr = a.text || a.displayText || a.snippet || '';
let bStr = b.text || b.displayText || b.snippet || '';

// return bStr.toLowerCase() - aStr.toLowerCase();
aStr = aStr.toLowerCase();
bStr = bStr.toLowerCase();

let res = 0;
if (aStr < bStr) {
res = -1;
} else if (aStr > bStr) {
res = 1;
}

return res;
return aStr.length - bStr.length;
}
},

Expand Down Expand Up @@ -270,6 +259,10 @@ export default {

propertyNamesOfType.push(prop.name);

if (prop.deprecated) {
prop.name += '|deprecated';
}

// property name
if (props[prop.name]) { // if duplicated property name - merge available values
Object.assign(props[prop.name], {
Expand Down
54 changes: 29 additions & 25 deletions spec/styleAutoCompleteProvider-spec.js
Expand Up @@ -44,23 +44,24 @@ describe('Tag suggestions', function () {
const suggestions = getSuggestions('W');

expect(suggestions.length).to.equal(4);

expect(suggestions[0].type).to.equal('tag');
expect(suggestions[0].text).to.equal('WebView');
expect(suggestions[0].rightLabel).to.equal('Ti.UI.WebView');
expect(suggestions[0].description).to.equal('Ti.UI.WebView: The web view allows you to open an HTML5 based view which can load either local or remote content.');
expect(suggestions[0].descriptionMoreURL).to.equal('http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.WebView');
expect(suggestions[0].text).to.equal('Widget');
expect(suggestions[0].rightLabel).to.equal('Alloy.Widget');
expect(suggestions[0].description).to.equal('Alloy.Widget: Widgets are self-contained components that can be easily dropped into an Alloy project.');
expect(suggestions[0].descriptionMoreURL).to.equal('http://docs.appcelerator.com/platform/latest/#!/api/Alloy.Widget');

expect(suggestions[1].type).to.equal('tag');
expect(suggestions[1].text).to.equal('Widget');
expect(suggestions[1].rightLabel).to.equal('Alloy.Widget');
expect(suggestions[1].description).to.equal('Alloy.Widget: Widgets are self-contained components that can be easily dropped into an Alloy project.');
expect(suggestions[1].descriptionMoreURL).to.equal('http://docs.appcelerator.com/platform/latest/#!/api/Alloy.Widget');
expect(suggestions[1].text).to.equal('Window');
expect(suggestions[1].rightLabel).to.equal('Ti.UI.Window');
expect(suggestions[1].description).to.equal('Ti.UI.Window: The Window is an empty drawing surface or container.');
expect(suggestions[1].descriptionMoreURL).to.equal('http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.Window');

expect(suggestions[2].type).to.equal('tag');
expect(suggestions[2].text).to.equal('Window');
expect(suggestions[2].rightLabel).to.equal('Ti.UI.Window');
expect(suggestions[2].description).to.equal('Ti.UI.Window: The Window is an empty drawing surface or container.');
expect(suggestions[2].descriptionMoreURL).to.equal('http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.Window');
expect(suggestions[2].text).to.equal('WebView');
expect(suggestions[2].rightLabel).to.equal('Ti.UI.WebView');
expect(suggestions[2].description).to.equal('Ti.UI.WebView: The web view allows you to open an HTML5 based view which can load either local or remote content.');
expect(suggestions[2].descriptionMoreURL).to.equal('http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.WebView');

expect(suggestions[3].type).to.equal('tag');
expect(suggestions[3].text).to.equal('WindowToolbar');
Expand Down Expand Up @@ -91,17 +92,18 @@ describe('Property suggestions', function () {

initTextEditor('"#id":{s');
const suggestions = getSuggestions('s');

expect(suggestions[0].type).to.equal('property');
expect(suggestions[0].displayText).to.equal('SATELLITE_TYPE');
expect(suggestions[0].snippet).to.equal('SATELLITE_TYPE: ');
expect(suggestions[0].displayText).to.equal('style');
expect(suggestions[0].snippet).to.equal('style: ');

expect(suggestions[1].type).to.equal('property');
expect(suggestions[1].displayText).to.equal('saveToPhotoGallery');
expect(suggestions[1].snippet).to.equal('saveToPhotoGallery: ');
expect(suggestions[1].displayText).to.equal('speed');
expect(suggestions[1].snippet).to.equal('speed: ');

expect(suggestions[2].type).to.equal('property');
expect(suggestions[2].displayText).to.equal('scale');
expect(suggestions[2].snippet).to.equal('scale: ');
expect(suggestions[2].displayText).to.equal('sound');
expect(suggestions[2].snippet).to.equal('sound: ');
});

it('should provide correct snippet for object types', function () {
Expand Down Expand Up @@ -152,10 +154,10 @@ describe('Property suggestions', function () {
expect(suggestions.length).to.equal(2);

expect(suggestions[0].type).to.equal('value');
expect(suggestions[0].text).to.equal('magenta');
expect(suggestions[0].text).to.equal('maroon');

expect(suggestions[1].type).to.equal('value');
expect(suggestions[1].text).to.equal('maroon');
expect(suggestions[1].text).to.equal('magenta');
});

it('should provide color values without quotes', function () {
Expand All @@ -167,10 +169,11 @@ describe('Property suggestions', function () {
expect(suggestions.length).to.equal(2);

expect(suggestions[0].type).to.equal('value');
expect(suggestions[0].text).to.equal('\'magenta\'');
expect(suggestions[0].text).to.equal('\'maroon\'');

expect(suggestions[1].type).to.equal('value');
expect(suggestions[1].text).to.equal('\'maroon\'');
expect(suggestions[1].text).to.equal('\'magenta\'');

});

it('should provide layout values', function () {
Expand All @@ -182,12 +185,13 @@ describe('Property suggestions', function () {
expect(suggestions.length).to.equal(3);

expect(suggestions[0].type).to.equal('value');
expect(suggestions[0].text).to.equal('\'composite\'');
expect(suggestions[0].text).to.equal('\'vertical\'');

expect(suggestions[1].type).to.equal('value');
expect(suggestions[1].text).to.equal('\'horizontal\'');
expect(suggestions[1].text).to.equal('\'composite\'');

expect(suggestions[2].type).to.equal('value');
expect(suggestions[2].text).to.equal('\'vertical\'');
expect(suggestions[2].text).to.equal('\'horizontal\'');

});
});
38 changes: 19 additions & 19 deletions spec/viewAutoCompleteProvider-spec.js
Expand Up @@ -47,25 +47,25 @@ describe('Tag suggestions', function () {
expect(suggestions.length).to.equal(4);

expect(suggestions[0].type).to.equal('tag');
expect(suggestions[0].displayText).to.equal('WebView');
expect(suggestions[0].snippet).to.equal('WebView$1>$2</WebView>');
expect(suggestions[0].rightLabel).to.equal('Ti.UI.WebView');
expect(suggestions[0].description).to.equal('Ti.UI.WebView: The web view allows you to open an HTML5 based view which can load either local or remote content.');
expect(suggestions[0].descriptionMoreURL).to.equal('http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.WebView');
expect(suggestions[0].displayText).to.equal('Widget');
expect(suggestions[0].snippet).to.equal('Widget$1>$2</Widget>');
expect(suggestions[0].rightLabel).to.equal('Alloy.Widget');
expect(suggestions[0].description).to.equal('Alloy.Widget: Widgets are self-contained components that can be easily dropped into an Alloy project.');
expect(suggestions[0].descriptionMoreURL).to.equal('http://docs.appcelerator.com/platform/latest/#!/api/Alloy.Widget');

expect(suggestions[1].type).to.equal('tag');
expect(suggestions[1].displayText).to.equal('Widget');
expect(suggestions[1].snippet).to.equal('Widget$1>$2</Widget>');
expect(suggestions[1].rightLabel).to.equal('Alloy.Widget');
expect(suggestions[1].description).to.equal('Alloy.Widget: Widgets are self-contained components that can be easily dropped into an Alloy project.');
expect(suggestions[1].descriptionMoreURL).to.equal('http://docs.appcelerator.com/platform/latest/#!/api/Alloy.Widget');
expect(suggestions[1].displayText).to.equal('Window');
expect(suggestions[1].snippet).to.equal('Window$1>$2</Window>');
expect(suggestions[1].rightLabel).to.equal('Ti.UI.Window');
expect(suggestions[1].description).to.equal('Ti.UI.Window: The Window is an empty drawing surface or container.');
expect(suggestions[1].descriptionMoreURL).to.equal('http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.Window');

expect(suggestions[2].type).to.equal('tag');
expect(suggestions[2].displayText).to.equal('Window');
expect(suggestions[2].snippet).to.equal('Window$1>$2</Window>');
expect(suggestions[2].rightLabel).to.equal('Ti.UI.Window');
expect(suggestions[2].description).to.equal('Ti.UI.Window: The Window is an empty drawing surface or container.');
expect(suggestions[2].descriptionMoreURL).to.equal('http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.Window');
expect(suggestions[2].displayText).to.equal('WebView');
expect(suggestions[2].snippet).to.equal('WebView$1>$2</WebView>');
expect(suggestions[2].rightLabel).to.equal('Ti.UI.WebView');
expect(suggestions[2].description).to.equal('Ti.UI.WebView: The web view allows you to open an HTML5 based view which can load either local or remote content.');
expect(suggestions[2].descriptionMoreURL).to.equal('http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.WebView');

expect(suggestions[3].type).to.equal('tag');
expect(suggestions[3].displayText).to.equal('WindowToolbar');
Expand Down Expand Up @@ -117,10 +117,10 @@ describe('Attribute suggestions', function () {
expect(suggestions.length).to.equal(35);

expect(suggestions[0].type).to.equal('function');
expect(suggestions[0].displayText).to.equal('onAndroidback');
expect(suggestions[0].snippet).to.equal('onAndroidback="$1"$0');
expect(suggestions[0].displayText).to.equal('onOpen');
expect(suggestions[0].snippet).to.equal('onOpen="$1"$0');
expect(suggestions[0].rightLabel).to.equal('Window');
expect(suggestions[0].description).to.equal('Ti.UI.Window: androidback event');
expect(suggestions[0].descriptionMoreURL).to.equal('http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.Window-event-androidback');
expect(suggestions[0].description).to.equal('Ti.UI.Window: open event');
expect(suggestions[0].descriptionMoreURL).to.equal('http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.Window-event-open');
});
});

0 comments on commit 59bb539

Please sign in to comment.