@konfuzio/document-validation-ui 0.1.18-dev.4 → 0.1.19-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import DocumentDashboard from "../DocumentDashboard.vue";
|
|
2
|
+
import DocumentPage from "../DocumentPage/DocumentPage.vue";
|
|
3
|
+
|
|
4
|
+
const viewport = {
|
|
5
|
+
width: 1280,
|
|
6
|
+
height: 1300,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
describe("Document Page", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
cy.fetchDocument();
|
|
12
|
+
cy.setFullMode();
|
|
13
|
+
cy.viewport(viewport.width, viewport.height);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("All annotations appear at the right place", () => {
|
|
17
|
+
cy.getStore("document").then(($document) => {
|
|
18
|
+
if (
|
|
19
|
+
$document.selectedDocument.pages[0] &&
|
|
20
|
+
$document.annotations &&
|
|
21
|
+
$document.annotations.length > 0
|
|
22
|
+
) {
|
|
23
|
+
cy.setScale($document.selectedDocument.pages[0]);
|
|
24
|
+
cy.fetchBlob(
|
|
25
|
+
`${$document.selectedDocument.pages[0].image_url}?${$document.selectedDocument.downloaded_at}`
|
|
26
|
+
).then((blob) => {
|
|
27
|
+
cy.mount(DocumentPage, {
|
|
28
|
+
propsData: {
|
|
29
|
+
page: $document.selectedDocument.pages[0],
|
|
30
|
+
imageBlob: blob,
|
|
31
|
+
},
|
|
32
|
+
}).then(({ wrapper, component }) => {
|
|
33
|
+
$document.annotations.forEach((annotation) => {
|
|
34
|
+
const values = component.annotationRect(annotation.span[0]);
|
|
35
|
+
if (values.y < viewport.height) {
|
|
36
|
+
// check if ann is visible on viewport
|
|
37
|
+
cy.get(".pdf-page-container").click(values.x, values.y);
|
|
38
|
+
|
|
39
|
+
cy.getStore("document").then(($newDocument) => {
|
|
40
|
+
if ($newDocument.sidebarAnnotationSelected) {
|
|
41
|
+
expect(
|
|
42
|
+
$newDocument.sidebarAnnotationSelected.annotation.id
|
|
43
|
+
).to.eql(annotation.id);
|
|
44
|
+
} else {
|
|
45
|
+
throw new Error("Annotation not on right place");
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
} else {
|
|
53
|
+
throw new Error("Document has no annotations");
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("Can click on an entity", () => {
|
|
59
|
+
cy.getStore("document").then(($document) => {
|
|
60
|
+
if ($document.selectedDocument.pages[0]) {
|
|
61
|
+
cy.setScale($document.selectedDocument.pages[0]);
|
|
62
|
+
cy.fetchBlob(
|
|
63
|
+
`${$document.selectedDocument.pages[0].image_url}?${$document.selectedDocument.downloaded_at}`
|
|
64
|
+
).then((blob) => {
|
|
65
|
+
cy.mount(DocumentPage, {
|
|
66
|
+
propsData: {
|
|
67
|
+
page: $document.pages[0],
|
|
68
|
+
imageBlob: blob,
|
|
69
|
+
},
|
|
70
|
+
}).then(({ wrapper, component }) => {
|
|
71
|
+
if ($document.pages && $document.pages.length > 0) {
|
|
72
|
+
const entities = $document.pages.flatMap((page) => {
|
|
73
|
+
return page.entities;
|
|
74
|
+
});
|
|
75
|
+
const entity =
|
|
76
|
+
entities[Math.floor(Math.random() * entities.length)]; // get a random entity
|
|
77
|
+
const values = component.entityRect(entity);
|
|
78
|
+
if (values.y < viewport.height) {
|
|
79
|
+
cy.get(".pdf-page-container").click(values.x, values.y);
|
|
80
|
+
cy.get(".annotation-popup").should("exist");
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
cy.get(".annotation-popup").should("not.exist");
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
throw new Error("Document has no pages");
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -143,6 +143,11 @@ export default {
|
|
|
143
143
|
type: Object,
|
|
144
144
|
required: true,
|
|
145
145
|
},
|
|
146
|
+
imageBlob: {
|
|
147
|
+
type: Blob,
|
|
148
|
+
required: false,
|
|
149
|
+
default: null,
|
|
150
|
+
},
|
|
146
151
|
},
|
|
147
152
|
|
|
148
153
|
data() {
|
|
@@ -458,22 +463,31 @@ export default {
|
|
|
458
463
|
if (this.image && !force) {
|
|
459
464
|
return;
|
|
460
465
|
}
|
|
461
|
-
const image = new Image();
|
|
462
466
|
if (process.env.NODE_ENV === "test") {
|
|
463
467
|
return;
|
|
464
468
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
)
|
|
469
|
-
.
|
|
470
|
-
image
|
|
471
|
-
image
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
469
|
+
|
|
470
|
+
const convertBlob = (blob) => {
|
|
471
|
+
const image = new Image();
|
|
472
|
+
image.src = URL.createObjectURL(blob);
|
|
473
|
+
image.onload = () => {
|
|
474
|
+
// set image only when it is loaded
|
|
475
|
+
this.image = image;
|
|
476
|
+
};
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
if (!this.imageBlob) {
|
|
480
|
+
api
|
|
481
|
+
.makeFileRequest(
|
|
482
|
+
`${this.page.image_url}?${this.selectedDocument.downloaded_at}`
|
|
483
|
+
)
|
|
484
|
+
.then((myBlob) => {
|
|
485
|
+
convertBlob(myBlob);
|
|
486
|
+
})
|
|
487
|
+
.catch((error) => {});
|
|
488
|
+
} else {
|
|
489
|
+
convertBlob(this.imageBlob);
|
|
490
|
+
}
|
|
477
491
|
},
|
|
478
492
|
|
|
479
493
|
/**
|