|
@@ -60,6 +60,53 @@ describe("The nickname autocomplete feature", function () {
|
|
done();
|
|
done();
|
|
}));
|
|
}));
|
|
|
|
|
|
|
|
+ it("should order by query index position and length", mock.initConverse(
|
|
|
|
+ ['rosterGroupsFetched', 'chatBoxesFetched'], {}, async function (done, _converse) {
|
|
|
|
+ await mock.openAndEnterChatRoom(_converse, 'lounge@montague.lit', 'tom');
|
|
|
|
+ const view = _converse.chatboxviews.get('lounge@montague.lit');
|
|
|
|
+
|
|
|
|
+ // Nicknames from presences
|
|
|
|
+ ['bernard', 'naber', 'helberlo', 'john', 'jones'].forEach((nick) => {
|
|
|
|
+ _converse.connection._dataRecv(mock.createRequest(
|
|
|
|
+ $pres({
|
|
|
|
+ 'to': 'tom@montague.lit/resource',
|
|
|
|
+ 'from': `lounge@montague.lit/${nick}`
|
|
|
|
+ })
|
|
|
|
+ .c('x', { xmlns: Strophe.NS.MUC_USER })
|
|
|
|
+ .c('item', {
|
|
|
|
+ 'affiliation': 'none',
|
|
|
|
+ 'jid': `${nick}@montague.lit/resource`,
|
|
|
|
+ 'role': 'participant'
|
|
|
|
+ })));
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ const textarea = view.el.querySelector('textarea.chat-textarea');
|
|
|
|
+ const at_event = {
|
|
|
|
+ 'target': textarea,
|
|
|
|
+ 'preventDefault': function preventDefault() { },
|
|
|
|
+ 'stopPropagation': function stopPropagation() { },
|
|
|
|
+ 'keyCode': 50,
|
|
|
|
+ 'key': '@'
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ // Test that results are sorted by query index
|
|
|
|
+ view.onKeyDown(at_event);
|
|
|
|
+ textarea.value = '@ber';
|
|
|
|
+ view.onKeyUp(at_event);
|
|
|
|
+ await u.waitUntil(() => view.el.querySelectorAll('.suggestion-box__results li').length === 3);
|
|
|
|
+ expect(view.el.querySelector('.suggestion-box__results li:first-child').textContent).toBe('bernard');
|
|
|
|
+ expect(view.el.querySelector('.suggestion-box__results li:nth-child(2)').textContent).toBe('naber');
|
|
|
|
+ expect(view.el.querySelector('.suggestion-box__results li:nth-child(3)').textContent).toBe('helberlo');
|
|
|
|
+
|
|
|
|
+ // Test that when the query index is equal, results should be sorted by length
|
|
|
|
+ textarea.value = '@jo';
|
|
|
|
+ view.onKeyUp(at_event);
|
|
|
|
+ await u.waitUntil(() => view.el.querySelectorAll('.suggestion-box__results li').length === 2);
|
|
|
|
+ expect(view.el.querySelector('.suggestion-box__results li:first-child').textContent).toBe('john');
|
|
|
|
+ expect(view.el.querySelector('.suggestion-box__results li:nth-child(2)').textContent).toBe('jones');
|
|
|
|
+ done();
|
|
|
|
+ }));
|
|
|
|
+
|
|
it("autocompletes when the user presses tab",
|
|
it("autocompletes when the user presses tab",
|
|
mock.initConverse(
|
|
mock.initConverse(
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|