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/15 17:16:50 UTC

[incubator-annotator] branch dom-tests updated: Add a few more cases.

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


The following commit(s) were added to refs/heads/dom-tests by this push:
     new 2b26f66  Add a few more cases.
2b26f66 is described below

commit 2b26f66e2bcd405e711452146200f3251dea7408
Author: Gerben <ge...@treora.com>
AuthorDate: Fri May 15 19:15:59 2020 +0200

    Add a few more cases.
---
 packages/dom/test/text-quote-match.ts | 49 +++++++++++++++++++++++++++++++++--
 1 file changed, 47 insertions(+), 2 deletions(-)

diff --git a/packages/dom/test/text-quote-match.ts b/packages/dom/test/text-quote-match.ts
index 4e9eb57..d94e7ad 100644
--- a/packages/dom/test/text-quote-match.ts
+++ b/packages/dom/test/text-quote-match.ts
@@ -39,7 +39,7 @@ const testCases: {
     expected: RangeInfo[],
   }
 } = {
-  "simple": {
+  'simple': {
     html: `<b>lorem ipsum dolor amet yada yada</b>`,
     selector: {
       type: 'TextQuoteSelector',
@@ -54,6 +54,51 @@ const testCases: {
       },
     ]
   },
+  'across elements': {
+    html: `<b>lorem <i>ipsum dolor</i> amet yada yada</b>`,
+    selector: {
+      type: 'TextQuoteSelector',
+      exact: 'dolor am',
+    },
+    expected: [
+      {
+        startContainer: '//i/text()',
+        startOffset: 6,
+        endContainer: '//b/text()[2]',
+        endOffset: 3,
+      },
+    ]
+  },
+  'exact element contents': {
+    html: `<b>lorem <i>ipsum dolor</i> amet yada yada</b>`,
+    selector: {
+      type: 'TextQuoteSelector',
+      exact: 'ipsum dolor',
+    },
+    expected: [
+      {
+        startContainer: '//i/text()',
+        startOffset: 0,
+        endContainer: '//b/text()[2]',
+        endOffset: 0,
+      },
+    ]
+  },
+  'text inside <head>': {
+    html: `<head><title>The title</title></head><b>lorem ipsum dolor amet yada yada</b>`,
+    selector: {
+      type: 'TextQuoteSelector',
+      exact: 'title',
+    },
+    expected: [
+      {
+        startContainer: '//title/text()',
+        startOffset: 4,
+        endContainer: '//b/text()[1]',
+        endOffset: 0,
+      },
+    ]
+  },
 };
 
 describe('createTextQuoteSelectorMatcher', () => {
@@ -61,7 +106,7 @@ describe('createTextQuoteSelectorMatcher', () => {
     it(`works for case: '${name}'`, async () => {
       const doc = domParser.parseFromString(html, 'text/html');
       const matcher = createTextQuoteSelectorMatcher(selector);
-      const matches = await asyncIterableToArray(matcher(doc.body));
+      const matches = await asyncIterableToArray(matcher(doc));
       assert.equal(matches.length, expected.length);
       matches.forEach((match, i) => {
         assert.include(match, hydrateRange(expected[i], doc));