-
Notifications
You must be signed in to change notification settings - Fork 1
/
activity.test.js
114 lines (88 loc) · 4 KB
/
activity.test.js
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
'use strict'
const path = require('path')
const chai = require('chai')
chai.should()
const expect = chai.expect
const fs = require('fs').promises
const helpers = require('./helpers')
const Activity = require('../activity')
describe('activity', function () {
describe('the constructor Activity(jsonActivity, context)', function () {
describe('the first parameter "jsonActivity"', function () {
it('expects an object', function () {
expect(function () {
new Activity({}, {})
}).to.not.throw()
})
it('throws an TypeError if passed data is not a json object', function () {
expect(function () {
new Activity('This is not an object', {})
}).to.throw(TypeError)
expect(function () {
new Activity('a string', {})
}).to.throw(TypeError)
expect(function () {
new Activity([], {})
}).to.throw(TypeError)
})
it('throws an ReferenceError if no data is passed at all', function () {
expect(function () {
new Activity(undefined, {})
}).to.throw(ReferenceError)
})
})
describe('the second parameter "context"', function () {
it('expects an object', function () {
expect(function () {
new Activity({}, {})
}).to.not.throw()
})
it('throws an TypeError if passed data is not a json object', function () {
expect(function () {
new Activity({}, 'This is not an object')
}).to.throw(TypeError)
expect(function () {
new Activity({}, 'a string')
}).to.throw(TypeError)
expect(function () {
new Activity({}, [])
}).to.throw(TypeError)
})
it('throws an ReferenceError if no data is passed at all', function () {
expect(function () {
new Activity({})
}).to.throw(ReferenceError)
})
})
})
describe('Activity.prototype.render()', function () {
context('valid data was passed to the constructor', function () {
it('renders a Activity with empt Card if the object is empty', async function () {
const activity = new Activity({}, {})
const htmlRendered = activity.render()
const htmlExpected = await fs.readFile(path.join(__dirname, 'mock-data', 'activity', 'mock-activity-empty.html'), 'utf8')
helpers.stripWhitespaces(htmlRendered).should.equal(helpers.stripWhitespaces(htmlExpected))
})
it('renders an empty steps container if empty list is given', async function () {
const activity = new Activity({
steps: []
}, {})
const htmlRendered = activity.render()
const htmlExpected = await fs.readFile(path.join(__dirname, 'mock-data', 'activity', 'mock-activity-steps-empty.html'), 'utf8')
helpers.stripWhitespaces(htmlRendered).should.equal(helpers.stripWhitespaces(htmlExpected))
})
it('can render all features', async function () {
const activity = new Activity({
title: 'Awesome Activity',
description: 'Lorem ipsum dolor sit amet ...',
steps: []
}, {})
const htmlRendered = activity.render()
const htmlExpected = await fs.readFile(path.join(__dirname, 'mock-data', 'activity', 'mock-activity-all-features.html'), 'utf8')
helpers.stripWhitespaces(htmlRendered).should.equal(helpers.stripWhitespaces(htmlExpected))
})
})
// context('this.jsonData is invalid', function() {
// })
})
})