From 7d0116c322eb27648589adc4978202ca5e504892 Mon Sep 17 00:00:00 2001 From: tangxiaomian Date: Mon, 26 Sep 2022 22:10:28 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20add=20getContainerXPath=20test=20(#?= =?UTF-8?q?2132)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kuitos --- src/__tests__/utils.test.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/__tests__/utils.test.ts b/src/__tests__/utils.test.ts index 30c12ce..b735904 100644 --- a/src/__tests__/utils.test.ts +++ b/src/__tests__/utils.test.ts @@ -2,6 +2,7 @@ import { version } from '../../package.json'; import { Deferred, genAppInstanceIdByName, + getContainerXPath, getDefaultTplWrapper, getWrapperId, getXPathForElement, @@ -101,6 +102,40 @@ it('Deferred should worked [2]', async () => { expect(err).toBeInstanceOf(Error); }); +it('should getContainerXPath work well', () => { + const article = document.createElement('article'); + article.innerHTML = ` +
+
+
+
+
+ `; + + document.body.appendChild(article); + // const testNode = document.querySelector('#testNode'); + const xpath = getContainerXPath('#testNode'); + expect(xpath).toEqual( + // eslint-disable-next-line max-len + `/*[name()='HTML']/*[name()='BODY'][1]/*[name()='ARTICLE'][1]/*[name()='DIV'][1]/*[name()='DIV'][2]`, + ); + const testNode2 = document.createElement('div'); + testNode2.innerHTML = ` +
+ `; + + document.body.appendChild(testNode2); + const xpath1 = getContainerXPath(testNode2); + + expect(xpath1).toEqual( + // eslint-disable-next-line max-len + `/*[name()='HTML']/*[name()='BODY'][1]/*[name()='DIV'][1]`, + ); + + const xpath2 = getContainerXPath(undefined); + expect(xpath2).toBeUndefined(); +}); + it('should getXPathForElement work well', () => { const article = document.createElement('article'); article.innerHTML = `