-
Notifications
You must be signed in to change notification settings - Fork 0
/
Oppgave2q.html
83 lines (70 loc) · 2.25 KB
/
Oppgave2q.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>QUnit Example</title>
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.9.2.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="https://code.jquery.com/qunit/qunit-2.9.2.js"></script>
<script src="Oppgave2.js"></script>
<script>
// mock-view
function show() { }
// model
let numbers = [7, 3, 1, 5, 8];
let selectBarNo;
let inputValue;
let error = null;
QUnit.test("Select different bar", function (assert) {
selectBarNo = 2;
selectBar(1);
assert.equal(selectBarNo, 1);
});
QUnit.test("Select the same bar", function (assert) {
selectBarNo = 1;
selectBar(1);
assert.equal(selectBarNo, null);
});
QUnit.test("Remove bar", function (assert) {
selectBarNo = 1;
removeBar();
assert.equal(numbers.length, 4);
assert.equal(numbers[0], 3);
assert.equal(selectBarNo, null);
numbers = [7, 3, 1, 5, 8];
});
QUnit.test("Change bar", function (assert) {
selectBarNo = 1;
inputValue = 5;
changeBar();
assert.equal(numbers[selectBarNo - 1], 5);
assert.equal(error, null);
numbers = [7, 3, 1, 5, 8];
});
QUnit.test("Change bar invalid input", function (assert) {
selectBarNo = 1;
inputValue = 11;
changeBar();
assert.equal(numbers[selectBarNo - 1], 7);
assert.equal(error, 'Ugyldig verdi');
});
QUnit.test("Add bar", function (assert) {
inputValue = 5;
addBar();
assert.equal(numbers[5], 5);
assert.equal(error, null);
numbers = [7, 3, 1, 5, 8];
});
QUnit.test("Add bar invalid input", function (assert) {
inputValue = 11;
addBar();
assert.equal(numbers[5], undefined);
assert.equal(error, 'Ugyldig verdi');
});
</script>
</body>
</html>