This repository has been archived by the owner on Nov 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shape.spec.js
160 lines (159 loc) · 4.84 KB
/
shape.spec.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import fileMotif from "../../file/file.motif.js";
import folderMotif from "../../folder/folder.motif.js";
import { CASE, FEATURE, MODULE } from "../../spec-section/_enums/type/spec-section.type.enum.js";
import websitePageMotif from "../website-page.motif.js";
import shape from "./shape.js";
import { TEMPLATE_FILE_NOT_FOUND, TEMPLATE_IS_NEITHER_STRING_NOR_FUNCTION, TEMPLATE_IS_NOT_A_PUG_FILE } from "./_errors/shape.errors.js";
export default {
type: MODULE,
group: [
{
type: FEATURE,
label: 'Returns a new object created from '
+ 'given parameters.',
group: [
{
type: FEATURE,
label: 'Object has WEBSITE_FOLDER id as `motif` property.',
test: () =>
shape(() => '', {}).motif
=== websitePageMotif.id
},
{
type: FEATURE,
label: 'Object has a `function` as `template` property '
+ '(see below for `string` `template` parameter cases).',
test: () =>
typeof shape(() => '', {}).template
=== 'function'
},
{
type: FEATURE,
label: 'Object has the same `data` I/O.',
test: () => {
const data = { valid: true }
return shape(() => '', data).data
=== data
}
}
]
},
{
type: FEATURE,
label: 'If `string` `template` (path), returns the '
+ 'compiled and provisionned (with factory `data`) '
+ '`.pug` file template function.',
group: [
{
type: FEATURE,
label: 'When executed, the `template()` property '
+ 'returns an `pug` rendered HTML fragment.',
test: async () => {
const path = '_tests/website-page-shape-path-pug'
await folderMotif.create(path)
const templateName = 'temp.pug'
await fileMotif.create(
path,
templateName,
() => 'div.row')
const shaped = shape(
path + '/' + templateName,
{}
)
return shaped.template()
.localeCompare('<div class="row"></div>')
=== 0
}
},
{
type: FEATURE,
label: 'Provisions by default the template data '
+ 'with factory `data` parameter.',
test: async () => {
const path = '_tests/website-page-shape-default-data'
await folderMotif.create(path)
const templateName = 'temp.pug'
await fileMotif.create(
path,
templateName,
() => 'p= content')
const shaped = shape(
path + '/' + templateName,
{ content: 'ok !' }
)
return shaped.template()
.localeCompare('<p>ok !</p>')
=== 0
}
},
{
type: FEATURE,
label: 'Product function can override default '
+ 'data with its own `data` parameter.',
test: async () => {
const path = '_tests/website-page-shape-override-data'
await folderMotif.create(path)
const templateName = 'temp.pug'
await fileMotif.create(
path,
templateName,
() => 'p= content')
const shaped = shape(
path + '/' + templateName,
{ content: 'one' }
)
return shaped.template({ content: 'two' })
.localeCompare('<p>two</p>')
=== 0
}
}
]
},
{
type: FEATURE,
label: 'Controls parameters rules, and throw exceptions '
+ 'if any is broken.',
group: [
{
type: CASE,
label: 'Parameter `template` is not of an '
+ 'allowed type (Function, string).',
test: () => {
try {
shape({}, {})
return false
} catch (err) {
return err.message === TEMPLATE_IS_NEITHER_STRING_NOR_FUNCTION
}
}
},
{
type: CASE,
label: 'Parameter `template` is a string but '
+ 'the string doesn\'t hold a `.pug` extension.',
test: () => {
try {
shape('home', {})
return false
} catch (err) {
return err.message === TEMPLATE_IS_NOT_A_PUG_FILE
}
}
},
{
type: CASE,
label: 'Parameter `template` is a string but '
+ 'the path it holds doesn\'t match any file.',
test: () => {
try {
shape('home.pug', {})
return false
} catch (err) {
return err.message === TEMPLATE_FILE_NOT_FOUND
}
}
}
]
}
]
}