Skip to content

Commit d77165a

Browse files
author
Mingze
authored
test(cypress): Add E2E tests for selecting annotations (#549)
* test(cypress): Add E2E tests for selecting annotations * test(cypress): Address feedbacks
1 parent 5d509fb commit d77165a

File tree

2 files changed

+48
-42
lines changed

2 files changed

+48
-42
lines changed

test/integration/Region.e2e.test.js

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,24 @@ describe('Regions', () => {
1818
// Enter region creation mode
1919
cy.getByTestId('bp-AnnotationsControls-regionBtn').click();
2020

21-
// Draw a 50x50 region on the first page starting at x50, y50
22-
cy.getByTestId('ba-RegionCreator')
23-
.first()
24-
.trigger('mousedown', {
25-
buttons: 1,
26-
clientX: 50,
27-
clientY: 50,
28-
})
29-
.trigger('mousemove', {
30-
buttons: 1,
31-
clientX: 100,
32-
clientY: 100,
33-
})
34-
.trigger('mouseup');
35-
36-
// Type a message in the reply form and save the new annotation
37-
cy.getByTestId('ba-ReplyField-editor').type('This is an automated test annotation.');
38-
cy.getByTestId('ba-Popup-submit').click();
39-
40-
// Assert that at least one annotation is present on the image
41-
cy.get('[data-testid^="ba-AnnotationTarget"]');
21+
// Add a region annotation on the document
22+
cy.drawRegion();
23+
cy.submitReply();
24+
25+
// Assert that at least one annotation is present on the document and is active
26+
cy.get('[data-testid^="ba-AnnotationTarget"]').should('have.class', 'is-active');
27+
28+
// Exit region creation mode
29+
cy.getByTestId('bp-AnnotationsControls-regionBtn').click();
30+
31+
// Assert that annotation target is not active
32+
cy.get('[data-testid^="ba-AnnotationTarget"]').should('not.have.class', 'is-active');
33+
34+
// Select annotation target
35+
cy.get('[data-testid^="ba-AnnotationTarget"]').click();
36+
37+
// Assert that annotation target is active
38+
cy.get('[data-testid^="ba-AnnotationTarget"]').should('have.class', 'is-active');
4239
});
4340

4441
it('should create a new region on an image', () => {
@@ -55,27 +52,12 @@ describe('Regions', () => {
5552
// Enter region creation mode
5653
cy.getByTestId('bp-AnnotationsControls-regionBtn').click();
5754

58-
// Draw a 100x100 region on the image starting at (200, 200)
59-
cy.getByTestId('ba-RegionCreator')
60-
.first()
61-
.trigger('mousedown', {
62-
buttons: 1,
63-
clientX: 200,
64-
clientY: 200,
65-
})
66-
.trigger('mousemove', {
67-
buttons: 1,
68-
clientX: 300,
69-
clientY: 300,
70-
})
71-
.trigger('mouseup');
72-
73-
// Type a message in the reply form and save the new annotation
74-
cy.getByTestId('ba-ReplyField-editor').type('This is an automated test annotation.');
75-
cy.getByTestId('ba-Popup-submit').click();
76-
77-
// Assert that at least one annotation is present on the image
78-
cy.get('[data-testid^="ba-AnnotationTarget"]');
55+
// Add a region annotation on the image
56+
cy.drawRegion();
57+
cy.submitReply();
58+
59+
// Assert that at least one annotation is present on the image and is active
60+
cy.get('[data-testid^="ba-AnnotationTarget"]').should('have.class', 'is-active');
7961
});
8062

8163
it('should hide region button for rotated image', () => {

test/support/commands.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,27 @@ Cypress.Commands.add('showPreview', (fileId, { token } = {}) => {
99
cy.get('[data-testid="fileid"]').type(fileId);
1010
cy.get('[data-testid="fileid-set"]').click();
1111
});
12+
13+
// Annotations-specific commands
14+
Cypress.Commands.add('drawRegion', ({ x = 200, y = 200, width = 100, height = 100 } = {}) => {
15+
// Draw a width * height region starting at (x, y)
16+
cy.getByTestId('ba-RegionCreator')
17+
.first()
18+
.trigger('mousedown', {
19+
buttons: 1,
20+
clientX: x,
21+
clientY: y,
22+
})
23+
.trigger('mousemove', {
24+
buttons: 1,
25+
clientX: x + width,
26+
clientY: y + height,
27+
})
28+
.trigger('mouseup');
29+
});
30+
31+
Cypress.Commands.add('submitReply', (message = 'Automated test annotations') => {
32+
// Type a message in the reply form and save the new annotation
33+
cy.getByTestId('ba-ReplyField-editor').type(message);
34+
cy.getByTestId('ba-Popup-submit').click();
35+
});

0 commit comments

Comments
 (0)