Skip to content

Commit 5d509fb

Browse files
author
Mingze
authored
test(cypress): Add E2E tests for creating annotations on images (#548)
1 parent e18c6b3 commit 5d509fb

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

test/integration/Region.e2e.test.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,64 @@ describe('Regions', () => {
4040
// Assert that at least one annotation is present on the image
4141
cy.get('[data-testid^="ba-AnnotationTarget"]');
4242
});
43+
44+
it('should create a new region on an image', () => {
45+
// Show the preview
46+
cy.showPreview(Cypress.env('FILE_ID_IMAGE'));
47+
48+
// Wait for the empty region layer to be present
49+
cy.getByTestId('ba-Layer--region');
50+
51+
// Assert that the region creator does not exist and no annotations are present
52+
cy.getByTestId('ba-RegionCreator').should('not.exist');
53+
cy.get('[data-testid^="ba-AnnotationTarget"]').should('not.exist');
54+
55+
// Enter region creation mode
56+
cy.getByTestId('bp-AnnotationsControls-regionBtn').click();
57+
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"]');
79+
});
80+
81+
it('should hide region button for rotated image', () => {
82+
// Show the preview
83+
cy.showPreview(Cypress.env('FILE_ID_IMAGE'));
84+
85+
// Assert region button is not hidden
86+
cy.getByTestId('bp-AnnotationsControls-regionBtn').should('be.visible');
87+
88+
// Rotate image
89+
cy.getByTitle('Rotate left').click();
90+
91+
// Assert region button is hidden
92+
cy.getByTestId('bp-AnnotationsControls-regionBtn').should('not.be.visible');
93+
94+
// Rotate image back to non-rotated state
95+
cy.getByTitle('Rotate left')
96+
.click()
97+
.click()
98+
.click();
99+
100+
// Assert region button is not hidden
101+
cy.getByTestId('bp-AnnotationsControls-regionBtn').should('be.visible');
102+
});
43103
});

0 commit comments

Comments
 (0)