mirror of
https://github.com/web-infra-dev/midscene.git
synced 2025-07-07 09:01:38 +00:00

* feat: extract web content as a tree * chore: update test data * chore: update test data * feat: update answer of evaluation * chore: update test cases * chore: remove focusing on cases * fix: ci * fix: put rect in html tree * fix: CI * fix: AI test * fix: lint * fix: CI * fix: static-page compatibility * fix: CI * fix: map by markerId * fix: llm planning prompt * chore: update hash length * chore: ignore writing dump file * fix: lint * fix: ci snapshot * chore: snapshot tree in web extractor * chore: export tree utils in core * chore: export tree utils in core * fix: CI * fix: update test case and evaluation * chore: remove unused file * refactor(extract): modify dependencies (#358) * refactor(extract): modify dependencies * chore: modify files config * chore: add indexId as key for map --------- Co-authored-by: Zhou Xiao <zhouxiao.shaw@bytedance.com>
210 lines
7.5 KiB
TypeScript
210 lines
7.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { NodeType } from '../../src/constants';
|
|
import { descriptionOfTree } from '../../src/extractor/tree';
|
|
|
|
describe('utils', () => {
|
|
const tree = {
|
|
node: {
|
|
attributes: {
|
|
nodeType: NodeType.CONTAINER,
|
|
},
|
|
id: '1',
|
|
indexId: 19,
|
|
rect: {
|
|
x: 0,
|
|
y: 0,
|
|
width: 100,
|
|
height: 100,
|
|
left: 0,
|
|
top: 0,
|
|
},
|
|
center: [50, 50] as [number, number],
|
|
content:
|
|
'Legend had it that the Whispering Woods held an ancient secret, one that connected the world of man and magic, of reality and dream. Each leaf, every rustling branch, was said to carry the whispers of the ancient spirits who protected the forest. Elara often spent her evenings perched on the boundary stones, listening intently to the murmur of the leaves, wondering what secrets they concealed.',
|
|
},
|
|
children: [
|
|
{
|
|
node: {
|
|
attributes: {
|
|
nodeType: NodeType.TEXT,
|
|
ariaLabel:
|
|
'image description, it could be a long text, very loooooooooooooooooooooooooooooooooooooooooong',
|
|
},
|
|
id: '2',
|
|
indexId: 999,
|
|
rect: {
|
|
x: 0,
|
|
y: 0,
|
|
width: 100,
|
|
height: 100,
|
|
left: 0,
|
|
top: 0,
|
|
},
|
|
center: [50, 50] as [number, number],
|
|
content: 'world',
|
|
},
|
|
children: [],
|
|
},
|
|
{
|
|
node: {
|
|
attributes: {
|
|
nodeType: NodeType.IMG,
|
|
style: 'width: 100px; height: 100px;',
|
|
src: 'https://example.com/image.jpg',
|
|
htmlTagName: '<img>',
|
|
ariaLabel: 'image description',
|
|
storyContent:
|
|
'Legend had it that the Whispering Woods held an ancient secret, one that connected the world of man and magic, of reality and dream. Each leaf, every rustling branch, was said to carry the whispers of the ancient spirits who protected the forest. Elara often spent her evenings perched on the boundary stones, listening intently to the murmur of the leaves, wondering what secrets they concealed.',
|
|
},
|
|
id: '3',
|
|
indexId: 20,
|
|
rect: {
|
|
x: 0,
|
|
y: 0,
|
|
width: 100,
|
|
height: 100,
|
|
left: 0,
|
|
top: 0,
|
|
},
|
|
center: [50, 50] as [number, number],
|
|
content: 'world 2345',
|
|
},
|
|
children: [
|
|
{
|
|
node: {
|
|
attributes: {
|
|
nodeType: NodeType.IMG,
|
|
style: 'width: 100px; height: 100px;',
|
|
src: 'https://example.com/image.jpg',
|
|
htmlTagName: '<img>',
|
|
ariaLabel: 'image description',
|
|
storyContent:
|
|
'Legend had it that the Whispering Woods held an ancient secret, one that connected the world of man and magic, of reality and dream. Each leaf, every rustling branch, was said to carry the whispers of the ancient spirits who protected the forest. Elara often spent her evenings perched on the boundary stones, listening intently to the murmur of the leaves, wondering what secrets they concealed.',
|
|
},
|
|
id: '3',
|
|
indexId: 20,
|
|
rect: {
|
|
x: 0,
|
|
y: 0,
|
|
width: 100,
|
|
height: 100,
|
|
left: 0,
|
|
top: 0,
|
|
},
|
|
center: [50, 50] as [number, number],
|
|
content: '',
|
|
},
|
|
children: [],
|
|
},
|
|
{
|
|
node: {
|
|
attributes: {
|
|
nodeType: NodeType.IMG,
|
|
style: 'width: 100px; height: 100px;',
|
|
src: 'https://example.com/image.jpg',
|
|
htmlTagName: '<img>',
|
|
ariaLabel: 'image description',
|
|
storyContent:
|
|
'Legend had it that the Whispering Woods held an ancient secret, one that connected the world of man and magic, of reality and dream. Each leaf, every rustling branch, was said to carry the whispers of the ancient spirits who protected the forest. Elara often spent her evenings perched on the boundary stones, listening intently to the murmur of the leaves, wondering what secrets they concealed.',
|
|
},
|
|
id: '3',
|
|
indexId: 20,
|
|
rect: {
|
|
x: 0,
|
|
y: 0,
|
|
width: 3,
|
|
height: 3,
|
|
left: 0,
|
|
top: 0,
|
|
},
|
|
center: [50, 50] as [number, number],
|
|
content: '',
|
|
},
|
|
children: [],
|
|
},
|
|
{
|
|
node: {
|
|
attributes: {
|
|
nodeType: NodeType.CONTAINER,
|
|
},
|
|
id: '3',
|
|
indexId: 20,
|
|
rect: {
|
|
x: 0,
|
|
y: 0,
|
|
width: 3,
|
|
height: 3,
|
|
left: 0,
|
|
top: 0,
|
|
},
|
|
center: [50, 50] as [number, number],
|
|
content: '',
|
|
},
|
|
children: [
|
|
{
|
|
node: {
|
|
attributes: {
|
|
nodeType: NodeType.IMG,
|
|
},
|
|
id: '3',
|
|
indexId: 20,
|
|
rect: {
|
|
x: 0,
|
|
y: 0,
|
|
width: 3,
|
|
height: 3,
|
|
left: 0,
|
|
top: 0,
|
|
},
|
|
center: [50, 50] as [number, number],
|
|
content: '',
|
|
},
|
|
children: [
|
|
{
|
|
node: {
|
|
attributes: {
|
|
nodeType: NodeType.IMG,
|
|
style: 'width: 100px; height: 100px;',
|
|
src: 'https://example.com/image.jpg',
|
|
htmlTagName: '<img>',
|
|
ariaLabel: 'image description',
|
|
storyContent:
|
|
'Legend had it that the Whispering Woods held an ancient secret, one that connected the world of man and magic, of reality and dream. Each leaf, every rustling branch, was said to carry the whispers of the ancient spirits who protected the forest. Elara often spent her evenings perched on the boundary stones, listening intently to the murmur of the leaves, wondering what secrets they concealed.',
|
|
},
|
|
id: '3222',
|
|
indexId: 20,
|
|
rect: {
|
|
x: 0,
|
|
y: 0,
|
|
width: 100,
|
|
height: 100,
|
|
left: 0,
|
|
top: 0,
|
|
},
|
|
center: [50, 50] as [number, number],
|
|
content: 'world 2345',
|
|
},
|
|
children: [],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
it('should be able to describe tree', async () => {
|
|
const description = descriptionOfTree(tree);
|
|
// console.log(description);
|
|
expect(description).toMatchSnapshot();
|
|
});
|
|
|
|
it('should be able to describe tree, filterNonTextContent = true', async () => {
|
|
const description = descriptionOfTree(tree, 20, true);
|
|
// console.log(description);
|
|
expect(description).toMatchSnapshot();
|
|
});
|
|
});
|