You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@annotator.apache.org by ge...@apache.org on 2020/05/25 18:03:29 UTC
[incubator-annotator] 05/08: Simple (but failing!) tests for
minimal prefix+suffix
This is an automated email from the ASF dual-hosted git repository.
gerben pushed a commit to branch dom-tests
in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git
commit d5bd5cb0fefb8fdee8f6900b00c13f7796550eb5
Author: Gerben <ge...@treora.com>
AuthorDate: Mon May 25 15:52:37 2020 +0200
Simple (but failing!) tests for minimal prefix+suffix
---
packages/dom/test/text-quote-describe-cases.ts | 95 ++++++++++++++++++++++++++
packages/dom/test/text-quote-describe.ts | 9 +++
2 files changed, 104 insertions(+)
diff --git a/packages/dom/test/text-quote-describe-cases.ts b/packages/dom/test/text-quote-describe-cases.ts
new file mode 100644
index 0000000..29c0d83
--- /dev/null
+++ b/packages/dom/test/text-quote-describe-cases.ts
@@ -0,0 +1,95 @@
+import { TextQuoteSelector } from "../../selector/src";
+import { RangeInfo } from "./utils";
+
+const testCases: {
+ [name: string]: {
+ html: string,
+ range: RangeInfo,
+ expected: TextQuoteSelector,
+ }
+} = {
+ 'simple': {
+ html: '<b>lorem ipsum dolor amet yada yada</b>',
+ range: {
+ startContainerXPath: '//b/text()',
+ startOffset: 12,
+ endContainerXPath: '//b/text()',
+ endOffset: 20,
+ },
+ expected: {
+ type: 'TextQuoteSelector',
+ exact: 'dolor am',
+ prefix: '',
+ suffix: '',
+ },
+ },
+ 'minimal prefix': {
+ html: '<b>To annotate or not to annotate.</b>',
+ range: {
+ startContainerXPath: '//b/text()',
+ startOffset: 22,
+ endContainerXPath: '//b/text()',
+ endOffset: 26,
+ },
+ expected: {
+ type: 'TextQuoteSelector',
+ exact: 'anno',
+ prefix: 'to ',
+ suffix: '',
+ },
+ },
+ 'minimal suffix': {
+ html: '<b>To annotate or not to annotate.</b>',
+ range: {
+ startContainerXPath: '//b/text()',
+ startOffset: 7,
+ endContainerXPath: '//b/text()',
+ endOffset: 11,
+ },
+ expected: {
+ type: 'TextQuoteSelector',
+ exact: 'tate',
+ prefix: '',
+ suffix: ' ',
+ },
+ },
+ 'use suffix for start of text': {
+ html: '<b>to annotate or not to annotate.</b>',
+ range: {
+ startContainerXPath: '//b/text()',
+ startOffset: 0,
+ endContainerXPath: '//b/text()',
+ endOffset: 2,
+ },
+ expected: {
+ type: 'TextQuoteSelector',
+ exact: 'to',
+ prefix: '',
+ suffix: ' annotate ',
+ },
+ },
+ 'use prefix for end of text': {
+ html: '<b>To annotate or not to annotate</b>',
+ range: {
+ startContainerXPath: '//b/text()',
+ startOffset: 26,
+ endContainerXPath: '//b/text()',
+ endOffset: 30,
+ },
+ expected: {
+ type: 'TextQuoteSelector',
+ exact: 'tate',
+ prefix: 'to anno',
+ suffix: '',
+ },
+ },
+
+ // TODO test for:
+ // emtpy range
+ // empty scope
+ // custom scope
+ // string edges
+ // element edges, across elements, etc.
+};
+
+export default testCases;
diff --git a/packages/dom/test/text-quote-describe.ts b/packages/dom/test/text-quote-describe.ts
index 8d9f74c..15447b7 100644
--- a/packages/dom/test/text-quote-describe.ts
+++ b/packages/dom/test/text-quote-describe.ts
@@ -20,12 +20,21 @@
import { assert } from 'chai';
import { describeTextQuote } from '../src/text-quote/describe';
+import testCases from './text-quote-describe-cases';
import testMatchCases from './text-quote-match-cases';
import { hydrateRange } from './utils';
const domParser = new window.DOMParser();
describe('createTextQuoteSelectorMatcher', () => {
+ for (const [name, { html, range, expected }] of Object.entries(testCases)) {
+ it(`works for case: ${name}`, async () => {
+ const doc = domParser.parseFromString(html, 'text/html');
+ const result = await describeTextQuote(hydrateRange(range, doc), doc);
+ assert.deepEqual(result, expected);
+ })
+ }
+
describe('inverts test cases of text quote matcher', () => {
const applicableTestCases = Object.entries(testMatchCases)
.filter(([_, { expected }]) => expected.length > 0);