Skip to content

Commit 08685f2

Browse files
author
Conrad Chan
authored
test(cypress): Adding discoverability tests (#672)
1 parent 154c28e commit 08685f2

File tree

5 files changed

+90
-14
lines changed

5 files changed

+90
-14
lines changed

test/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,16 @@
5656
}
5757

5858
/* global BoxAnnotations */
59-
var annotations = new BoxAnnotations(null, { features: { drawing: true } });
59+
var annotations = new BoxAnnotations(null, { features: { discoverability: true, drawing: true } });
6060

6161
/* global Box */
6262
var preview = new Box.Preview();
6363

6464
preview.show(fileid, token, {
6565
container: '.preview-container',
6666
boxAnnotations: annotations,
67+
enableAnnotationsDiscoverability: true,
68+
enableAnnotationsImageDiscoverability: true,
6769
showAnnotations: true,
6870
showAnnotationsControls: true,
6971
showAnnotationsDrawingCreate: true,
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/// <reference types="Cypress" />
2+
describe('Discoverability', () => {
3+
beforeEach(() => {
4+
cy.visit('/');
5+
});
6+
7+
it('should be able to draw a region without entering the mode', () => {
8+
// Show the preview
9+
cy.showPreview(Cypress.env('FILE_ID_DOC_SANITY'));
10+
11+
// Wait for the region layer to be present
12+
cy.getByTestId('ba-Layer--region');
13+
14+
// Add a region annotation on the document
15+
cy.drawRegion();
16+
cy.getByTestId('ba-Popup-cancel').click();
17+
18+
// Assert that annotation target is not active
19+
cy.get('.ba-RegionAnnotation').should('not.have.class', 'is-active');
20+
21+
// Select annotation target
22+
cy.get('.ba-RegionAnnotation').click();
23+
24+
// Assert that annotation target is active
25+
cy.get('.ba-RegionAnnotation').should('have.class', 'is-active');
26+
});
27+
28+
it('should be able to promote a highlight without entering the mode', () => {
29+
// Show the preview
30+
cy.showPreview(Cypress.env('FILE_ID_DOC_SANITY'));
31+
32+
// Wait for the region layer to be present
33+
cy.getByTestId('ba-Layer--highlight');
34+
35+
// Add a highlight annotation on the document
36+
cy.selectText();
37+
cy.getByTestId('ba-PopupHighlight-button').click();
38+
cy.getByTestId('ba-Popup-cancel').click();
39+
40+
// Assert that annotation target is not active
41+
cy.get('.ba-HighlightTarget').should('not.have.class', 'is-active');
42+
43+
// Select annotation target
44+
cy.get('.ba-HighlightTarget-rect')
45+
.first()
46+
.click();
47+
48+
// Assert that annotation target is active
49+
cy.get('.ba-HighlightTarget').should('have.class', 'is-active');
50+
});
51+
52+
it('should leave region mode if zooming in on an image', () => {
53+
// Show the preview
54+
cy.showPreview(Cypress.env('FILE_ID_IMAGE_SANITY'));
55+
56+
// Wait for annotations to load
57+
cy.get('.bp-image').should('have.class', 'ba-annotations-loaded');
58+
59+
// Check that after zooming in, the region annotation button is no longer active
60+
cy.getByTestId('bp-AnnotationsControls-regionBtn').should('have.class', 'bp-is-active');
61+
cy.getByTestId('bp-ZoomControls-in').click();
62+
cy.getByTestId('bp-AnnotationsControls-regionBtn').should('not.have.class', 'bp-is-active');
63+
});
64+
65+
it('should remain in region mode after initial zoom occurs on an image', () => {
66+
// Show the preview
67+
cy.showPreview(Cypress.env('FILE_ID_IMAGE_SANITY'));
68+
69+
// Wait for annotations to load
70+
cy.get('.bp-image').should('have.class', 'ba-annotations-loaded');
71+
72+
// Check that after zooming in, the region annotation button is no longer active
73+
cy.getByTestId('bp-AnnotationsControls-regionBtn').should('have.class', 'bp-is-active');
74+
cy.getByTestId('bp-ZoomControls-in').click();
75+
cy.getByTestId('bp-AnnotationsControls-regionBtn')
76+
.should('not.have.class', 'bp-is-active')
77+
.click()
78+
.should('have.class', 'bp-is-active');
79+
80+
cy.getByTestId('bp-ZoomControls-out').click();
81+
cy.getByTestId('bp-AnnotationsControls-regionBtn').should('have.class', 'bp-is-active');
82+
});
83+
});

test/integration/Region.e2e.test.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ describe('Regions', () => {
1111
// Wait for the empty region layer to be present
1212
cy.getByTestId('ba-Layer--region');
1313

14-
// Assert that the region creator does not exist and no annotations are present
15-
cy.getByTestId('ba-RegionCreator').should('not.exist');
14+
// Assert that no annotations are present
1615
cy.get('.ba-RegionAnnotation').should('not.exist');
1716

1817
// Enter region creation mode
@@ -45,13 +44,9 @@ describe('Regions', () => {
4544
// Wait for the empty region layer to be present
4645
cy.getByTestId('ba-Layer--region');
4746

48-
// Assert that the region creator does not exist and no annotations are present
49-
cy.getByTestId('ba-RegionCreator').should('not.exist');
47+
// Assert that no annotations are present
5048
cy.get('.ba-RegionAnnotation').should('not.exist');
5149

52-
// Enter region creation mode
53-
cy.getByTestId('bp-AnnotationsControls-regionBtn').click();
54-
5550
// Add a region annotation on the image
5651
cy.drawRegion();
5752
cy.submitReply();

test/integration/Sanity.e2e.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ describe('Annotations', () => {
88
// Show the preview
99
cy.showPreview(Cypress.env('FILE_ID_DOC_SANITY'));
1010

11-
// Wait for viewer to load
12-
cy.get('.bp').should('have.class', 'bp-loaded');
1311
// Wait for annotations to load
1412
cy.get('.bp-doc').should('have.class', 'ba-annotations-loaded');
1513

1614
// Assert document content is present
17-
cy.contains('The Content Platform for Your Apps');
15+
cy.contains('Chicken Chicken Chicken: Chicken Chicken');
1816

1917
// Assert that at least one annotation is present on the document
2018
cy.get('[data-testid^="ba-AnnotationTarget"]');
@@ -24,8 +22,6 @@ describe('Annotations', () => {
2422
// Show the preview
2523
cy.showPreview(Cypress.env('FILE_ID_IMAGE_SANITY'));
2624

27-
// Wait for viewer to load
28-
cy.get('.bp').should('have.class', 'bp-loaded');
2925
// Wait for annotations to load
3026
cy.get('.bp-image').should('have.class', 'ba-annotations-loaded');
3127

test/support/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Cypress.env({
2-
FILE_ID_DOC_SANITY: '694517832310', // Read-only
2+
FILE_ID_DOC_SANITY: '764564067308', // Read-only
33
FILE_ID_IMAGE_SANITY: '694517831110', // Read-only
44
});

0 commit comments

Comments
 (0)