Skip to content

Commit c20afe0

Browse files
committed
Clean changes ready for pr
1 parent f5afea5 commit c20afe0

File tree

16 files changed

+764
-522
lines changed

16 files changed

+764
-522
lines changed

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"engine": "node >= 6",
3232
"devDependencies": {
3333
"autoprefixer": "^7.1.1",
34+
"babel-plugin-transform-object-rest-spread": "^6.26.0",
3435
"babel-preset-es2015": "^6.24.1",
3536
"grunt": "^1.0.1",
3637
"grunt-babel": "^6.0.0",
@@ -40,8 +41,9 @@
4041
"grunt-contrib-clean": "^1.1.0",
4142
"grunt-contrib-compress": "^1.4.1",
4243
"grunt-contrib-concat": "^1.0.1",
44+
"grunt-contrib-connect": "^3.0.0",
4345
"grunt-contrib-jade": "^1.0.0",
44-
"grunt-contrib-jasmine": "^1.1.0",
46+
"grunt-contrib-jasmine": "^2.2.0",
4547
"grunt-contrib-uglify": "^3.0.1",
4648
"grunt-contrib-watch": "^1.0.0",
4749
"grunt-notify": "^0.4.5",
@@ -51,8 +53,7 @@
5153
"grunt-sass": "^2.0.0",
5254
"grunt-text-replace": "^0.4.0",
5355
"husky": "^0.14.3",
54-
"jasmine": "^2.6.0",
55-
"jasmine-jquery": "^2.1.1",
56+
"jasmine": "^3.6.0",
5657
"jquery": "^3.2.1",
5758
"lint-staged": "^7.0.5",
5859
"node-archiver": "^0.3.0",

tests/spec/autocomplete/autocompleteSpec.js

+40-39
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
describe("Autocomplete Plugin", function () {
2-
beforeEach(function(done) {
3-
loadFixtures('autocomplete/autocompleteFixture.html');
2+
beforeEach(async function(done) {
3+
await XloadFixtures(['autocomplete/autocompleteFixture.html']);
44
setTimeout(function() {
5-
$('input.autocomplete').autocomplete({
5+
M.Autocomplete.init(
6+
document.querySelectorAll('input.autocomplete'),
7+
{
68
data: {
79
"Apple": null,
810
"Microsoft": null,
@@ -12,87 +14,86 @@ describe("Autocomplete Plugin", function () {
1214
done();
1315
}, 400);
1416
});
17+
afterEach(function(){
18+
XunloadFixtures();
19+
});
1520

1621
describe("Autocomplete", function () {
17-
// var browserSelect, normalInput, normalDropdown;
22+
// let browserSelect, normalInput, normalDropdown;
1823

1924
// beforeEach(function() {
2025
// browserSelect = $('select.normal');
2126
// });
2227

2328
it("should work with multiple initializations", function (done) {
24-
var $normal = $('#normal-autocomplete');
25-
var $parent = $normal.parent();
29+
let normal = document.querySelector('#normal-autocomplete');
2630
setTimeout(function() {
27-
$normal.autocomplete({ data: {"hi": null} });
28-
$normal.autocomplete({ data: {"hi": null} });
29-
$normal.autocomplete({ data: {"hi": null} });
30-
$normal.autocomplete({
31+
M.Autocomplete.init(normal, { "hi": null });
32+
M.Autocomplete.init(normal, { "hi": null });
33+
M.Autocomplete.init(normal, { "hi": null });
34+
M.Autocomplete.init(normal, {
3135
data: {
3236
"Apple": null,
3337
"Microsoft": null,
3438
"Google": 'http://placehold.it/250x250'
3539
}
3640
});
3741

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

40-
expect($autocompleteEl.length).toEqual(1, 'Should dynamically generate autocomplete structure.');
44+
expect(autocompleteEl.length).toEqual(1, 'Should dynamically generate autocomplete structure.');
4145
done();
4246
}, 400);
4347
});
4448

4549
it("should limit results if option is set", function (done) {
46-
var $limited = $('#limited-autocomplete');
47-
var data = {};
48-
for (var i = 100; i >= 0; i--) {
49-
var randString = 'a' + Math.random().toString(36).substring(2);
50+
let limited = document.querySelector('#limited-autocomplete');
51+
let data = {};
52+
for (let i = 100; i >= 0; i--) {
53+
let randString = 'a' + Math.random().toString(36).substring(2);
5054
data[randString] = null;
5155
}
5256

53-
$limited.autocomplete({
54-
data: data,
55-
limit: 20
56-
});
57+
let limitedInstance = M.Autocomplete.getInstance(limited);
58+
limitedInstance.updateData(data);
59+
limitedInstance.options.limit = 20;
5760

58-
$limited.focus();
59-
$limited.val('a');
60-
keyup($limited[0], 65);
61+
focus(limited);
62+
limited.value = 'a';
63+
keyup(limited, 65);
6164

6265
setTimeout(function() {
63-
var $autocompleteEl = $(M.Autocomplete.getInstance($limited[0]).container);
64-
expect($autocompleteEl.children().length).toEqual(20, 'Results should be at max the set limit');
66+
let autocompleteEl = limitedInstance.container;
67+
expect(autocompleteEl.children.length).toEqual(20, 'Results should be at max the set limit');
6568
done();
6669
}, 200);
6770

6871
});
6972

7073
it("should open correctly from typing", function (done) {
71-
var $normal = $('#normal-autocomplete');
72-
var $parent = $normal.parent();
73-
var $autocompleteEl = $normal.parent().find('.autocomplete-content');
74+
let normal = document.querySelector('#normal-autocomplete');
75+
let autocompleteEl = normal.parentNode.querySelector('.autocomplete-content');
7476

75-
$normal.focus();
76-
$normal.val('e');
77-
keyup($normal[0], 69);
77+
focus(normal);
78+
normal.value = 'e';
79+
keyup(normal, 69);
7880

7981
setTimeout(function() {
80-
expect($autocompleteEl.children().length).toEqual(2, 'Results should show dropdown on text input');
82+
expect(autocompleteEl.children.length).toEqual(2, 'Results should show dropdown on text input');
8183
done();
8284
}, 200);
8385
});
8486

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

90-
$normal.val('e');
91-
keyup($normal[0], 9);
92-
focus($normal[0]);
91+
normal.value = 'e';
92+
keyup(normal, 9);
93+
focus(normal);
9394

9495
setTimeout(function() {
95-
expect($autocompleteEl.children().length).toEqual(2, 'Results should show dropdown on text input');
96+
expect(autocompleteEl.children.length).toEqual(2, 'Results should show dropdown on text input');
9697
done();
9798
}, 200);
9899
});

tests/spec/cards/cardsSpec.js

+66-48
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
describe( "Cards", function () {
2-
var reveal;
2+
beforeEach(async function() {
3+
await XloadFixtures(['cards/cardsFixture.html']);
4+
});
35

4-
beforeEach(function() {
5-
loadFixtures('cards/cardsFixture.html');
6+
afterEach(function(){
7+
XunloadFixtures();
68
});
79

810
describe("reveal cards", function () {
9-
var revealCard;
11+
let revealCard;
1012

1113
beforeEach(function() {
12-
revealCard = $('.card.reveal');
14+
revealCard = document.querySelector('.card.reveal');
1315
});
1416

1517
it("should have a hidden card-reveal", function (done) {
16-
var revealDiv = revealCard.find('.card-reveal');
17-
var activator = revealCard.find('.activator');
18+
let revealDiv = revealCard.querySelector('.card-reveal');
19+
let activator = revealCard.querySelector('.activator');
1820

1921
expect(revealDiv).toBeHidden('reveal div should be hidden initially');
2022

2123
setTimeout(function() {
22-
activator.click();
24+
click(activator);
2325

2426
setTimeout(function() {
2527
expect(revealDiv).toBeVisible('reveal did not appear after activator was clicked.');
2628

2729
// Check revealDiv covers reveal card.
28-
expect(revealDiv.outerWidth()).toEqual(revealCard.outerWidth(), 'activator was not as wide as reveal card.');
29-
expect(revealDiv.outerHeight()).toEqual(revealCard.outerHeight(), 'activator was not as high as reveal card.');
30-
expect(revealDiv.offset().top).toEqual(revealCard.offset().top, 'activator was not as in the same y as reveal card.');
31-
expect(revealDiv.offset().left).toEqual(revealCard.offset().left, 'activator was not as in the same x as reveal card.');
30+
let revealDivPositions = revealDiv.getBoundingClientRect();
31+
let revealCardPositions = revealCard.getBoundingClientRect();
32+
expect(revealDivPositions.width).toEqual(revealCardPositions.width, 'activator was not as wide as reveal card.');
33+
expect(revealDivPositions.height).toEqual(revealCardPositions.height, 'activator was not as high as reveal card.');
34+
expect(revealDivPositions.top).toEqual(revealCardPositions.top, 'activator was not as in the same y as reveal card.');
35+
expect(revealDivPositions.left).toEqual(revealCardPositions.left, 'activator was not as in the same x as reveal card.');
3236

3337
done();
3438
}, 400);
@@ -38,64 +42,78 @@ describe( "Cards", function () {
3842
});
3943

4044
describe("image cards", function () {
41-
var imageCard;
45+
let imageCard;
4246

4347
beforeEach(function() {
44-
imageCard = $('.card.image');
48+
imageCard = document.querySelector('.card.image');
4549
});
4650

4751
it("should have an image that fills to full width of card", function () {
48-
var image = imageCard.find('.card-image > img');
52+
let image = imageCard.querySelector('.card-image > img');
53+
let imagePositions = image.getBoundingClientRect();
54+
let imageCardPositions = imageCard.getBoundingClientRect();
4955

50-
expect(image.outerWidth()).toEqual(imageCard.outerWidth(), 'image does not fill width of card');
51-
expect(image.offset().top).toEqual(imageCard.offset().top, 'image was not as in the same y as card.');
56+
expect(imagePositions.width).toEqual(imageCardPositions.width, 'image does not fill width of card');
57+
expect(imagePositions.top).toEqual(imageCardPositions.top, 'image was not as in the same y as card.');
5258
});
5359
});
5460

5561

5662
describe("sized cards", function () {
57-
var small, medium, large;
63+
let small, medium, large;
5864

5965
beforeEach(function() {
60-
small = $('.card.small');
61-
medium = $('.card.medium');
62-
large = $('.card.large');
66+
small = document.querySelector('.card.small');
67+
medium = document.querySelector('.card.medium');
68+
large = document.querySelector('.card.large');
6369
});
6470

6571
it("should have small card dimensions", function () {
66-
var cardImage = small.find('.card-image');
67-
var cardContent = small.find('.card-content');
68-
var cardAction = small.find('.card-action');
69-
70-
expect(small.outerHeight()).toEqual(300, 'small card should be 300px high');
71-
expect(cardImage.outerHeight()).toBeLessThan(181, 'small image should be <= 180px or 60% high');
72-
expect(cardContent.outerHeight()).toBeLessThan(121, 'small content should be <= 120px or 40% high');
73-
expect(cardAction.offset().top + cardAction.outerHeight())
74-
.toEqual(small.offset().top + small.outerHeight(), 'small action should be at bottom of card');
72+
let cardImage = small.querySelector('.card-image');
73+
let cardContent = small.querySelector('.card-content');
74+
let cardAction = small.querySelector('.card-action');
75+
let smallRect = small.getBoundingClientRect();
76+
let cardImageRect = cardImage.getBoundingClientRect();
77+
let cardContentRect = cardContent.getBoundingClientRect();
78+
let cardActionRect = cardAction.getBoundingClientRect();
79+
80+
expect(smallRect.height).toEqual(300, 'small card should be 300px high');
81+
expect(cardImageRect.height).toBeLessThan(181, 'small image should be <= 180px or 60% high');
82+
expect(cardContentRect.height).toBeLessThan(121, 'small content should be <= 120px or 40% high');
83+
expect(cardActionRect.top + cardActionRect.height)
84+
.toEqual(smallRect.top + smallRect.height, 'small action should be at bottom of card');
7585
});
7686

7787
it("should have medium card dimensions", function () {
78-
var cardImage = medium.find('.card-image');
79-
var cardContent = medium.find('.card-content');
80-
var cardAction = medium.find('.card-action');
81-
82-
expect(medium.outerHeight()).toEqual(400, 'medium card should be 400px high');
83-
expect(cardImage.outerHeight()).toBeLessThan(241, 'medium image should be <= 240 or 60% high');
84-
expect(cardContent.outerHeight()).toBeLessThan(161, 'medium content should be <= 160px or 40% high');
85-
expect(cardAction.offset().top + cardAction.outerHeight())
86-
.toEqual(medium.offset().top + medium.outerHeight(), 'medium action should be at bottom of card');
88+
let cardImage = medium.querySelector('.card-image');
89+
let cardContent = medium.querySelector('.card-content');
90+
let cardAction = medium.querySelector('.card-action');
91+
let mediumRect = medium.getBoundingClientRect();
92+
let cardImageRect = cardImage.getBoundingClientRect();
93+
let cardContentRect = cardContent.getBoundingClientRect();
94+
let cardActionRect = cardAction.getBoundingClientRect();
95+
96+
expect(mediumRect.height).toEqual(400, 'medium card should be 400px high');
97+
expect(cardImageRect.height).toBeLessThan(241, 'medium image should be <= 240 or 60% high');
98+
expect(cardContentRect.height).toBeLessThan(161, 'medium content should be <= 160px or 40% high');
99+
expect(cardActionRect.top + cardActionRect.height)
100+
.toEqual(mediumRect.top + mediumRect.height, 'medium action should be at bottom of card');
87101
});
88102

89103
it("should have large card dimensions", function () {
90-
var cardImage = large.find('.card-image');
91-
var cardContent = large.find('.card-content');
92-
var cardAction = large.find('.card-action');
93-
94-
expect(large.outerHeight()).toEqual(500, 'large card should be 500px high');
95-
expect(cardImage.outerHeight()).toBeLessThan(301, 'large image should be <= 300 or 60% high');
96-
expect(cardContent.outerHeight()).toBeLessThan(201, 'large content should be <= 200 or 40% high');
97-
expect(cardAction.offset().top + cardAction.outerHeight())
98-
.toEqual(large.offset().top + large.outerHeight(), 'large action should be at bottom of card');
104+
let cardImage = large.querySelector('.card-image');
105+
let cardContent = large.querySelector('.card-content');
106+
let cardAction = large.querySelector('.card-action');
107+
let largeRect = large.getBoundingClientRect();
108+
let cardImageRect = cardImage.getBoundingClientRect();
109+
let cardContentRect = cardContent.getBoundingClientRect();
110+
let cardActionRect = cardAction.getBoundingClientRect();
111+
112+
expect(largeRect.height).toEqual(500, 'large card should be 500px high');
113+
expect(cardImageRect.height).toBeLessThan(301, 'large image should be <= 300 or 60% high');
114+
expect(cardContentRect.height).toBeLessThan(201, 'large content should be <= 200 or 40% high');
115+
expect(cardActionRect.top + cardActionRect.height)
116+
.toEqual(largeRect.top + largeRect.height, 'large action should be at bottom of card');
99117
});
100118
});
101119

tests/spec/carousel/carouselSpec.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
describe("Carousel", function () {
22

3-
beforeEach(function() {
4-
loadFixtures('carousel/carouselFixture.html');
3+
beforeEach(async function() {
4+
await XloadFixtures(['carousel/carouselFixture.html']);
5+
});
6+
afterEach(function(){
7+
XunloadFixtures();
58
});
69

710
describe("carousel plugin", function () {
@@ -10,17 +13,19 @@ describe("Carousel", function () {
1013
// });
1114

1215
it("No wrap next and prev should not overflow", function (done) {
13-
$noWrap = $('#slider-no-wrap').carousel({ noWrap: true });
14-
$noWrap.carousel('prev');
16+
let noWrap = M.Carousel.init(
17+
document.querySelector('#slider-no-wrap'), { noWrap: true }
18+
);
19+
noWrap.prev();
1520

16-
expect($noWrap[0].M_Carousel.center).toEqual(0, 'Prev should do nothing');
21+
expect(noWrap.center).toEqual(0, 'Prev should do nothing');
1722

18-
$noWrap.carousel('set', 3);
23+
noWrap.set(3);
1924
setTimeout(function() {
20-
$noWrap.carousel('next');
25+
noWrap.next();
2126

2227
setTimeout(function() {
23-
expect($noWrap[0].M_Carousel.center).toEqual(3, 'Next should do nothing');
28+
expect(noWrap.center).toEqual(3, 'Next should do nothing');
2429

2530
done();
2631
}, 400);

0 commit comments

Comments
 (0)