Skip to content

Commit

Permalink
tests: removed js-fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 24, 2023
1 parent b84bca0 commit e3df4e0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 77 deletions.
3 changes: 0 additions & 3 deletions tests/netteForms/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/netteForms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
139 changes: 66 additions & 73 deletions tests/netteForms/spec/Nette.validateRuleSpec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
describe('Nette.getValue & validateRule', function() {

beforeEach(function() {
fixtures.cleanUp();
});

let testContainer;

it('text input', function() {
fixtures.set('<form><input type="text" name="input"></form>');
testContainer.innerHTML = `<form><input type="text" name="input"></form>`;

var doc = fixtures.window().document,
form = doc.forms[0],
let form = testContainer.querySelector('form'),
el = form.input;

expect(Nette.getValue(el)).toBe('');
Expand Down Expand Up @@ -85,10 +80,9 @@ describe('Nette.getValue & validateRule', function() {


it('text area', function() {
fixtures.set('<form><textarea name="input"></textarea></form>');
testContainer.innerHTML = `<form><textarea name="input"></textarea></form>`;

var doc = fixtures.window().document,
form = doc.forms[0],
let form = testContainer.querySelector('form'),
el = form.input;

expect(Nette.getValue(el)).toBe('');
Expand All @@ -106,34 +100,31 @@ describe('Nette.getValue & validateRule', function() {


it('upload', function() {
fixtures.set('<form method="post" enctype="multipart/form-data"><input type="file" name="input"></form>');
testContainer.innerHTML = `<form method="post" enctype="multipart/form-data"><input type="file" name="input"></form>`;

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('<form method="post" enctype="multipart/form-data"><input type="file" name="input[]" multiple></form>');
testContainer.innerHTML = `<form method="post" enctype="multipart/form-data"><input type="file" name="input[]" multiple></form>`;

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('<form><input type="checkbox" name="input" value="r"></form>');
testContainer.innerHTML = `<form><input type="checkbox" name="input" value="r"></form>`;

var doc = fixtures.window().document,
form = doc.forms[0],
let form = testContainer.querySelector('form'),
el = form.input;

expect(Nette.getValue(el)).toBe(false);
Expand All @@ -150,22 +141,21 @@ describe('Nette.getValue & validateRule', function() {


it('checkbox list', function() {
fixtures.set('<form> \
<input type="checkbox" name="input[]" value="r" id="input-r"> \
<input type="checkbox" name="input[]" value="g" id="input-g"> \
<input type="checkbox" name="input[]" value="b" id="input-b"> \
</form>');

var doc = fixtures.window().document,
form = doc.forms[0],
testContainer.innerHTML = `<form>
<input type="checkbox" name="input[]" value="r" id="input-r">
<input type="checkbox" name="input[]" value="g" id="input-g">
<input type="checkbox" name="input[]" value="b" id="input-b">
</form>`;

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);
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);
Expand All @@ -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);
Expand All @@ -189,18 +179,17 @@ describe('Nette.getValue & validateRule', function() {


it('checkbox list with single item', function() {
fixtures.set('<form><input type="checkbox" name="input[]" value="r" id="input-r"></form>');
testContainer.innerHTML = `<form><input type="checkbox" name="input[]" value="r" id="input-r"></form>`;

var doc = fixtures.window().document,
form = doc.forms[0],
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);
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);
Expand All @@ -213,10 +202,9 @@ describe('Nette.getValue & validateRule', function() {


it('radio', function() {
fixtures.set('<form><input type="radio" name="input" value="f"><form>');
testContainer.innerHTML = `<form><input type="radio" name="input" value="f"><form>`;

var doc = fixtures.window().document,
form = doc.forms[0],
let form = testContainer.querySelector('form'),
el = form.input;

expect(Nette.getValue(el)).toBe(null);
Expand All @@ -235,24 +223,23 @@ describe('Nette.getValue & validateRule', function() {


it('radio list', function() {
fixtures.set('<form> \
<input type="radio" name="input" value="m" id="input-m"> \
<input type="radio" name="input" value="f" id="input-f"> \
</form>');
testContainer.innerHTML = `<form>
<input type="radio" name="input" value="m" id="input-m">
<input type="radio" name="input" value="f" id="input-f">
</form>`;

var doc = fixtures.window().document,
form = doc.forms[0],
let form = testContainer.querySelector('form'),
el = form.input;

expect(Nette.getValue(el)).toBe(null);
expect(Nette.validateRule(el, 'filled')).toBe(false);
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);
Expand All @@ -263,52 +250,50 @@ describe('Nette.getValue & validateRule', function() {


it('selectbox', function() {
fixtures.set('<form> \
<select name="input"> \
<option value="">Prompt</option> \
<optgroup label="World"><option value="bu" id="option-2">Buranda</option></optgroup> \
<option value="?" id="option-3">other</option> \
</select> \
</form>');

var doc = fixtures.window().document,
form = doc.forms[0],
testContainer.innerHTML = `<form>
<select name="input">
<option value="">Prompt</option>
<optgroup label="World"><option value="bu" id="option-2">Buranda</option></optgroup>
<option value="?" id="option-3">other</option>
</select>
</form>`;

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);
expect(Nette.validateRule(el, 'equal', 'bu')).toBe(true);
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('<form> \
<select name="input[]" multiple> \
<optgroup label="World"><option value="bu" id="option-2">Buranda</option></optgroup> \
<option value="?" id="option-3">other</option> \
</select> \
</form>');

var doc = fixtures.window().document,
form = doc.forms[0],
testContainer.innerHTML = `<form>
<select name="input[]" multiple>
<optgroup label="World"><option value="bu" id="option-2">Buranda</option></optgroup>
<option value="?" id="option-3">other</option>
</select>
</form>`;

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);
Expand All @@ -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);
Expand All @@ -332,14 +317,22 @@ describe('Nette.getValue & validateRule', function() {


it('missing name', function() {
fixtures.set('<form><input></form>');
testContainer.innerHTML = '<form><input></form>';

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);
});
});

0 comments on commit e3df4e0

Please sign in to comment.