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
6460fbc1
Commit
6460fbc1
authored
Dec 16, 2016
by
Robert Knight
Committed by
GitHub
Dec 16, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #179 from hypothesis/anchoring-baseline-tests
Add HTML baseline tests
parents
09f6b2f4
feebb62b
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
745 additions
and
0 deletions
+745
-0
index.js
.../scripts/annotator/anchoring/test/html-baselines/index.js
+34
-0
minimal.html
...ipts/annotator/anchoring/test/html-baselines/minimal.html
+1
-0
minimal.json
...ipts/annotator/anchoring/test/html-baselines/minimal.json
+24
-0
wikipedia-regression-testing.html
...ing/test/html-baselines/wikipedia-regression-testing.html
+311
-0
wikipedia-regression-testing.json
...ing/test/html-baselines/wikipedia-regression-testing.json
+320
-0
html-test.js
h/static/scripts/annotator/anchoring/test/html-test.js
+55
-0
No files found.
h/static/scripts/annotator/anchoring/test/html-baselines/index.js
0 → 100644
View file @
6460fbc1
'use strict'
;
// Fixtures for anchoring baseline tests. The goals of these tests are to:
//
// 1) Check for unexpected changes in the selectors captured when describing
// a Range in a web page.
// 2) Test anchoring in larger and more complex pages than the basic anchoring
// unit tests.
//
// Each fixture consists of:
//
// - An HTML file for a web page
// - A set of annotations in the JSON format returned by the Hypothesis API
//
// To add a new fixture:
//
// 1. Open up a web page in the browser and annotate it.
// 2. Save the web page (HTML only) via File -> Save Page As... as
// `<fixture name>.html` in this directory.
// It is important to save the page exactly as it was when annotated, since
// many pages have at least some dynamic content.
// 3. Fetch the annotations for the web page via the Hypothesis API and save
// them as `<fixture name>.json` in this directory
// 4. Add an entry to the fixture list below.
module
.
exports
=
[{
name
:
'Minimal Document'
,
html
:
require
(
'./minimal.html'
),
annotations
:
require
(
'./minimal.json'
),
},{
name
:
'Wikipedia - Regression Testing'
,
html
:
require
(
'./wikipedia-regression-testing.html'
),
annotations
:
require
(
'./wikipedia-regression-testing.json'
),
}];
h/static/scripts/annotator/anchoring/test/html-baselines/minimal.html
0 → 100644
View file @
6460fbc1
<body><div>
One Two Three
</div></body>
h/static/scripts/annotator/anchoring/test/html-baselines/minimal.json
0 → 100644
View file @
6460fbc1
{
"total"
:
1
,
"rows"
:
[{
"id"
:
"test"
,
"target"
:
[{
"selector"
:
[{
"type"
:
"RangeSelector"
,
"startContainer"
:
"/div[1]"
,
"endContainer"
:
"/div[1]"
,
"startOffset"
:
4
,
"endOffset"
:
7
,
},{
"type"
:
"TextPositionSelector"
,
"start"
:
4
,
"end"
:
7
,
},{
"type"
:
"TextQuoteSelector"
,
"prefix"
:
"One "
,
"suffix"
:
" Three
\n
"
,
"exact"
:
"Two"
,
}],
}],
}],
}
h/static/scripts/annotator/anchoring/test/html-baselines/wikipedia-regression-testing.html
0 → 100644
View file @
6460fbc1
This diff is collapsed.
Click to expand it.
h/static/scripts/annotator/anchoring/test/html-baselines/wikipedia-regression-testing.json
0 → 100644
View file @
6460fbc1
This diff is collapsed.
Click to expand it.
h/static/scripts/annotator/anchoring/test/html-test.js
View file @
6460fbc1
...
...
@@ -61,6 +61,15 @@ function findByType(selectors, type) {
return
selectors
.
find
(
function
(
s
)
{
return
s
.
type
===
type
;
});
}
/**
* Return a copy of a list of selectors sorted by type.
*/
function
sortByType
(
selectors
)
{
return
selectors
.
slice
().
sort
(
function
(
a
,
b
)
{
return
a
.
type
.
localeCompare
(
b
.
type
);
});
}
/**
* Test cases for mapping ranges to selectors.
*
...
...
@@ -191,4 +200,50 @@ describe('HTML anchoring', function () {
});
return
Promise
.
all
(
anchored
);
},
testCases
);
describe
(
'Web page baselines'
,
function
()
{
var
fixtures
=
require
(
'./html-baselines'
);
var
frame
;
before
(
function
()
{
frame
=
document
.
createElement
(
'iframe'
);
document
.
body
.
appendChild
(
frame
);
});
after
(
function
()
{
frame
.
remove
();
});
unroll
(
'generates selectors which match the baseline (#name)'
,
function
(
fixture
)
{
var
fixtureHtml
=
fixture
.
html
;
var
annotations
=
fixture
.
annotations
.
rows
;
// Break references to external stylesheets and images so that the test
// runner does not try to load them.
//
// This method is crude but Good Enough™ for our test fixtures and does
// not modify the offset of any substrings within the text content of the
// document for matches that occur in a text-content context (eg.
// <pre>, <noscript>).
fixtureHtml
=
fixtureHtml
.
replace
(
/src=/g
,
'sr_='
).
replace
(
/href=/g
,
'hre_='
);
frame
.
contentWindow
.
document
.
documentElement
.
innerHTML
=
fixtureHtml
;
var
annotationsChecked
=
annotations
.
map
(
function
(
ann
)
{
// Anchor the existing selectors
var
root
=
frame
.
contentWindow
.
document
.
body
;
var
selectors
=
ann
.
target
[
0
].
selector
;
var
result
=
html
.
anchor
(
root
,
selectors
);
return
result
.
then
(
function
(
range
)
{
// Re-anchor the selectors and check that the new and existing
// selectors match.
return
html
.
describe
(
root
,
range
);
}).
then
(
function
(
newSelectors
)
{
assert
.
deepEqual
(
sortByType
(
selectors
),
sortByType
(
newSelectors
));
});
});
return
Promise
.
all
(
annotationsChecked
);
},
fixtures
);
});
});
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