Commit a8146c9e authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Move `ShareAnnotationsPanel` => `ShareDialog`

parent ffa32aa9
...@@ -16,7 +16,7 @@ import AnnotationView from './AnnotationView'; ...@@ -16,7 +16,7 @@ import AnnotationView from './AnnotationView';
import HelpPanel from './HelpPanel'; import HelpPanel from './HelpPanel';
import NotebookView from './NotebookView'; import NotebookView from './NotebookView';
import ProfileView from './ProfileView'; import ProfileView from './ProfileView';
import ShareAnnotationsPanel from './ShareAnnotationsPanel'; import ShareDialog from './ShareDialog';
import SidebarView from './SidebarView'; import SidebarView from './SidebarView';
import StreamView from './StreamView'; import StreamView from './StreamView';
import ToastMessages from './ToastMessages'; import ToastMessages from './ToastMessages';
...@@ -160,7 +160,7 @@ function HypothesisApp({ ...@@ -160,7 +160,7 @@ function HypothesisApp({
<div className="container"> <div className="container">
<ToastMessages /> <ToastMessages />
<HelpPanel /> <HelpPanel />
<ShareAnnotationsPanel /> <ShareDialog />
{route && ( {route && (
<main> <main>
......
...@@ -17,13 +17,13 @@ import classnames from 'classnames'; ...@@ -17,13 +17,13 @@ import classnames from 'classnames';
import type { ComponentChildren, JSX } from 'preact'; import type { ComponentChildren, JSX } from 'preact';
import { useCallback, useState } from 'preact/hooks'; import { useCallback, useState } from 'preact/hooks';
import { pageSharingLink } from '../helpers/annotation-sharing'; import { pageSharingLink } from '../../helpers/annotation-sharing';
import { withServices } from '../service-context'; import { withServices } from '../../service-context';
import type { ToastMessengerService } from '../services/toast-messenger'; import type { ToastMessengerService } from '../../services/toast-messenger';
import { useSidebarStore } from '../store'; import { useSidebarStore } from '../../store';
import { copyText } from '../util/copy-to-clipboard'; import { copyText } from '../../util/copy-to-clipboard';
import ShareLinks from './ShareLinks'; import ShareLinks from '../ShareLinks';
import SidebarPanel from './SidebarPanel'; import SidebarPanel from '../SidebarPanel';
function LoadingSpinner() { function LoadingSpinner() {
return ( return (
...@@ -213,7 +213,7 @@ function ExportPanelContent({ ...@@ -213,7 +213,7 @@ function ExportPanelContent({
); );
} }
export type ShareAnnotationPanelProps = { export type ShareDialogProps = {
// injected // injected
toastMessenger: ToastMessengerService; toastMessenger: ToastMessengerService;
}; };
...@@ -225,7 +225,7 @@ export type ShareAnnotationPanelProps = { ...@@ -225,7 +225,7 @@ export type ShareAnnotationPanelProps = {
* are on the current page (as defined by the main frame's URI) and contained * are on the current page (as defined by the main frame's URI) and contained
* within the app's currently-focused group. * within the app's currently-focused group.
*/ */
function ShareAnnotationsPanel({ toastMessenger }: ShareAnnotationPanelProps) { function ShareDialog({ toastMessenger }: ShareDialogProps) {
const store = useSidebarStore(); const store = useSidebarStore();
const mainFrame = store.mainFrame(); const mainFrame = store.mainFrame();
const focusedGroup = store.focusedGroup(); const focusedGroup = store.focusedGroup();
...@@ -329,4 +329,4 @@ function ShareAnnotationsPanel({ toastMessenger }: ShareAnnotationPanelProps) { ...@@ -329,4 +329,4 @@ function ShareAnnotationsPanel({ toastMessenger }: ShareAnnotationPanelProps) {
); );
} }
export default withServices(ShareAnnotationsPanel, ['toastMessenger']); export default withServices(ShareDialog, ['toastMessenger']);
export { default } from './ShareDialog';
import { mount } from 'enzyme'; import { mount } from 'enzyme';
import { act } from 'preact/test-utils'; import { act } from 'preact/test-utils';
import { checkAccessibility } from '../../../test-util/accessibility'; import { checkAccessibility } from '../../../../test-util/accessibility';
import { mockImportedComponents } from '../../../test-util/mock-imported-components'; import { mockImportedComponents } from '../../../../test-util/mock-imported-components';
import ShareAnnotationsPanel from '../ShareAnnotationsPanel'; import ShareDialog from '../ShareDialog';
import { $imports } from '../ShareAnnotationsPanel'; import { $imports } from '../ShareDialog';
describe('ShareAnnotationsPanel', () => { describe('ShareDialog', () => {
let fakeStore; let fakeStore;
let fakeBouncerLink; let fakeBouncerLink;
let fakePageSharingLink; let fakePageSharingLink;
...@@ -19,10 +19,8 @@ describe('ShareAnnotationsPanel', () => { ...@@ -19,10 +19,8 @@ describe('ShareAnnotationsPanel', () => {
id: 'testprivate', id: 'testprivate',
}; };
const createShareAnnotationsPanel = props => const createComponent = props =>
mount( mount(<ShareDialog toastMessenger={fakeToastMessenger} {...props} />);
<ShareAnnotationsPanel toastMessenger={fakeToastMessenger} {...props} />
);
beforeEach(() => { beforeEach(() => {
fakeBouncerLink = 'http://hyp.is/go?url=http%3A%2F%2Fwww.example.com'; fakeBouncerLink = 'http://hyp.is/go?url=http%3A%2F%2Fwww.example.com';
...@@ -48,11 +46,11 @@ describe('ShareAnnotationsPanel', () => { ...@@ -48,11 +46,11 @@ describe('ShareAnnotationsPanel', () => {
$imports.$mock(mockImportedComponents()); $imports.$mock(mockImportedComponents());
$imports.$mock({ $imports.$mock({
'../store': { useSidebarStore: () => fakeStore }, '../../store': { useSidebarStore: () => fakeStore },
'../helpers/annotation-sharing': { '../../helpers/annotation-sharing': {
pageSharingLink: fakePageSharingLink, pageSharingLink: fakePageSharingLink,
}, },
'../util/copy-to-clipboard': fakeCopyToClipboard, '../../util/copy-to-clipboard': fakeCopyToClipboard,
}); });
}); });
...@@ -62,7 +60,7 @@ describe('ShareAnnotationsPanel', () => { ...@@ -62,7 +60,7 @@ describe('ShareAnnotationsPanel', () => {
describe('panel dialog title', () => { describe('panel dialog title', () => {
it("sets sidebar panel dialog title to include group's name", () => { it("sets sidebar panel dialog title to include group's name", () => {
const wrapper = createShareAnnotationsPanel(); const wrapper = createComponent();
assert.equal( assert.equal(
wrapper.find('SidebarPanel').prop('title'), wrapper.find('SidebarPanel').prop('title'),
...@@ -73,7 +71,7 @@ describe('ShareAnnotationsPanel', () => { ...@@ -73,7 +71,7 @@ describe('ShareAnnotationsPanel', () => {
it('sets a temporary title if focused group not available', () => { it('sets a temporary title if focused group not available', () => {
fakeStore.focusedGroup = sinon.stub().returns({}); fakeStore.focusedGroup = sinon.stub().returns({});
const wrapper = createShareAnnotationsPanel(); const wrapper = createComponent();
assert.equal( assert.equal(
wrapper.find('SidebarPanel').prop('title'), wrapper.find('SidebarPanel').prop('title'),
'Share Annotations in ...' 'Share Annotations in ...'
...@@ -85,19 +83,19 @@ describe('ShareAnnotationsPanel', () => { ...@@ -85,19 +83,19 @@ describe('ShareAnnotationsPanel', () => {
it('does not render share panel content if needed info not available', () => { it('does not render share panel content if needed info not available', () => {
fakeStore.focusedGroup.returns(undefined); fakeStore.focusedGroup.returns(undefined);
const wrapper = createShareAnnotationsPanel(); const wrapper = createComponent();
assert.isFalse(wrapper.exists('.ShareAnnotationsPanel')); assert.isFalse(wrapper.exists('.ShareAnnotationsPanel'));
}); });
it('renders a spinner if focused group not available yet', () => { it('renders a spinner if focused group not available yet', () => {
fakeStore.focusedGroup.returns(undefined); fakeStore.focusedGroup.returns(undefined);
const wrapper = createShareAnnotationsPanel(); const wrapper = createComponent();
assert.isTrue(wrapper.find('Spinner').exists()); assert.isTrue(wrapper.find('Spinner').exists());
}); });
it('renders panel content if needed info available', () => { it('renders panel content if needed info available', () => {
const wrapper = createShareAnnotationsPanel(); const wrapper = createComponent();
assert.isFalse(wrapper.find('Spinner').exists()); assert.isFalse(wrapper.find('Spinner').exists());
}); });
}); });
...@@ -129,7 +127,7 @@ describe('ShareAnnotationsPanel', () => { ...@@ -129,7 +127,7 @@ describe('ShareAnnotationsPanel', () => {
id: 'testid,', id: 'testid,',
}); });
const wrapper = createShareAnnotationsPanel(); const wrapper = createComponent();
assert.match( assert.match(
wrapper.find('[data-testid="sharing-intro"]').text(), wrapper.find('[data-testid="sharing-intro"]').text(),
...@@ -146,7 +144,7 @@ describe('ShareAnnotationsPanel', () => { ...@@ -146,7 +144,7 @@ describe('ShareAnnotationsPanel', () => {
it('renders explanatory text about inability to share', () => { it('renders explanatory text about inability to share', () => {
fakePageSharingLink.returns(null); fakePageSharingLink.returns(null);
const wrapper = createShareAnnotationsPanel(); const wrapper = createComponent();
const panelEl = wrapper.find('[data-testid="no-sharing"]'); const panelEl = wrapper.find('[data-testid="no-sharing"]');
assert.include(panelEl.text(), 'These annotations cannot be shared'); assert.include(panelEl.text(), 'These annotations cannot be shared');
...@@ -156,7 +154,7 @@ describe('ShareAnnotationsPanel', () => { ...@@ -156,7 +154,7 @@ describe('ShareAnnotationsPanel', () => {
describe('web share link', () => { describe('web share link', () => {
it('displays web share link in readonly form input', () => { it('displays web share link in readonly form input', () => {
const wrapper = createShareAnnotationsPanel(); const wrapper = createComponent();
const inputEl = wrapper.find('input'); const inputEl = wrapper.find('input');
assert.equal(inputEl.prop('value'), fakeBouncerLink); assert.equal(inputEl.prop('value'), fakeBouncerLink);
...@@ -166,7 +164,7 @@ describe('ShareAnnotationsPanel', () => { ...@@ -166,7 +164,7 @@ describe('ShareAnnotationsPanel', () => {
context('document URI cannot be shared', () => { context('document URI cannot be shared', () => {
it('does not render an input field with share link', () => { it('does not render an input field with share link', () => {
fakePageSharingLink.returns(null); fakePageSharingLink.returns(null);
const wrapper = createShareAnnotationsPanel(); const wrapper = createComponent();
const inputEl = wrapper.find('input'); const inputEl = wrapper.find('input');
assert.isFalse(inputEl.exists()); assert.isFalse(inputEl.exists());
...@@ -175,7 +173,7 @@ describe('ShareAnnotationsPanel', () => { ...@@ -175,7 +173,7 @@ describe('ShareAnnotationsPanel', () => {
describe('copy link to clipboard', () => { describe('copy link to clipboard', () => {
it('copies link to clipboard when copy button clicked', () => { it('copies link to clipboard when copy button clicked', () => {
const wrapper = createShareAnnotationsPanel(); const wrapper = createComponent();
wrapper.find('IconButton').props().onClick(); wrapper.find('IconButton').props().onClick();
...@@ -183,7 +181,7 @@ describe('ShareAnnotationsPanel', () => { ...@@ -183,7 +181,7 @@ describe('ShareAnnotationsPanel', () => {
}); });
it('confirms link copy when successful', () => { it('confirms link copy when successful', () => {
const wrapper = createShareAnnotationsPanel(); const wrapper = createComponent();
wrapper.find('IconButton').props().onClick(); wrapper.find('IconButton').props().onClick();
...@@ -195,7 +193,7 @@ describe('ShareAnnotationsPanel', () => { ...@@ -195,7 +193,7 @@ describe('ShareAnnotationsPanel', () => {
it('flashes an error if link copying unsuccessful', () => { it('flashes an error if link copying unsuccessful', () => {
fakeCopyToClipboard.copyText.throws(); fakeCopyToClipboard.copyText.throws();
const wrapper = createShareAnnotationsPanel(); const wrapper = createComponent();
wrapper.find('IconButton').props().onClick(); wrapper.find('IconButton').props().onClick();
...@@ -206,7 +204,7 @@ describe('ShareAnnotationsPanel', () => { ...@@ -206,7 +204,7 @@ describe('ShareAnnotationsPanel', () => {
describe('tabbed dialog panel', () => { describe('tabbed dialog panel', () => {
it('does not render a tabbed dialog if export feature flag is not enabled', () => { it('does not render a tabbed dialog if export feature flag is not enabled', () => {
const wrapper = createShareAnnotationsPanel(); const wrapper = createComponent();
assert.isFalse(wrapper.find('TabHeader').exists()); assert.isFalse(wrapper.find('TabHeader').exists());
}); });
...@@ -217,7 +215,7 @@ describe('ShareAnnotationsPanel', () => { ...@@ -217,7 +215,7 @@ describe('ShareAnnotationsPanel', () => {
}); });
it('renders a tabbed dialog with share panel active', () => { it('renders a tabbed dialog with share panel active', () => {
const wrapper = createShareAnnotationsPanel(); const wrapper = createComponent();
assert.isTrue(wrapper.find('TabHeader').exists()); assert.isTrue(wrapper.find('TabHeader').exists());
assert.isTrue( assert.isTrue(
...@@ -229,7 +227,7 @@ describe('ShareAnnotationsPanel', () => { ...@@ -229,7 +227,7 @@ describe('ShareAnnotationsPanel', () => {
}); });
it('shows the export tab panel when export tab clicked', () => { it('shows the export tab panel when export tab clicked', () => {
const wrapper = createShareAnnotationsPanel(); const wrapper = createComponent();
const shareTabSelector = 'Tab[aria-controls="share-panel"]'; const shareTabSelector = 'Tab[aria-controls="share-panel"]';
const exportTabSelector = 'Tab[aria-controls="export-panel"]'; const exportTabSelector = 'Tab[aria-controls="export-panel"]';
...@@ -265,7 +263,7 @@ describe('ShareAnnotationsPanel', () => { ...@@ -265,7 +263,7 @@ describe('ShareAnnotationsPanel', () => {
}); });
it('shows a loading indicator on the export tab if not ready', () => { it('shows a loading indicator on the export tab if not ready', () => {
const wrapper = createShareAnnotationsPanel(); const wrapper = createComponent();
const exportTabSelector = 'Tab[aria-controls="export-panel"]'; const exportTabSelector = 'Tab[aria-controls="export-panel"]';
fakeStore.isLoading.returns(true); fakeStore.isLoading.returns(true);
...@@ -293,7 +291,7 @@ describe('ShareAnnotationsPanel', () => { ...@@ -293,7 +291,7 @@ describe('ShareAnnotationsPanel', () => {
it( it(
'should pass a11y checks', 'should pass a11y checks',
checkAccessibility({ checkAccessibility({
content: () => createShareAnnotationsPanel(), content: () => createComponent(),
}) })
); );
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment