Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…not set
- Loading branch information
1 parent
b0e985b
commit ba694cd
Showing
3 changed files
with
117 additions
and
4 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,114 @@ | ||
const $ = require('jquery'); | ||
const Typeahead = require('../../src/jquery.typeahead'); | ||
|
||
describe('Typeahead groupOrder option Tests', () => { | ||
'use strict'; | ||
|
||
let myTypeahead; | ||
|
||
describe('groupOrder defined as desc', () => { | ||
beforeAll(() => { | ||
document.body.innerHTML = '<input class="js-typeahead">'; | ||
|
||
myTypeahead = $.typeahead({ | ||
input: '.js-typeahead', | ||
minLength: 0, | ||
group: 'category', | ||
groupOrder: 'desc', | ||
display: 'name', | ||
source: { | ||
myGroup: { | ||
data: [{ category: 'Arizona', id: '1', name: 'Phil' }, { category: 'Indiana', id: '3', name: 'George' }], | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('Should have 1 group and contain 2 items ordered DESC', () => { | ||
expect(myTypeahead.groupBy).toEqual('category'); | ||
|
||
myTypeahead.node.val('').trigger('input'); | ||
|
||
expect(myTypeahead.groups).toEqual(['Indiana', 'Arizona']); | ||
expect(myTypeahead.resultCountPerGroup).toEqual({ Indiana: 1, Arizona: 1 }); | ||
|
||
expect(myTypeahead.result[0]).toEqual({ | ||
matchedKey: 'name', | ||
category: 'Indiana', | ||
id: '3', | ||
name: 'George', | ||
group: 'myGroup', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('groupOrder defined as a boolean', () => { | ||
beforeAll(() => { | ||
document.body.innerHTML = '<input class="js-typeahead">'; | ||
|
||
myTypeahead = $.typeahead({ | ||
input: '.js-typeahead', | ||
minLength: 0, | ||
group: 'category', | ||
groupOrder: true, | ||
display: 'name', | ||
source: { | ||
myGroup: { | ||
data: [{ category: 'Arizona', id: '1', name: 'Phil' }, { category: 'Indiana', id: '3', name: 'George' }], | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('Should have 1 group and contain 2 items ordered ASC', () => { | ||
expect(myTypeahead.groupBy).toEqual('category'); | ||
|
||
myTypeahead.node.val('').trigger('input'); | ||
|
||
expect(myTypeahead.groups).toEqual(['Arizona', 'Indiana']); | ||
expect(myTypeahead.resultCountPerGroup).toEqual({ Arizona: 1, Indiana: 1 }); | ||
expect(myTypeahead.result[0]).toEqual({ | ||
matchedKey: 'name', | ||
category: 'Arizona', | ||
id: '1', | ||
name: 'Phil', | ||
group: 'myGroup', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('groupOrder defined as an Array', () => { | ||
beforeAll(() => { | ||
document.body.innerHTML = '<input class="js-typeahead">'; | ||
|
||
myTypeahead = $.typeahead({ | ||
input: '.js-typeahead', | ||
minLength: 0, | ||
group: 'category', | ||
groupOrder: ['Indiana', 'Arizona'], | ||
display: 'name', | ||
source: { | ||
myGroup: { | ||
data: [{ category: 'Arizona', id: '1', name: 'Phil' }, { category: 'Indiana', id: '3', name: 'George' }], | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('Should have 1 group and contain 2 items', () => { | ||
expect(myTypeahead.groupBy).toEqual('category'); | ||
|
||
myTypeahead.node.val('').trigger('input'); | ||
|
||
expect(myTypeahead.groups).toEqual(['Indiana', 'Arizona']); | ||
expect(myTypeahead.resultCountPerGroup).toEqual({ Indiana: 1, Arizona: 1 }); | ||
expect(myTypeahead.result[0]).toEqual({ | ||
matchedKey: 'name', | ||
category: 'Indiana', | ||
id: '3', | ||
name: 'George', | ||
group: 'myGroup', | ||
}); | ||
}); | ||
}); | ||
}); |