Skip to content

Commit

Permalink
Fix: Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum committed Jan 17, 2019
1 parent 548278f commit 23ff128
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 213 deletions.
18 changes: 18 additions & 0 deletions src/__tests__/AnnotationThread-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-unused-expressions */
import * as ReactDOM from 'react-dom';
import AnnotationThread from '../AnnotationThread';
import * as util from '../util';
import {
Expand Down Expand Up @@ -117,6 +118,23 @@ describe('AnnotationThread', () => {
});
});

describe('renderAnnotationPopover()', () => {
beforeEach(() => {
thread.getPopoverParent = jest.fn().mockReturnValue(rootElement);
util.getPopoverLayer = jest.fn().mockReturnValue(rootElement);
util.shouldDisplayMobileUI = jest.fn().mockReturnValue(false);
thread.scrollIntoView = jest.fn();
ReactDOM.render = jest.fn();
thread.position = jest.fn();
});

it('should render and display the popover for this annotation', () => {
thread.renderAnnotationPopover();
expect(thread.popoverComponent).not.toBeUndefined();
expect(thread.scrollIntoView).toBeCalled();
});
});

describe('hide()', () => {
it('should hide the thread element', () => {
thread.unmountPopover = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,14 @@ describe('components/AnnotationPopover', () => {
expect(wrapper.find('.ba-inline-popover').length).toEqual(1);
});

test('should correctly render a BRUI Overlay if not on mobile', () => {
const wrapper = render({
canAnnotate: true,
comments,
isMobile: false
});
expect(wrapper).toMatchSnapshot();
expect(wrapper.find('Overlay').prop('shouldDefaultFocus')).toBeTruthy();
});

test('should correctly render a div without a Focus Trap if on mobile', () => {
test('should correctly render a div without a Focus Trap', () => {
const wrapper = render({
canAnnotate: true,
comments,
isMobile: true
});
expect(wrapper).toMatchSnapshot();
expect(wrapper.find('Overlay').prop('shouldDefaultFocus')).toBeFalsy();
expect(wrapper.find('Overlay').exists()).toBeFalsy();
});

test('should correctly render a popover with comments and reply textarea', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,111 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`components/AnnotationPopover should correctly render a BRUI Overlay if not on mobile 1`] = `
<Internationalize>
<div
className="ba-popover"
>
<span
className="ba-popover-caret"
/>
<Overlay
shouldDefaultFocus={true}
>
<CommentList
comments={
Array [
Object {
"createdAt": "2017-09-27T10:40:41-07:00",
"createdBy": Object {
"email": "[email protected]",
"id": "789ghi",
"name": "Mia Thermopolis",
"type": "user",
},
"id": "123",
"message": "test",
"permissions": Object {},
},
Object {
"createdAt": "2017-09-27T10:40:41-07:00",
"createdBy": Object {
"email": "[email protected]",
"id": "789ghi",
"name": "Mia Thermopolis",
"type": "user",
},
"id": "456",
"message": "test",
"permissions": Object {},
},
]
}
onDelete={
[MockFunction] {
"calls": Array [
Array [],
],
"results": Array [
Object {
"isThrow": false,
"value": undefined,
},
],
}
}
/>
<ActionControls
canComment={false}
canDelete={false}
hasComments={true}
isPending={false}
onCancel={
[MockFunction] {
"calls": Array [
Array [],
],
"results": Array [
Object {
"isThrow": false,
"value": undefined,
},
],
}
}
onCommentClick={[Function]}
onCreate={
[MockFunction] {
"calls": Array [
Array [],
],
"results": Array [
Object {
"isThrow": false,
"value": undefined,
},
],
}
}
onDelete={
[MockFunction] {
"calls": Array [
Array [],
],
"results": Array [
Object {
"isThrow": false,
"value": undefined,
},
],
}
}
/>
</Overlay>
</div>
</Internationalize>
`;

exports[`components/AnnotationPopover should correctly render a div without a Focus Trap if on mobile 1`] = `
exports[`components/AnnotationPopover should correctly render a div without a Focus Trap 1`] = `
<Internationalize>
<div
className="ba-popover ba-animate-popover"
Expand Down Expand Up @@ -140,8 +35,8 @@ exports[`components/AnnotationPopover should correctly render a div without a Fo
/>
</PlainButton>
</span>
<Overlay
shouldDefaultFocus={false}
<div
className="ba-popover-overlay"
>
<CommentList
comments={
Expand Down Expand Up @@ -232,7 +127,7 @@ exports[`components/AnnotationPopover should correctly render a div without a Fo
}
}
/>
</Overlay>
</div>
</div>
</Internationalize>
`;
Expand All @@ -245,8 +140,8 @@ exports[`components/AnnotationPopover should correctly render a pending annotati
<span
className="ba-popover-caret"
/>
<Overlay
shouldDefaultFocus={true}
<div
className="ba-popover-overlay"
>
<AnnotatorLabel
isPending={true}
Expand Down Expand Up @@ -297,7 +192,7 @@ exports[`components/AnnotationPopover should correctly render a pending annotati
}
}
/>
</Overlay>
</div>
</div>
</Internationalize>
`;
Expand All @@ -310,8 +205,8 @@ exports[`components/AnnotationPopover should correctly render a popover with com
<span
className="ba-popover-caret"
/>
<Overlay
shouldDefaultFocus={true}
<div
className="ba-popover-overlay"
>
<CommentList
comments={
Expand Down Expand Up @@ -402,7 +297,7 @@ exports[`components/AnnotationPopover should correctly render a popover with com
}
}
/>
</Overlay>
</div>
</div>
</Internationalize>
`;
Expand All @@ -415,8 +310,8 @@ exports[`components/AnnotationPopover should correctly render a view-only popove
<span
className="ba-popover-caret"
/>
<Overlay
shouldDefaultFocus={true}
<div
className="ba-popover-overlay"
>
<CommentList
comments={
Expand Down Expand Up @@ -461,7 +356,7 @@ exports[`components/AnnotationPopover should correctly render a view-only popove
}
}
/>
</Overlay>
</div>
</div>
</Internationalize>
`;
Expand All @@ -474,8 +369,8 @@ exports[`components/AnnotationPopover should correctly render an annotation with
<span
className="ba-popover-caret"
/>
<Overlay
shouldDefaultFocus={true}
<div
className="ba-popover-overlay"
>
<AnnotatorLabel
isPending={false}
Expand Down Expand Up @@ -528,7 +423,7 @@ exports[`components/AnnotationPopover should correctly render an annotation with
}
type="highlight"
/>
</Overlay>
</div>
</div>
</Internationalize>
`;
Expand All @@ -541,14 +436,14 @@ exports[`components/AnnotationPopover should render a view-only annotation with
<span
className="ba-popover-caret"
/>
<Overlay
shouldDefaultFocus={true}
<div
className="ba-popover-overlay"
>
<AnnotatorLabel
isPending={false}
type="highlight"
/>
</Overlay>
</div>
</div>
</Internationalize>
`;
9 changes: 0 additions & 9 deletions src/doc/DocAnnotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -842,15 +842,6 @@ class DocAnnotator extends Annotator {
super.toggleAnnotationMode(mode);
}

/** @inheritdoc */
hideAnnotations(event: ?Event) {
if (event && util.isInDialog(event, this.container)) {
return;
}

super.hideAnnotations();
}

/**
* Delegates click event to click handlers for threads on the page.
*
Expand Down
Loading

0 comments on commit 23ff128

Please sign in to comment.