From e3df4e0ddeb953da80d0789bc3973fbdcfb6a60e Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 24 Oct 2023 02:51:24 +0200 Subject: [PATCH] tests: removed js-fixtures --- tests/netteForms/Gruntfile.js | 3 - tests/netteForms/package.json | 1 - .../netteForms/spec/Nette.validateRuleSpec.js | 139 +++++++++--------- 3 files changed, 66 insertions(+), 77 deletions(-) diff --git a/tests/netteForms/Gruntfile.js b/tests/netteForms/Gruntfile.js index 65e2d4140..ad31b91cf 100644 --- a/tests/netteForms/Gruntfile.js +++ b/tests/netteForms/Gruntfile.js @@ -6,9 +6,6 @@ module.exports = function(grunt) { '../../src/assets/*.js', '!../../src/assets/*.min.js' ], options: { - vendor: [ - 'node_modules/js-fixtures/fixtures.js' - ], specs: 'spec/*Spec.js' } } diff --git a/tests/netteForms/package.json b/tests/netteForms/package.json index ad243089e..1311800d6 100644 --- a/tests/netteForms/package.json +++ b/tests/netteForms/package.json @@ -3,7 +3,6 @@ "grunt": "^1.6.1", "grunt-contrib-jasmine": "^4.0.0", "jasmine": "^5.1.0", - "js-fixtures": "^1.5.3", "load-grunt-tasks": "^5.1.0" } } diff --git a/tests/netteForms/spec/Nette.validateRuleSpec.js b/tests/netteForms/spec/Nette.validateRuleSpec.js index 03fdace3f..469d027a0 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,22 @@ 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); + }); });