From 932a9a3847d47db630c0251db5c1207bc778920b Mon Sep 17 00:00:00 2001 From: Cashew Date: Sat, 6 Jan 2024 20:48:57 +0700 Subject: [PATCH] remove duplicate --- test/document-util.test.js | 108 ------------------------------------- 1 file changed, 108 deletions(-) diff --git a/test/document-util.test.js b/test/document-util.test.js index d7451f6978..98816725fb 100644 --- a/test/document-util.test.js +++ b/test/document-util.test.js @@ -231,114 +231,6 @@ describe('Document utility tests', () => { // Clean source.cleanup(); }); - // Get test parameters - /** @type {import('test/document-util').DocumentUtilTestData} */ - const { - elementFromPointSelector, - caretRangeFromPointSelector, - startNodeSelector, - startOffset, - endNodeSelector, - endOffset, - resultType, - sentenceScanExtent, - sentence, - hasImposter, - terminateAtNewlines - } = parseJson(/** @type {string} */ (testElement.dataset.testData)); - - const elementFromPointValue = querySelectorChildOrSelf(testElement, elementFromPointSelector); - const caretRangeFromPointValue = querySelectorChildOrSelf(testElement, caretRangeFromPointSelector); - const startNode = getChildTextNodeOrSelf(window, querySelectorChildOrSelf(testElement, startNodeSelector)); - const endNode = getChildTextNodeOrSelf(window, querySelectorChildOrSelf(testElement, endNodeSelector)); - - // Defaults to true - const terminateAtNewlines2 = typeof terminateAtNewlines === 'boolean' ? terminateAtNewlines : true; - - expect(elementFromPointValue).not.toStrictEqual(null); - expect(caretRangeFromPointValue).not.toStrictEqual(null); - expect(startNode).not.toStrictEqual(null); - expect(endNode).not.toStrictEqual(null); - - // Setup functions - document.elementFromPoint = () => elementFromPointValue; - - document.caretRangeFromPoint = (x, y) => { - const imposter = getChildTextNodeOrSelf(window, findImposterElement(document)); - expect(!!imposter).toStrictEqual(!!hasImposter); - - const range = document.createRange(); - range.setStart(/** @type {Node} */ (imposter ? imposter : startNode), startOffset); - range.setEnd(/** @type {Node} */ (imposter ? imposter : startNode), endOffset); - - // Override getClientRects to return a rect guaranteed to contain (x, y) - range.getClientRects = () => { - /** @type {import('test/document-types').PseudoDOMRectList} */ - const domRectList = Object.assign( - [new DOMRect(x - 1, y - 1, 2, 2)], - { - /** - * @this {DOMRect[]} - * @param {number} index - * @returns {DOMRect} - */ - item: function item(index) { return this[index]; } - } - ); - return domRectList; - }; - return range; - }; - - // Test docRangeFromPoint - const source = DocumentUtil.getRangeFromPoint(0, 0, { - deepContentScan: false, - normalizeCssZoom: true - }); - switch (resultType) { - case 'TextSourceRange': - expect(getPrototypeOfOrNull(source)).toStrictEqual(TextSourceRange.prototype); - break; - case 'TextSourceElement': - expect(getPrototypeOfOrNull(source)).toStrictEqual(TextSourceElement.prototype); - break; - case 'null': - expect(source).toStrictEqual(null); - break; - default: - expect.unreachable(); - break; - } - if (source === null) { continue; } - - // Sentence info - const terminatorString = '…。..??!!'; - const terminatorMap = new Map(); - for (const char of terminatorString) { - terminatorMap.set(char, [false, true]); - } - const quoteArray = [['「', '」'], ['『', '』'], ['\'', '\''], ['"', '"']]; - const forwardQuoteMap = new Map(); - const backwardQuoteMap = new Map(); - for (const [char1, char2] of quoteArray) { - forwardQuoteMap.set(char1, [char2, false]); - backwardQuoteMap.set(char2, [char1, false]); - } - - // Test docSentenceExtract - const sentenceActual = DocumentUtil.extractSentence( - source, - false, - sentenceScanExtent, - terminateAtNewlines2, - terminatorMap, - forwardQuoteMap, - backwardQuoteMap - ).text; - expect(sentenceActual).toStrictEqual(sentence); - - // Clean - source.cleanup(); } }); });