Skip to content

Commit

Permalink
style: fix linter issues from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wuda-io committed Dec 23, 2024
1 parent 562a542 commit 800255c
Show file tree
Hide file tree
Showing 18 changed files with 111 additions and 139 deletions.
18 changes: 7 additions & 11 deletions spec/helpers/helper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable no-undef */
/* eslint-disable no-unused-vars */

const KEYMAP = {
'27': 'Escape',
'32': 'Space',
Expand Down Expand Up @@ -121,28 +118,27 @@ const KEYMAP = {
'105': '9'
};

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function XloadHtml(html, options) {
options = options ? options : {};
const defaultOptions = { insertionType: 'append' };
options = {
...defaultOptions,
...options
};

const div = document.createElement('div');
div.classList.add('please-delete-me');
div.innerHTML = html;

if (options.insertionType === 'append') {
document.body.appendChild(div);
} else if (options.insertionType === 'prepend') {
document.body.prepend(div);
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function XunloadFixtures() {
document.querySelectorAll('.please-delete-me').forEach((el) => el.remove());
//
document.querySelectorAll('.material-tooltip').forEach((el) => el.remove());
document.querySelectorAll('.dropdown-content').forEach((el) => el.remove());
}
Expand All @@ -152,7 +148,7 @@ beforeEach(() => {
toExist: (util, customEqualityTesters) => {
return {
compare: (actual) => {
let result = {};
const result = {};
result.pass = util.equals(!!actual, true, customEqualityTesters);
return result;
}
Expand Down Expand Up @@ -190,7 +186,7 @@ beforeEach(() => {
return {
compare: (actual) => {
const style = getComputedStyle(actual);
let result = {};
const result = {};
result.pass = util.equals(
style.getPropertyValue('display'),
'none',
Expand All @@ -204,7 +200,7 @@ beforeEach(() => {
return {
compare: (actual) => {
const style = getComputedStyle(actual);
let result = {};
const result = {};
result.pass = !util.equals(
style.getPropertyValue('display'),
'none',
Expand All @@ -224,7 +220,7 @@ beforeEach(() => {
toHaveClass: (util, customEqualityTesters) => {
return {
compare: (actual, expected) => {
let result = {};
const result = {};
result.pass = util.equals(
actual.classList.contains(expected),
true,
Expand All @@ -237,7 +233,7 @@ beforeEach(() => {
toNotHaveClass: (util, customEqualityTesters) => {
return {
compare: function (actual, expected) {
let result = {};
const result = {};
result.pass = util.equals(
actual.classList.contains(expected),
false,
Expand Down
10 changes: 5 additions & 5 deletions spec/tests/autocomplete/autocompleteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('Autocomplete Plugin', () => {
}
const limitedInstance = M.Autocomplete.getInstance(limited);
const limit = 20;
limitedInstance.options.onSearch = (text) => {
limitedInstance.options.onSearch = () => {
const filteredItems = data.slice(0, limit);
limitedInstance.setMenuItems(filteredItems);
};
Expand All @@ -114,8 +114,8 @@ describe('Autocomplete Plugin', () => {
});

it('should open correctly from typing', (done) => {
let normal = document.querySelector('#normal-autocomplete');
let autocompleteEl = normal.parentNode.querySelector('.autocomplete-content');
const normal = document.querySelector('#normal-autocomplete');
const autocompleteEl = normal.parentNode.querySelector('.autocomplete-content');
focus(normal);
normal.value = 'e';
keyup(normal, 69);
Expand All @@ -129,8 +129,8 @@ describe('Autocomplete Plugin', () => {
});

it('should open correctly from keyboard focus', (done) => {
let normal = document.querySelector('#normal-autocomplete');
let autocompleteEl = normal.parentNode.querySelector('.autocomplete-content');
const normal = document.querySelector('#normal-autocomplete');
const autocompleteEl = normal.parentNode.querySelector('.autocomplete-content');
normal.value = 'e';
keyup(normal, 9);
focus(normal);
Expand Down
44 changes: 21 additions & 23 deletions spec/tests/cards/cardsSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-undef */

describe('Cards', () => {
const fixture = `<div class="row">
<div class="col s12 m6">
Expand Down Expand Up @@ -150,13 +148,13 @@ describe('Cards', () => {
});

it('should have small card dimensions', () => {
let cardImage = small.querySelector('.card-image');
let cardContent = small.querySelector('.card-content');
let cardAction = small.querySelector('.card-action');
let smallRect = small.getBoundingClientRect();
let cardImageRect = cardImage.getBoundingClientRect();
let cardContentRect = cardContent.getBoundingClientRect();
let cardActionRect = cardAction.getBoundingClientRect();
const cardImage = small.querySelector('.card-image');
const cardContent = small.querySelector('.card-content');
const cardAction = small.querySelector('.card-action');
const smallRect = small.getBoundingClientRect();
const cardImageRect = cardImage.getBoundingClientRect();
const cardContentRect = cardContent.getBoundingClientRect();
const cardActionRect = cardAction.getBoundingClientRect();

expect(smallRect.height).toEqual(300, 'small card should be 300px high');
expect(cardImageRect.height).toBeLessThan(181, 'small image should be <= 180px or 60% high');
Expand All @@ -171,13 +169,13 @@ describe('Cards', () => {
});

it('should have medium card dimensions', () => {
let cardImage = medium.querySelector('.card-image');
let cardContent = medium.querySelector('.card-content');
let cardAction = medium.querySelector('.card-action');
let mediumRect = medium.getBoundingClientRect();
let cardImageRect = cardImage.getBoundingClientRect();
let cardContentRect = cardContent.getBoundingClientRect();
let cardActionRect = cardAction.getBoundingClientRect();
const cardImage = medium.querySelector('.card-image');
const cardContent = medium.querySelector('.card-content');
const cardAction = medium.querySelector('.card-action');
const mediumRect = medium.getBoundingClientRect();
const cardImageRect = cardImage.getBoundingClientRect();
const cardContentRect = cardContent.getBoundingClientRect();
const cardActionRect = cardAction.getBoundingClientRect();

expect(mediumRect.height).toEqual(400, 'medium card should be 400px high');
expect(cardImageRect.height).toBeLessThan(241, 'medium image should be <= 240 or 60% high');
Expand All @@ -192,13 +190,13 @@ describe('Cards', () => {
});

it('should have large card dimensions', () => {
let cardImage = large.querySelector('.card-image');
let cardContent = large.querySelector('.card-content');
let cardAction = large.querySelector('.card-action');
let largeRect = large.getBoundingClientRect();
let cardImageRect = cardImage.getBoundingClientRect();
let cardContentRect = cardContent.getBoundingClientRect();
let cardActionRect = cardAction.getBoundingClientRect();
const cardImage = large.querySelector('.card-image');
const cardContent = large.querySelector('.card-content');
const cardAction = large.querySelector('.card-action');
const largeRect = large.getBoundingClientRect();
const cardImageRect = cardImage.getBoundingClientRect();
const cardContentRect = cardContent.getBoundingClientRect();
const cardActionRect = cardAction.getBoundingClientRect();

expect(largeRect.height).toEqual(500, 'large card should be 500px high');
expect(cardImageRect.height).toBeLessThan(301, 'large image should be <= 300 or 60% high');
Expand Down
8 changes: 4 additions & 4 deletions spec/tests/carousel/carouselSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-undef */

describe('Carousel', () => {
const fixture = `<div class="carousel carousel-slider" id="slider-no-wrap">
<div class="carousel-item">
Expand Down Expand Up @@ -52,10 +50,12 @@ describe('Carousel', () => {

document.querySelectorAll('.indicator-item')[1].click();
setTimeout(() => {
expect(carousel.center).toEqual(1, 'carousel item was not visible after indicator interaction');
expect(carousel.center).toEqual(
1,
'carousel item was not visible after indicator interaction'
);
done();
}, 30);
});

});
});
10 changes: 4 additions & 6 deletions spec/tests/chips/chipsSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-undef */

describe('Chips', () => {
const fixture = `<div class="chips"></div>
<div class="chips chips-initial"></div>
Expand Down Expand Up @@ -66,7 +64,7 @@ describe('Chips', () => {
M.Chips.init(chips);
M.Chips.init(chips);
chipsUserInput = document.querySelector('.chips.input-field');
M.Chips.init(chips, {allowUserInput: true});
M.Chips.init(chips, { allowUserInput: true });
input = chipsUserInput.querySelectorAll('input');
expect(input.length).toEqual(1, 'Should dynamically generate chips structure.');
});
Expand All @@ -77,8 +75,8 @@ describe('Chips', () => {
input.value = 'one';
keydown(input, 13);
setTimeout(() => {
let numChips = chips.querySelectorAll('.chip').length;
let oneChip = chips.querySelector('.chip');
const numChips = chips.querySelectorAll('.chip').length;
const oneChip = chips.querySelector('.chip');
expect(numChips).toEqual(1, 'one chip should have been added');
for (let i = oneChip.children.length - 1; i >= 0; i--) {
oneChip.children[i].remove();
Expand All @@ -92,7 +90,7 @@ describe('Chips', () => {
chips = document.querySelector('.chips.chips-initial.input-field');
let numChips = chips.querySelectorAll('.chip').length;
expect(numChips).toEqual(3, '3 initial chips should have been added');
let chipCloseButton = chips.querySelectorAll('.chip .close');
const chipCloseButton = chips.querySelectorAll('.chip .close');
expect(chipCloseButton.length).toEqual(3, 'expected all chips to have close button');
click(chipCloseButton[0]);
setTimeout(() => {
Expand Down
34 changes: 16 additions & 18 deletions spec/tests/collapsible/collapsibleSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-undef */

describe('Collapsible Plugin:', () => {
let collapsible, accordion, popout, expandable, expandablePreselect;

Expand Down Expand Up @@ -80,8 +78,8 @@ describe('Collapsible Plugin:', () => {
describe('collapsible', () => {
it('should open all items, keeping all open', (done) => {
// Collapsible body height should be 0 on start when hidden.
let headers = expandable.querySelectorAll('.collapsible-header');
let bodies = expandable.querySelectorAll('.collapsible-body');
const headers = expandable.querySelectorAll('.collapsible-header');
const bodies = expandable.querySelectorAll('.collapsible-body');
for (let i = 0; i < bodies.length; i++) {
expect(bodies[i]).hasMaxHeightZero(
'because collapsible bodies should be hidden initially.'
Expand All @@ -103,9 +101,9 @@ describe('Collapsible Plugin:', () => {
});

it('should allow preopened sections', () => {
let bodies = expandablePreselect.querySelectorAll('.collapsible-body');
const bodies = expandablePreselect.querySelectorAll('.collapsible-body');
for (let i = 0; i < bodies.length; i++) {
let headerLi = bodies[i].parentNode;
const headerLi = bodies[i].parentNode;
if (i === 1) {
expect(headerLi).toHaveClass(
'active',
Expand Down Expand Up @@ -136,15 +134,15 @@ describe('Collapsible Plugin:', () => {
inDuration: 0,
outDuration: 0
});
let bodies = expandable.querySelectorAll('.collapsible-body');
const bodies = expandable.querySelectorAll('.collapsible-body');
expect(openCallback).toEqual(false, 'because open callback not yet fired');
expect(closeCallback).toEqual(false, 'because close callback not yet fired');
for (let i = 0; i < bodies.length; i++) {
//TODO replace with alternative for deprecated jasmine-jquery
expect(bodies[i]).hasMaxHeightZero(
'because collapsible bodies should be hidden initially.'
);
let collapsibleInstance = M.Collapsible.getInstance(bodies[i].parentNode.parentNode);
const collapsibleInstance = M.Collapsible.getInstance(bodies[i].parentNode.parentNode);
collapsibleInstance.open(i);
}
expect(openCallback).toEqual(true, 'because open callback fired');
Expand All @@ -171,10 +169,10 @@ describe('Collapsible Plugin:', () => {
describe('accordion', () => {
it('should open first and second items, keeping only second open', (done) => {
// Collapsible body height should be 0 on start when hidden.
let firstHeader = accordion.querySelector('.collapsible-header');
let firstBody = accordion.querySelector('.collapsible-body');
let secondHeader = accordion.querySelectorAll('.collapsible-header')[1];
let secondBody = accordion.querySelectorAll('.collapsible-body')[1];
const firstHeader = accordion.querySelector('.collapsible-header');
const firstBody = accordion.querySelector('.collapsible-body');
const secondHeader = accordion.querySelectorAll('.collapsible-header')[1];
const secondBody = accordion.querySelectorAll('.collapsible-body')[1];
expect(firstBody).hasMaxHeightZero('because accordion bodies should be hidden initially.');
expect(secondBody).hasMaxHeightZero('because accordion bodies should be hidden initially.');
// Collapsible body height should be > 0 after being opened.
Expand All @@ -200,15 +198,15 @@ describe('Collapsible Plugin:', () => {
describe('popout', () => {
it('should open first and popout', (done) => {
// Collapsible body height should be 0 on start when hidden.
let listItems = popout.querySelectorAll('li');
let firstHeader = popout.querySelector('.collapsible-header');
let firstBody = popout.querySelector('.collapsible-body');
const listItems = popout.querySelectorAll('li');
const firstHeader = popout.querySelector('.collapsible-header');
const firstBody = popout.querySelector('.collapsible-body');
expect(firstBody).hasMaxHeightZero('because accordion bodies should be hidden initially.');
// Expect margin to be > 0 because not popped out.
for (let i = 0; i < listItems.length; i++) {
let listItemStyles = getComputedStyle(listItems[i]);
let marginLeft = parseInt(listItemStyles.getPropertyValue('margin-left'));
let marginRight = parseInt(listItemStyles.getPropertyValue('margin-right'));
const listItemStyles = getComputedStyle(listItems[i]);
const marginLeft = parseInt(listItemStyles.getPropertyValue('margin-left'));
const marginRight = parseInt(listItemStyles.getPropertyValue('margin-right'));
expect(marginLeft).toBeGreaterThan(
0,
'because closed popout items should have horizontal margins.'
Expand Down
2 changes: 0 additions & 2 deletions spec/tests/datepicker/datepickerSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-undef */

describe('Datepicker Plugin', () => {
const fixture = `<div class="row">
<div class="input-field col s12">
Expand Down
2 changes: 0 additions & 2 deletions spec/tests/dropdown/dropdownSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-undef */

describe('Dropdown Plugin:', () => {
const fixture = `<div class="row">
<div class="input-field col s12">
Expand Down
2 changes: 0 additions & 2 deletions spec/tests/fab/fabSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-undef */

describe('Fab Plugin:', () => {
const fixture = `<div class="fixed-action-btn">
<a class="btn-floating btn-large red">
Expand Down
2 changes: 0 additions & 2 deletions spec/tests/forms/formsSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-undef */

const MULTILINE_TEXT =
'This is line 1.\nThis is line 2.\nThis is line 3.\nThis is line 4.\nThis is line 5.\nAnd this is line 6.';

Expand Down
2 changes: 0 additions & 2 deletions spec/tests/materialbox/materialboxSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-undef */

describe('Materialbox:', () => {
const fixture = `<div id="transformTest" style="transform: translate3d(1px,1px,1px)">
<img
Expand Down
Loading

0 comments on commit 800255c

Please sign in to comment.