From f7c617cbafa6a1cd048171c1c188aa881bd7db85 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 24 Oct 2023 04:10:48 +0200 Subject: [PATCH] tests: removed js-fixtures --- tests/netteForms/karma.conf.js | 1 - .../netteForms/spec/Nette.validateRuleSpec.js | 140 +++++++++--------- 2 files changed, 67 insertions(+), 74 deletions(-) diff --git a/tests/netteForms/karma.conf.js b/tests/netteForms/karma.conf.js index ec5e83dc2..a8d361b6d 100644 --- a/tests/netteForms/karma.conf.js +++ b/tests/netteForms/karma.conf.js @@ -4,7 +4,6 @@ module.exports = function(config) { frameworks: ['jasmine'], browsers: ['ChromeHeadless'], files: [ - 'node_modules/js-fixtures/fixtures.js', '../../src/assets/netteForms.js', 'spec/*Spec.js' ], diff --git a/tests/netteForms/spec/Nette.validateRuleSpec.js b/tests/netteForms/spec/Nette.validateRuleSpec.js index 03fdace3f..099d99d4a 100644 --- a/tests/netteForms/spec/Nette.validateRuleSpec.js +++ b/tests/netteForms/spec/Nette.validateRuleSpec.js @@ -1,15 +1,10 @@ describe('Nette.getValue & validateRule', function() { - - beforeEach(function() { - fixtures.cleanUp(); - }); - + let testContainer; it('text input', function() { - fixtures.set('
'); + testContainer.innerHTML = `
`; - var doc = fixtures.window().document, - form = doc.forms[0], + let form = testContainer.querySelector('form'), el = form.input; expect(Nette.getValue(el)).toBe(''); @@ -85,10 +80,9 @@ describe('Nette.getValue & validateRule', function() { it('text area', function() { - fixtures.set('
'); + testContainer.innerHTML = `
`; - var doc = fixtures.window().document, - form = doc.forms[0], + let form = testContainer.querySelector('form'), el = form.input; expect(Nette.getValue(el)).toBe(''); @@ -106,34 +100,31 @@ describe('Nette.getValue & validateRule', function() { it('upload', function() { - fixtures.set('
'); + testContainer.innerHTML = `
`; - var doc = fixtures.window().document, - form = doc.forms[0], + let form = testContainer.querySelector('form'), el = form.input; - expect(Nette.getValue(el) instanceof fixtures.window().FileList).toBe(true); + expect(Nette.getValue(el) instanceof FileList).toBe(true); expect(Nette.getValue(el).length).toBe(0); }); it('multi upload', function() { - fixtures.set('
'); + testContainer.innerHTML = `
`; - var doc = fixtures.window().document, - form = doc.forms[0], + let form = testContainer.querySelector('form'), el = form['input[]']; - expect(Nette.getValue(el) instanceof fixtures.window().FileList).toBe(true); + expect(Nette.getValue(el) instanceof FileList).toBe(true); expect(Nette.getValue(el).length).toBe(0); }); it('checkbox', function() { - fixtures.set('
'); + testContainer.innerHTML = `
`; - var doc = fixtures.window().document, - form = doc.forms[0], + let form = testContainer.querySelector('form'), el = form.input; expect(Nette.getValue(el)).toBe(false); @@ -150,14 +141,13 @@ describe('Nette.getValue & validateRule', function() { it('checkbox list', function() { - fixtures.set('
\ - \ - \ - \ -
'); - - var doc = fixtures.window().document, - form = doc.forms[0], + testContainer.innerHTML = `
+ + + +
`; + + let form = testContainer.querySelector('form'), el = form['input[]']; expect(Nette.getValue(el)).toEqual([]); @@ -165,7 +155,7 @@ describe('Nette.getValue & validateRule', function() { expect(Nette.validateRule(el, 'blank')).toBe(true); expect(Nette.validateRule(el, 'equal', ['r', 'g', 'b'])).toBe(true); - doc.getElementById('input-r').checked = true; + testContainer.querySelector('#input-r').checked = true; expect(Nette.getValue(el)).toEqual(['r']); expect(Nette.validateRule(el, 'filled')).toBe(true); expect(Nette.validateRule(el, 'blank')).toBe(false); @@ -175,7 +165,7 @@ describe('Nette.getValue & validateRule', function() { expect(Nette.validateRule(el, 'minLength', 1)).toBe(true); expect(Nette.validateRule(el, 'minLength', 2)).toBe(false); - doc.getElementById('input-g').checked = true; + testContainer.querySelector('#input-g').checked = true; expect(Nette.getValue(el)).toEqual(['r', 'g']); expect(Nette.validateRule(el, 'filled')).toBe(true); expect(Nette.validateRule(el, 'blank')).toBe(false); @@ -189,10 +179,9 @@ describe('Nette.getValue & validateRule', function() { it('checkbox list with single item', function() { - fixtures.set('
'); + testContainer.innerHTML = `
`; - var doc = fixtures.window().document, - form = doc.forms[0], + let form = testContainer.querySelector('form'), el = form['input[]']; expect(Nette.getValue(el)).toEqual([]); @@ -200,7 +189,7 @@ describe('Nette.getValue & validateRule', function() { expect(Nette.validateRule(el, 'blank')).toBe(true); expect(Nette.validateRule(el, 'equal', ['r', 'g', 'b'])).toBe(true); - doc.getElementById('input-r').checked = true; + testContainer.querySelector('#input-r').checked = true; expect(Nette.getValue(el)).toEqual(['r']); expect(Nette.validateRule(el, 'filled')).toBe(true); expect(Nette.validateRule(el, 'blank')).toBe(false); @@ -213,10 +202,9 @@ describe('Nette.getValue & validateRule', function() { it('radio', function() { - fixtures.set('
'); + testContainer.innerHTML = ``; - var doc = fixtures.window().document, - form = doc.forms[0], + let form = testContainer.querySelector('form'), el = form.input; expect(Nette.getValue(el)).toBe(null); @@ -235,13 +223,12 @@ describe('Nette.getValue & validateRule', function() { it('radio list', function() { - fixtures.set(' \ - \ - \ -
'); + testContainer.innerHTML = `
+ + +
`; - var doc = fixtures.window().document, - form = doc.forms[0], + let form = testContainer.querySelector('form'), el = form.input; expect(Nette.getValue(el)).toBe(null); @@ -249,10 +236,10 @@ describe('Nette.getValue & validateRule', function() { expect(Nette.validateRule(el, 'blank')).toBe(true); expect(Nette.validateRule(el, 'equal', ['f', 'm'])).toBe(false); - doc.getElementById('input-m').checked = true; + testContainer.querySelector('#input-m').checked = true; expect(Nette.getValue(el)).toBe('m'); - doc.getElementById('input-f').checked = true; + testContainer.querySelector('#input-f').checked = true; expect(Nette.getValue(el)).toBe('f'); expect(Nette.validateRule(el, 'filled')).toBe(true); expect(Nette.validateRule(el, 'blank')).toBe(false); @@ -263,23 +250,22 @@ describe('Nette.getValue & validateRule', function() { it('selectbox', function() { - fixtures.set('
\ - \ -
'); - - var doc = fixtures.window().document, - form = doc.forms[0], + testContainer.innerHTML = `
+ +
`; + + let form = testContainer.querySelector('form'), el = form.input; expect(Nette.getValue(el)).toBe(''); expect(Nette.validateRule(el, 'filled')).toBe(false); expect(Nette.validateRule(el, 'blank')).toBe(true); - doc.getElementById('option-2').selected = true; + testContainer.querySelector('#option-2').selected = true; expect(Nette.getValue(el)).toBe('bu'); expect(Nette.validateRule(el, 'filled')).toBe(true); expect(Nette.validateRule(el, 'blank')).toBe(false); @@ -287,28 +273,27 @@ describe('Nette.getValue & validateRule', function() { expect(Nette.validateRule(el, 'equal', 'x')).toBe(false); expect(Nette.validateRule(el, 'equal', ['bu', 'x'])).toBe(true); - doc.getElementById('option-3').selected = true; + testContainer.querySelector('#option-3').selected = true; expect(Nette.getValue(el)).toBe('?'); }); it('multi selectbox', function() { - fixtures.set('
\ - \ -
'); - - var doc = fixtures.window().document, - form = doc.forms[0], + testContainer.innerHTML = `
+ +
`; + + let form = testContainer.querySelector('form'), el = form['input[]']; expect(Nette.getValue(el)).toEqual([]); expect(Nette.validateRule(el, 'filled')).toBe(false); expect(Nette.validateRule(el, 'blank')).toBe(true); - doc.getElementById('option-2').selected = true; + testContainer.querySelector('#option-2').selected = true; expect(Nette.getValue(el)).toEqual(['bu']); expect(Nette.validateRule(el, 'filled')).toBe(true); expect(Nette.validateRule(el, 'blank')).toBe(false); @@ -318,7 +303,7 @@ describe('Nette.getValue & validateRule', function() { expect(Nette.validateRule(el, 'minLength', 1)).toBe(true); expect(Nette.validateRule(el, 'minLength', 2)).toBe(false); - doc.getElementById('option-3').selected = true; + testContainer.querySelector('#option-3').selected = true; expect(Nette.getValue(el)).toEqual(['bu', '?']); expect(Nette.validateRule(el, 'filled')).toBe(true); expect(Nette.validateRule(el, 'blank')).toBe(false); @@ -332,14 +317,23 @@ describe('Nette.getValue & validateRule', function() { it('missing name', function() { - fixtures.set('
'); + testContainer.innerHTML = '
'; - var doc = fixtures.window().document, - form = doc.forms[0], + let form = testContainer.querySelector('form'), el = form.elements[0]; expect(Nette.getValue(el)).toEqual(''); el.value = ' hello '; expect(Nette.getValue(el)).toBe('hello'); }); + + + beforeEach(function() { + testContainer = document.createElement('div'); + document.body.appendChild(testContainer); + }); + + afterEach(function() { + document.body.removeChild(testContainer); + }); });