Skip to content

Commit

Permalink
chore: fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoushaw committed Sep 29, 2024
1 parent 1489394 commit de5252f
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/web-integration/src/extractor/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export interface ExtractedRect {
zoom: number;
}

function getRect(el: HTMLElement | Node, baseZoom = 1): ExtractedRect {
export function getRect(el: HTMLElement | Node, baseZoom = 1): ExtractedRect {
let originalRect: DOMRect;
let newZoom = 1;
if (!(el instanceof HTMLElement)) {
Expand Down Expand Up @@ -229,8 +229,8 @@ export function visibleRect(
}

// check if the element is covered by another element
// zoom can cause the element to be covered by another element
if (baseZoom !== 1 && isElementCovered(el, rect)) {
// if the element is zoomed, the coverage check should be done with the original zoom
if (baseZoom === 1 && isElementCovered(el, rect)) {
return false;
}

Expand Down
4 changes: 3 additions & 1 deletion packages/web-integration/src/extractor/web-extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getDocument,
getNodeAttributes,
getPseudoElementContent,
getRect,
logger,
midsceneGenerateHash,
setDataForNode,
Expand Down Expand Up @@ -252,9 +253,10 @@ export function extractTextWithPosition(
return elementInfo;
}

const rect = getRect(node, baseZoom);
for (let i = 0; i < node.childNodes.length; i++) {
logger('will dfs', node.childNodes[i]);
dfs(node.childNodes[i], `${nodePath}-${i}`, elementInfo?.zoom);
dfs(node.childNodes[i], `${nodePath}-${i}`, rect.zoom);
}

if (!elementInfo) {
Expand Down
2 changes: 1 addition & 1 deletion packages/web-integration/tests/ai/web/puppeteer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function launchPage(
},
) {
const browser = await puppeteer.launch({
headless: typeof opt?.headless === 'boolean' ? opt.headless : true,
headless: typeof opt?.headless === 'boolean' ? opt.headless : false,
});
const originPage = (await browser.pages())[0];
const viewportConfig = {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit de5252f

Please sign in to comment.