Skip to content

Commit c0d04ff

Browse files
author
tombertrand
committed
Format test files
1 parent f716f3d commit c0d04ff

36 files changed

+3951
-3808
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"name": "jquery-typeahead",
33
"version": "2.10.7",
4-
"description": "jQuery plugin that provides Typeahead (autocomplete) Search preview from Json object(s) via same domain Ajax request or cross domain Jsonp and offers data compression inside Local Storage. The plugin is built with a lot of options and callbacks to allow customization.",
4+
"description":
5+
"jQuery plugin that provides Typeahead (autocomplete) Search preview from Json object(s) via same domain Ajax request or cross domain Jsonp and offers data compression inside Local Storage. The plugin is built with a lot of options and callbacks to allow customization.",
56
"author": {
67
"name": "Tom Bertrand"
78
},
@@ -51,8 +52,7 @@
5152
"test": "jest"
5253
},
5354
"jest": {
54-
"setupFiles": [
55-
"<rootDir>/test/jestSetupFile.js"
56-
]
55+
"testURL": "http://localhost/",
56+
"setupFiles": ["<rootDir>/test/jestSetupFile.js"]
5757
}
5858
}
Lines changed: 74 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,74 @@
1-
const $ = require("jquery");
2-
const Typeahead = require('../../src/jquery.typeahead');
3-
4-
describe('Typeahead $.ajax.callback.done Tests', () => {
5-
6-
let myTypeahead;
7-
8-
beforeAll(() => {
9-
10-
document.body.innerHTML = '<input class="js-typeahead">';
11-
12-
myTypeahead = $.typeahead({
13-
input: ".js-typeahead",
14-
minLength: 0,
15-
order: "asc",
16-
group: true,
17-
blurOnTab: false,
18-
maxItemPerGroup: 3,
19-
hint: true,
20-
dynamic: true,
21-
source: {
22-
group1: {
23-
ajax: {
24-
type: "GET",
25-
url: "http://test.com/groups.json",
26-
data: {
27-
term: "{{query}}"
28-
},
29-
callback: {
30-
done: function (data) {
31-
return data.group1;
32-
}
33-
}
34-
}
35-
},
36-
group2: {
37-
ajax: {
38-
type: "GET",
39-
url: "http://test.com/groups.json",
40-
data: {
41-
term: "{{query}}"
42-
},
43-
callback: {
44-
done: function (data) {
45-
data.group2.shift();
46-
return data.group2;
47-
}
48-
}
49-
}
50-
},
51-
},
52-
});
53-
});
54-
55-
it('Should display the modified data 2 different groups', (done) => {
56-
57-
myTypeahead.node.triggerHandler('input').done(function () {
58-
59-
var hasDuplicatedData = false;
60-
var tmpResult = [];
61-
var stringifiedResult;
62-
63-
for (let i = 0, ii = myTypeahead.result.length; i < ii; ++i) {
64-
stringifiedResult = JSON.stringify(myTypeahead.result[i]);
65-
if (~tmpResult.indexOf(stringifiedResult)) {
66-
hasDuplicatedData = true;
67-
break;
68-
}
69-
tmpResult.push(stringifiedResult);
70-
}
71-
72-
expect(myTypeahead.result.length).toEqual(5);
73-
expect(hasDuplicatedData).toBeFalsy();
74-
75-
done()
76-
});
77-
78-
});
79-
80-
});
1+
const $ = require("jquery");
2+
const Typeahead = require("../../src/jquery.typeahead");
3+
4+
describe("Typeahead $.ajax.callback.done Tests", () => {
5+
let myTypeahead;
6+
7+
beforeAll(() => {
8+
document.body.innerHTML = '<input class="js-typeahead">';
9+
10+
myTypeahead = $.typeahead({
11+
input: ".js-typeahead",
12+
minLength: 0,
13+
order: "asc",
14+
group: true,
15+
blurOnTab: false,
16+
maxItemPerGroup: 3,
17+
hint: true,
18+
dynamic: true,
19+
source: {
20+
group1: {
21+
ajax: {
22+
type: "GET",
23+
url: "http://test.com/groups.json",
24+
data: {
25+
term: "{{query}}"
26+
},
27+
callback: {
28+
done: function(data) {
29+
return data.group1;
30+
}
31+
}
32+
}
33+
},
34+
group2: {
35+
ajax: {
36+
type: "GET",
37+
url: "http://test.com/groups.json",
38+
data: {
39+
term: "{{query}}"
40+
},
41+
callback: {
42+
done: function(data) {
43+
data.group2.shift();
44+
return data.group2;
45+
}
46+
}
47+
}
48+
}
49+
}
50+
});
51+
});
52+
53+
it("Should display the modified data 2 different groups", done => {
54+
myTypeahead.node.triggerHandler("input").done(function() {
55+
var hasDuplicatedData = false;
56+
var tmpResult = [];
57+
var stringifiedResult;
58+
59+
for (let i = 0, ii = myTypeahead.result.length; i < ii; ++i) {
60+
stringifiedResult = JSON.stringify(myTypeahead.result[i]);
61+
if (~tmpResult.indexOf(stringifiedResult)) {
62+
hasDuplicatedData = true;
63+
break;
64+
}
65+
tmpResult.push(stringifiedResult);
66+
}
67+
68+
expect(myTypeahead.result.length).toEqual(5);
69+
expect(hasDuplicatedData).toBeFalsy();
70+
71+
done();
72+
});
73+
});
74+
});
Lines changed: 88 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,88 @@
1-
const $ = require("jquery");
2-
const Typeahead = require('../../src/jquery.typeahead');
3-
4-
describe('Typeahead can not display null or boolean if the item is a string', () => {
5-
'use strict';
6-
7-
let myTypeahead;
8-
9-
beforeAll(() => {
10-
11-
document.body.innerHTML = '<input class="js-typeahead">';
12-
13-
myTypeahead = $.typeahead({
14-
input: '.js-typeahead',
15-
minLength: 0,
16-
generateOnLoad: true,
17-
source: {
18-
data: [null, false, true, "null", "false", "true"]
19-
}
20-
});
21-
});
22-
23-
it('Should display any value types', () => {
24-
myTypeahead.node.trigger('input');
25-
26-
expect(myTypeahead.result.length).toEqual(3);
27-
});
28-
});
29-
30-
describe('Typeahead can display any value type Tests from inside an object', () => {
31-
'use strict';
32-
33-
let myTypeahead;
34-
35-
beforeAll(() => {
36-
37-
document.body.innerHTML = '<input class="js-typeahead">';
38-
39-
myTypeahead = $.typeahead({
40-
input: '.js-typeahead',
41-
minLength: 0,
42-
generateOnLoad: true,
43-
display: ['string','numeric', 'booleanT', 'booleanF', 'undefined', 'deeper.key.level'],
44-
source: {
45-
data: [{
46-
string: 'string',
47-
numeric: 12345,
48-
booleanT: true,
49-
booleanF: false,
50-
deeper: {
51-
key: {
52-
level: 42
53-
}
54-
}
55-
}]
56-
}
57-
});
58-
});
59-
60-
it('Should display any value types', () => {
61-
myTypeahead.node.trigger('input');
62-
63-
expect(myTypeahead.resultHtml.find('span').text()).toEqual('string 12345 true false 42');
64-
});
65-
66-
it('Should display a boolean "false" search', () => {
67-
myTypeahead.node.val('false');
68-
myTypeahead.node.trigger('input');
69-
70-
expect(myTypeahead.result.length).toEqual(1);
71-
});
72-
73-
it('Should display a numeric value', () => {
74-
myTypeahead.node.val('345');
75-
myTypeahead.node.trigger('input');
76-
77-
expect(myTypeahead.result.length).toEqual(1);
78-
});
79-
});
1+
const $ = require("jquery");
2+
const Typeahead = require("../../src/jquery.typeahead");
3+
4+
describe("Typeahead can not display null or boolean if the item is a string", () => {
5+
"use strict";
6+
7+
let myTypeahead;
8+
9+
beforeAll(() => {
10+
document.body.innerHTML = '<input class="js-typeahead">';
11+
12+
myTypeahead = $.typeahead({
13+
input: ".js-typeahead",
14+
minLength: 0,
15+
generateOnLoad: true,
16+
source: {
17+
data: [null, false, true, "null", "false", "true"]
18+
}
19+
});
20+
});
21+
22+
it("Should display any value types", () => {
23+
myTypeahead.node.trigger("input");
24+
25+
expect(myTypeahead.result.length).toEqual(3);
26+
});
27+
});
28+
29+
describe("Typeahead can display any value type Tests from inside an object", () => {
30+
"use strict";
31+
32+
let myTypeahead;
33+
34+
beforeAll(() => {
35+
document.body.innerHTML = '<input class="js-typeahead">';
36+
37+
myTypeahead = $.typeahead({
38+
input: ".js-typeahead",
39+
minLength: 0,
40+
generateOnLoad: true,
41+
display: [
42+
"string",
43+
"numeric",
44+
"booleanT",
45+
"booleanF",
46+
"undefined",
47+
"deeper.key.level"
48+
],
49+
source: {
50+
data: [
51+
{
52+
string: "string",
53+
numeric: 12345,
54+
booleanT: true,
55+
booleanF: false,
56+
deeper: {
57+
key: {
58+
level: 42
59+
}
60+
}
61+
}
62+
]
63+
}
64+
});
65+
});
66+
67+
it("Should display any value types", () => {
68+
myTypeahead.node.trigger("input");
69+
70+
expect(myTypeahead.resultHtml.find("span").text()).toEqual(
71+
"string 12345 true false 42"
72+
);
73+
});
74+
75+
it('Should display a boolean "false" search', () => {
76+
myTypeahead.node.val("false");
77+
myTypeahead.node.trigger("input");
78+
79+
expect(myTypeahead.result.length).toEqual(1);
80+
});
81+
82+
it("Should display a numeric value", () => {
83+
myTypeahead.node.val("345");
84+
myTypeahead.node.trigger("input");
85+
86+
expect(myTypeahead.result.length).toEqual(1);
87+
});
88+
});

0 commit comments

Comments
 (0)