1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/**
* QUnit tests
*
* @since 1.9
*
* @file
* @ingroup SMW
*
* @licence GNU GPL v2 or later
* @author mwjames
*/
( function ( $, mw, smw ) {
'use strict';
QUnit.module( 'ext.smw.dataValue.quantity', QUnit.newMwEnvironment() );
var pass = 'Passes because ';
// Data provider
var testCases = [
{ test: { value: 1 }, expected: { value: 1 } },
{ test: { value: 0.0001, unit: 'km²' }, expected: { value: 0.0001, unit: 'km²' } },
{ test: { value: 1000, unit: 'm²' }, expected: { value: 1000, unit: 'm²' } }
];
/**
* Test accessibility
*
* @since: 1.9
*/
QUnit.test( 'instance', function ( assert ) {
assert.expect( 2 );
var result = new smw.dataValue.quantity( 3 );
assert.ok( result instanceof Object, pass + 'the smw.dataValue.quantity instance was accessible' );
assert.throws( function() {
new smw.dataValue.quantity( 'foo' );
}, pass + 'an error was raised due to wrong type' );
} );
/**
* Test type
*
* @since: 1.9
*/
QUnit.test( 'getDIType', function ( assert ) {
assert.expect( 1 );
var result = new smw.dataValue.quantity( 3 );
assert.equal( result.getDIType(), '_qty', pass + 'returned _qty' );
} );
/**
* Test getValue
*
* @since: 1.9
*/
QUnit.test( 'getValue', function ( assert ) {
assert.expect( 3 );
var result;
$.map( testCases, function ( testCase ) {
result = new smw.dataValue.quantity( testCase.test.value, testCase.test.unit );
assert.equal( result.getValue(), testCase.expected.value , pass + 'returned ' + testCase.expected.value );
} );
} );
/**
* Test getUnit
*
* @since: 1.9
*/
QUnit.test( 'getUnit', function ( assert ) {
assert.expect( 3 );
var result;
$.map( testCases, function ( testCase ) {
result = new smw.dataValue.quantity( testCase.test.value, testCase.test.unit );
assert.equal( result.getUnit(), testCase.expected.unit , pass + 'returned ' + testCase.expected.unit );
} );
} );
}( jQuery, mediaWiki, semanticMediaWiki ) );
|