Skip to content

Commit

Permalink
Merge pull request Dogfalo#64 from tomwjerry/pr-upgrade-testing-frame…
Browse files Browse the repository at this point in the history
…work
  • Loading branch information
DanielRuf authored Feb 26, 2021
2 parents 3ff127b + d49b248 commit 0bd1bed
Show file tree
Hide file tree
Showing 17 changed files with 820 additions and 530 deletions.
52 changes: 46 additions & 6 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ module.exports = function(grunt) {
src: ['bin/materialize.js'],
options: {
vendor: [
'node_modules/jquery/dist/jquery.min.js',
'node_modules/jasmine-jquery/lib/jasmine-jquery.js'
'node_modules/jquery/dist/jquery.min.js'
],
styles: 'bin/materialize.css',
specs: 'tests/spec/**/*Spec.js',
helpers: 'tests/spec/helper.js',
keepRunner: true
//helpers: 'test/spec/*.js'
keepRunner: true,
page: {
viewportSize: {
width: 1400,
height: 735
}
},
sandboxArgs: {
args: ['--headless', '--no-sandbox']
},
}
}
},
Expand Down Expand Up @@ -105,7 +112,8 @@ module.exports = function(grunt) {
'transform-es2015-block-scoping',
'transform-es2015-classes',
'transform-es2015-template-literals',
'transform-es2015-object-super'
'transform-es2015-object-super',
'babel-plugin-transform-object-rest-spread'
]
},
bin: {
Expand Down Expand Up @@ -605,7 +613,27 @@ module.exports = function(grunt) {
ignore: true
}
}
},

connect: {
server: {
options: {
port: 9001,
protocol: 'http',
middleware: function(connect, options, middlewares) {
middlewares.unshift(function(req, res, next){
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Credentials', true);
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
next();
});
return middlewares
}
}
}
}

};

grunt.initConfig(config);
Expand All @@ -628,6 +656,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('grunt-postcss');
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-contrib-connect');

// define the tasks
grunt.registerTask('release', [
Expand Down Expand Up @@ -666,5 +695,16 @@ module.exports = function(grunt) {
]);
grunt.registerTask('server', ['browserSync', 'notify:server']);
grunt.registerTask('monitor', ['concurrent:monitor']);
grunt.registerTask('travis', ['js_compile', 'sass_compile', 'jasmine']);
grunt.registerTask('travis', ['js_compile', 'sass_compile', 'connect', 'jasmine']);
grunt.registerTask('jas_test', ['connect', 'jasmine']);
grunt.registerTask('test_repeat', function(){
const tasks = ['connect'];
const n = 30;
for (let i = 0; i < n; i++) {
tasks.push('jasmine');
}

grunt.task.run(tasks);

});
};
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"engine": "node >= 6",
"devDependencies": {
"autoprefixer": "^7.1.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"grunt": "^1.0.1",
"grunt-babel": "^6.0.0",
Expand All @@ -40,8 +41,9 @@
"grunt-contrib-clean": "^1.1.0",
"grunt-contrib-compress": "^1.4.1",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-connect": "^3.0.0",
"grunt-contrib-jade": "^1.0.0",
"grunt-contrib-jasmine": "^1.1.0",
"grunt-contrib-jasmine": "^2.2.0",
"grunt-contrib-uglify": "^3.0.1",
"grunt-contrib-watch": "^1.0.0",
"grunt-notify": "^0.4.5",
Expand All @@ -51,8 +53,7 @@
"grunt-sass": "^2.0.0",
"grunt-text-replace": "^0.4.0",
"husky": "^0.14.3",
"jasmine": "^2.6.0",
"jasmine-jquery": "^2.1.1",
"jasmine": "^3.6.0",
"jquery": "^3.2.1",
"lint-staged": "^7.0.5",
"node-archiver": "^0.3.0",
Expand Down
79 changes: 40 additions & 39 deletions tests/spec/autocomplete/autocompleteSpec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
describe("Autocomplete Plugin", function () {
beforeEach(function(done) {
loadFixtures('autocomplete/autocompleteFixture.html');
beforeEach(async function(done) {
await XloadFixtures(['autocomplete/autocompleteFixture.html']);
setTimeout(function() {
$('input.autocomplete').autocomplete({
M.Autocomplete.init(
document.querySelectorAll('input.autocomplete'),
{
data: {
"Apple": null,
"Microsoft": null,
Expand All @@ -12,87 +14,86 @@ describe("Autocomplete Plugin", function () {
done();
}, 400);
});
afterEach(function(){
XunloadFixtures();
});

describe("Autocomplete", function () {
// var browserSelect, normalInput, normalDropdown;
// let browserSelect, normalInput, normalDropdown;

// beforeEach(function() {
// browserSelect = $('select.normal');
// });

it("should work with multiple initializations", function (done) {
var $normal = $('#normal-autocomplete');
var $parent = $normal.parent();
let normal = document.querySelector('#normal-autocomplete');
setTimeout(function() {
$normal.autocomplete({ data: {"hi": null} });
$normal.autocomplete({ data: {"hi": null} });
$normal.autocomplete({ data: {"hi": null} });
$normal.autocomplete({
M.Autocomplete.init(normal, { "hi": null });
M.Autocomplete.init(normal, { "hi": null });
M.Autocomplete.init(normal, { "hi": null });
M.Autocomplete.init(normal, {
data: {
"Apple": null,
"Microsoft": null,
"Google": 'http://placehold.it/250x250'
}
});

var $autocompleteEl = $parent.find('.autocomplete-content');
let autocompleteEl = normal.parentNode.querySelectorAll('.autocomplete-content');

expect($autocompleteEl.length).toEqual(1, 'Should dynamically generate autocomplete structure.');
expect(autocompleteEl.length).toEqual(1, 'Should dynamically generate autocomplete structure.');
done();
}, 400);
});

it("should limit results if option is set", function (done) {
var $limited = $('#limited-autocomplete');
var data = {};
for (var i = 100; i >= 0; i--) {
var randString = 'a' + Math.random().toString(36).substring(2);
let limited = document.querySelector('#limited-autocomplete');
let data = {};
for (let i = 100; i >= 0; i--) {
let randString = 'a' + Math.random().toString(36).substring(2);
data[randString] = null;
}

$limited.autocomplete({
data: data,
limit: 20
});
let limitedInstance = M.Autocomplete.getInstance(limited);
limitedInstance.updateData(data);
limitedInstance.options.limit = 20;

$limited.focus();
$limited.val('a');
keyup($limited[0], 65);
focus(limited);
limited.value = 'a';
keyup(limited, 65);

setTimeout(function() {
var $autocompleteEl = $(M.Autocomplete.getInstance($limited[0]).container);
expect($autocompleteEl.children().length).toEqual(20, 'Results should be at max the set limit');
let autocompleteEl = limitedInstance.container;
expect(autocompleteEl.children.length).toEqual(20, 'Results should be at max the set limit');
done();
}, 200);

});

it("should open correctly from typing", function (done) {
var $normal = $('#normal-autocomplete');
var $parent = $normal.parent();
var $autocompleteEl = $normal.parent().find('.autocomplete-content');
let normal = document.querySelector('#normal-autocomplete');
let autocompleteEl = normal.parentNode.querySelector('.autocomplete-content');

$normal.focus();
$normal.val('e');
keyup($normal[0], 69);
focus(normal);
normal.value = 'e';
keyup(normal, 69);

setTimeout(function() {
expect($autocompleteEl.children().length).toEqual(2, 'Results should show dropdown on text input');
expect(autocompleteEl.children.length).toEqual(2, 'Results should show dropdown on text input');
done();
}, 200);
});

it("should open correctly from keyboard focus", function (done) {
var $normal = $('#normal-autocomplete');
var $parent = $normal.parent();
var $autocompleteEl = $normal.parent().find('.autocomplete-content');
let normal = document.querySelector('#normal-autocomplete');
let autocompleteEl = normal.parentNode. querySelector('.autocomplete-content');

$normal.val('e');
keyup($normal[0], 9);
focus($normal[0]);
normal.value = 'e';
keyup(normal, 9);
focus(normal);

setTimeout(function() {
expect($autocompleteEl.children().length).toEqual(2, 'Results should show dropdown on text input');
expect(autocompleteEl.children.length).toEqual(2, 'Results should show dropdown on text input');
done();
}, 200);
});
Expand Down
Loading

0 comments on commit 0bd1bed

Please sign in to comment.