Skip to content

Commit 65e441f

Browse files
committed
Added test
1 parent 2c4e40b commit 65e441f

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

package.js

+18
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,21 @@ Package.onUse(function(api) {
2222
'autoform-datemask.js'
2323
], 'client');
2424
});
25+
26+
Package.on_test(function (api) {
27+
api.use([
28+
29+
'tinytest',
30+
'jquery',
31+
'test-helpers',
32+
33+
34+
35+
'momentjs:[email protected]',
36+
37+
'igorescobar:[email protected]',
38+
'jkutianski:autoform-datemask'
39+
], 'client');
40+
41+
api.add_files('test/test-datemask.js', 'client');
42+
});

test/test-datemask.js

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* jshint esversion: 6 */
2+
3+
Tinytest.add('AutoForm - datemask exist', test => {
4+
let _inputTypeDefinitions = AutoForm._inputTypeDefinitions;
5+
test.instanceOf(
6+
_inputTypeDefinitions.datemask, Object
7+
);
8+
});
9+
10+
Tinytest.add('AutoForm - ContextAjust', test => {
11+
let _inputTypeDefinitions = AutoForm._inputTypeDefinitions;
12+
13+
test.instanceOf(
14+
_inputTypeDefinitions.datemask.contextAdjust, Object
15+
);
16+
17+
test.equal(
18+
typeof _inputTypeDefinitions.datemask.contextAdjust, 'function'
19+
);
20+
21+
let ctx = { atts: { mask: 'mask', maskoptions: {}, format: 'format', minlength: 1 } };
22+
23+
test.equal(
24+
_inputTypeDefinitions.datemask.contextAdjust(ctx), { atts: {} }
25+
);
26+
});
27+
28+
Tinytest.add('AutoForm - ValueOut', test => {
29+
let _inputTypeDefinitions = AutoForm._inputTypeDefinitions;
30+
31+
test.instanceOf(
32+
_inputTypeDefinitions.datemask.valueOut, Object
33+
);
34+
test.equal(
35+
typeof _inputTypeDefinitions.datemask.valueOut, 'function'
36+
);
37+
38+
_inputTypeDefinitions.datemask.contextAdjust({
39+
atts: {
40+
format: 'DD/MM/YYYY',
41+
minlength: 10
42+
}
43+
});
44+
45+
test.equal(
46+
_inputTypeDefinitions.datemask.valueOut.call({ val: () => '' }), ''
47+
);
48+
49+
test.equal(
50+
_inputTypeDefinitions.datemask.valueOut.call({ val: () => '31/31/3131' }).toString(), 'Invalid Date'
51+
);
52+
53+
test.equal(
54+
_inputTypeDefinitions.datemask.valueOut.call({ val: () => '01/01/01' }).toString(), 'Invalid Date'
55+
);
56+
57+
test.notEqual(
58+
_inputTypeDefinitions.datemask.valueOut.call({ val: () => '01/01/2001' }).toString(), 'Invalid Date'
59+
);
60+
});
61+
62+
63+
Tinytest.add('Template - afDateMask exist', test => {
64+
test.instanceOf(
65+
Template.afDateMask, Object
66+
);
67+
});
68+
69+
Tinytest.add('Template - helpers', test => {
70+
test.equal(
71+
Object.keys(Template.afDateMask.__helpers), [' atts']
72+
);
73+
74+
test.equal(
75+
Template.afDateMask.__helpers[' atts'].call({ atts: { test: true } }),
76+
{ test: true, class: 'form-control' }
77+
);
78+
});

0 commit comments

Comments
 (0)