Skip to content

Commit 750617d

Browse files
Mingzemergify[bot]
andauthored
test(cypress): Add E2E tests for selecting highlight annotations (#621)
* test(cypress): Add E2E tests for selecting highlight annotations * test(cypress): Address comments Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 294c3ff commit 750617d

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

src/highlight/HighlightAnnotations.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const HighlightAnnotations = (props: Props): JSX.Element => {
117117
<div className="ba-HighlightAnnotations-target">
118118
<HighlightCanvas shapes={staged.shapes} />
119119
<HighlightSvg>
120-
<HighlightTarget ref={setHighlightRef} annotationId="staged" shapes={staged.shapes} />
120+
<HighlightTarget ref={setHighlightRef} annotationId="staged" isActive shapes={staged.shapes} />
121121
</HighlightSvg>
122122
</div>
123123
)}

src/highlight/HighlightList.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export function HighlightList({ activeId = null, annotations, className, onSelec
8282
<HighlightTarget
8383
key={id}
8484
annotationId={id}
85+
isActive={activeId === id}
8586
onHover={handleTargetHover}
8687
onSelect={onSelect}
8788
shapes={target.shapes}

src/highlight/HighlightTarget.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import './HighlightTarget.scss';
1010
type Props = {
1111
annotationId: string;
1212
className?: string;
13+
isActive?: boolean;
1314
onHover?: (annotationId: string | null) => void;
1415
onSelect?: (annotationId: string) => void;
1516
shapes: Array<Rect>;
@@ -18,7 +19,7 @@ type Props = {
1819
export type HighlightTargetRef = HTMLAnchorElement;
1920

2021
const HighlightTarget = (props: Props, ref: React.Ref<HighlightTargetRef>): JSX.Element => {
21-
const { annotationId, className, onHover = noop, onSelect = noop, shapes } = props;
22+
const { annotationId, className, isActive, onHover = noop, onSelect = noop, shapes } = props;
2223
const isCurrentFileVersion = ReactRedux.useSelector(getIsCurrentFileVersion);
2324

2425
const handleClick = (event: React.MouseEvent<HighlightTargetRef>): void => {
@@ -64,7 +65,7 @@ const HighlightTarget = (props: Props, ref: React.Ref<HighlightTargetRef>): JSX.
6465
// eslint-disable-next-line jsx-a11y/anchor-is-valid
6566
<a
6667
ref={ref}
67-
className={classNames('ba-HighlightTarget', className)}
68+
className={classNames('ba-HighlightTarget', className, { 'is-active': isActive })}
6869
data-resin-iscurrent={isCurrentFileVersion}
6970
data-resin-itemid={annotationId}
7071
data-resin-target="highlightText"

src/highlight/__tests__/HighlightTarget-test.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,20 @@ describe('HighlightTarget', () => {
3333

3434
describe('render()', () => {
3535
test('should render anchor with provided rects', () => {
36-
const wrapper = getWrapper();
37-
const anchor = wrapper.find('a');
38-
const rect = wrapper.find('rect');
39-
40-
expect(anchor.hasClass('is-active')).toBe(false);
41-
expect(anchor.hasClass('is-hover')).toBe(false);
36+
const rect = getWrapper().find('rect');
4237

4338
expect(rect.prop('height')).toBe('10%');
4439
expect(rect.prop('width')).toBe('20%');
4540
expect(rect.prop('x')).toBe('5%');
4641
expect(rect.prop('y')).toBe('5%');
4742
});
43+
44+
test.each([true, false])('should render classNames correctly when isActive is %s', isActive => {
45+
const wrapper = getWrapper({ isActive });
46+
47+
expect(wrapper.hasClass('ba-HighlightTarget')).toBe(true);
48+
expect(wrapper.hasClass('is-active')).toBe(isActive);
49+
});
4850
});
4951

5052
describe('interactivity', () => {

test/integration/Highlight.e2e.test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,19 @@ describe('Highlights', () => {
2121
cy.selectText();
2222
cy.submitReply();
2323

24-
// Assert that at least one highlight annotation is present on the document
25-
cy.get('.ba-HighlightTarget');
24+
// Assert that at least one highlight annotation is present on the document and is active
25+
cy.get('.ba-HighlightTarget').should('have.class', 'is-active');
2626

2727
// Exit highlight creation mode
2828
cy.getByTestId('bp-AnnotationsControls-highlightBtn').click();
29+
30+
// Assert that annotation target is not active
31+
cy.get('.ba-HighlightTarget').should('not.have.class', 'is-active');
32+
33+
// Select annotation target
34+
cy.get('.ba-HighlightTarget-rect').click();
35+
36+
// Assert that annotation target is active
37+
cy.get('.ba-HighlightTarget').should('have.class', 'is-active');
2938
});
3039
});

0 commit comments

Comments
 (0)