Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
ded59ab8
Commit
ded59ab8
authored
Apr 01, 2016
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for settings function's `settingsClass` parameter
parent
cb5246e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
12 deletions
+30
-12
config-test.js
h/static/scripts/annotator/test/config-test.js
+1
-1
settings-test.js
h/static/scripts/test/settings-test.js
+29
-11
No files found.
h/static/scripts/annotator/test/config-test.js
View file @
ded59ab8
...
...
@@ -64,7 +64,7 @@ describe('annotator configuration', function () {
});
});
it
(
'merges the config from the "
hypothesis-config" meta
tag'
,
function
()
{
it
(
'merges the config from the "
js-hypothesis-config" <script>
tag'
,
function
()
{
fakeScriptConfig
=
'{"annotations":"456"}'
;
assert
.
deepEqual
(
config
(
fakeWindowBase
),
{
app
:
'app.html'
,
...
...
h/static/scripts/test/settings-test.js
View file @
ded59ab8
'use strict'
;
var
settings
=
require
(
'../settings'
);
function
createJSONScriptTag
(
obj
)
{
function
createJSONScriptTag
(
obj
,
className
)
{
var
el
=
document
.
createElement
(
'script'
);
el
.
type
=
'application/json'
;
el
.
textContent
=
JSON
.
stringify
(
obj
);
el
.
classList
.
add
(
'js-hypothesis-settings'
);
el
.
classList
.
add
(
className
);
el
.
classList
.
add
(
'js-settings-test'
);
return
el
;
}
function
removeJSONScriptTags
()
{
var
elements
=
document
.
querySelectorAll
(
'.js-settings-test'
);
for
(
var
i
=
0
;
i
<
elements
.
length
;
i
++
)
{
elements
[
i
].
parentNode
.
removeChild
(
elements
[
i
]);
}
}
describe
(
'settings'
,
function
()
{
afterEach
(
function
()
{
var
elements
=
document
.
querySelectorAll
(
'.js-hypothesis-settings'
);
for
(
var
i
=
0
;
i
<
elements
.
length
;
i
++
)
{
elements
[
i
].
parentNode
.
removeChild
(
elements
[
i
]);
}
afterEach
(
removeJSONScriptTags
);
it
(
'reads config from .js-hypothesis-settings <script> tags'
,
function
()
{
document
.
body
.
appendChild
(
createJSONScriptTag
({
key
:
'value'
},
'js-hypothesis-settings'
));
assert
.
deepEqual
(
settings
(
document
),
{
key
:
'value'
});
});
it
(
'reads config from <script> tags with the specified class name'
,
function
()
{
document
.
body
.
appendChild
(
createJSONScriptTag
({
foo
:
'bar'
},
'js-custom-settings'
));
assert
.
deepEqual
(
settings
(
document
),
{});
assert
.
deepEqual
(
settings
(
document
,
'js-custom-settings'
),
{
foo
:
'bar'
});
});
it
(
'
should merge settin
gs'
,
function
()
{
document
.
body
.
appendChild
(
createJSONScriptTag
({
a
:
1
}
));
document
.
body
.
appendChild
(
createJSONScriptTag
({
b
:
2
}
));
assert
.
deepEqual
(
settings
(
document
),
{
a
:
1
,
b
:
2
});
it
(
'
merges settings from all config <script> ta
gs'
,
function
()
{
document
.
body
.
appendChild
(
createJSONScriptTag
({
a
:
1
},
'settings'
));
document
.
body
.
appendChild
(
createJSONScriptTag
({
b
:
2
},
'settings'
));
assert
.
deepEqual
(
settings
(
document
,
'settings'
),
{
a
:
1
,
b
:
2
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment