Commit d0039747 authored by Robert Knight's avatar Robert Knight

Add and update tests for JSTOR content banner

parent c052cd18
...@@ -29,7 +29,9 @@ export default function ContentPartnerBanner({ provider, onClose }) { ...@@ -29,7 +29,9 @@ export default function ContentPartnerBanner({ provider, onClose }) {
</> </>
)} )}
<div className="text-annotator-base"> <div className="text-annotator-base">
<LabeledButton onClick={onClose}>Close</LabeledButton> <LabeledButton onClick={onClose} data-testid="close-button">
Close
</LabeledButton>
</div> </div>
</div> </div>
); );
......
import { mount } from 'enzyme';
import ContentPartnerBanner from '../ContentPartnerBanner';
describe('ContentPartnerBanner', () => {
it('renders JSTOR banner', () => {
const wrapper = mount(<ContentPartnerBanner provider="jstor" />);
assert.include(wrapper.text(), 'Document hosted by JSTOR');
});
it('closes when "Close" button is clicked', () => {
const onClose = sinon.stub();
const wrapper = mount(
<ContentPartnerBanner provider="jstor" onClose={onClose} />
);
const closeButton = wrapper.find(
'LabeledButton[data-testid="close-button"]'
);
closeButton.prop('onClick')();
assert.calledOnce(onClose);
});
});
...@@ -77,6 +77,7 @@ describe('annotator/config/index', () => { ...@@ -77,6 +77,7 @@ describe('annotator/config/index', () => {
annotations: 'fakeValue', annotations: 'fakeValue',
branding: null, branding: null,
clientUrl: 'fakeValue', clientUrl: 'fakeValue',
contentPartner: null,
enableExperimentalNewNoteButton: null, enableExperimentalNewNoteButton: null,
externalContainerSelector: null, externalContainerSelector: null,
focus: null, focus: null,
...@@ -108,6 +109,7 @@ describe('annotator/config/index', () => { ...@@ -108,6 +109,7 @@ describe('annotator/config/index', () => {
annotations: 'fakeValue', annotations: 'fakeValue',
branding: 'fakeValue', branding: 'fakeValue',
clientUrl: 'fakeValue', clientUrl: 'fakeValue',
contentPartner: 'fakeValue',
enableExperimentalNewNoteButton: 'fakeValue', enableExperimentalNewNoteButton: 'fakeValue',
externalContainerSelector: 'fakeValue', externalContainerSelector: 'fakeValue',
focus: 'fakeValue', focus: 'fakeValue',
...@@ -163,6 +165,7 @@ describe('annotator/config/index', () => { ...@@ -163,6 +165,7 @@ describe('annotator/config/index', () => {
annotations: null, annotations: null,
branding: null, branding: null,
clientUrl: null, clientUrl: null,
contentPartner: null,
enableExperimentalNewNoteButton: null, enableExperimentalNewNoteButton: null,
externalContainerSelector: null, externalContainerSelector: null,
focus: null, focus: null,
...@@ -217,7 +220,7 @@ describe('annotator/config/index', () => { ...@@ -217,7 +220,7 @@ describe('annotator/config/index', () => {
[ [
{ {
app: 'annotator', app: 'annotator',
expectedKeys: ['clientUrl', 'subFrameIdentifier'], expectedKeys: ['clientUrl', 'contentPartner', 'subFrameIdentifier'],
}, },
{ {
app: 'sidebar', app: 'sidebar',
......
...@@ -39,6 +39,19 @@ describe('createIntegration', () => { ...@@ -39,6 +39,19 @@ describe('createIntegration', () => {
assert.instanceOf(integration, FakePDFIntegration); assert.instanceOf(integration, FakePDFIntegration);
}); });
it('passes options to PDF integration', () => {
const annotator = {};
fakeIsPDF.returns(true);
createIntegration(annotator, {
contentPartner: 'jstor',
});
assert.calledWith(FakePDFIntegration, annotator, {
contentPartner: 'jstor',
});
});
it('creates VitalSource content integration in the VS Bookshelf reader', () => { it('creates VitalSource content integration in the VS Bookshelf reader', () => {
const annotator = {}; const annotator = {};
fakeVitalSourceFrameRole.returns('content'); fakeVitalSourceFrameRole.returns('content');
......
...@@ -214,7 +214,7 @@ describe('annotator/integrations/pdf', () => { ...@@ -214,7 +214,7 @@ describe('annotator/integrations/pdf', () => {
}); });
}); });
function getWarningBanner() { function getBanner() {
return document.querySelector('hypothesis-banner'); return document.querySelector('hypothesis-banner');
} }
...@@ -225,7 +225,7 @@ describe('annotator/integrations/pdf', () => { ...@@ -225,7 +225,7 @@ describe('annotator/integrations/pdf', () => {
await delay(0); // Wait for text check to complete. await delay(0); // Wait for text check to complete.
assert.called(fakePDFAnchoring.documentHasText); assert.called(fakePDFAnchoring.documentHasText);
assert.isNull(getWarningBanner()); assert.isNull(getBanner());
}); });
it('does not show a warning if PDF does not load', async () => { it('does not show a warning if PDF does not load', async () => {
...@@ -235,7 +235,7 @@ describe('annotator/integrations/pdf', () => { ...@@ -235,7 +235,7 @@ describe('annotator/integrations/pdf', () => {
await delay(0); // Wait for text check to complete. await delay(0); // Wait for text check to complete.
assert.notCalled(fakePDFAnchoring.documentHasText); assert.notCalled(fakePDFAnchoring.documentHasText);
assert.isNull(getWarningBanner()); assert.isNull(getBanner());
}); });
it('shows a warning when PDF has no selectable text', async () => { it('shows a warning when PDF has no selectable text', async () => {
...@@ -245,7 +245,7 @@ describe('annotator/integrations/pdf', () => { ...@@ -245,7 +245,7 @@ describe('annotator/integrations/pdf', () => {
await delay(0); // Wait for text check to complete. await delay(0); // Wait for text check to complete.
assert.called(fakePDFAnchoring.documentHasText); assert.called(fakePDFAnchoring.documentHasText);
const banner = getWarningBanner(); const banner = getBanner();
assert.isNotNull(banner); assert.isNotNull(banner);
assert.include( assert.include(
banner.shadowRoot.textContent, banner.shadowRoot.textContent,
...@@ -253,6 +253,25 @@ describe('annotator/integrations/pdf', () => { ...@@ -253,6 +253,25 @@ describe('annotator/integrations/pdf', () => {
); );
}); });
it('shows banner when content is provided by JSTOR', () => {
pdfIntegration = createPDFIntegration({ contentPartner: 'jstor' });
const banner = getBanner();
assert.isNotNull(banner);
assert.include(banner.shadowRoot.textContent, 'Document hosted by JSTOR');
});
it('closes content partner banner when "Close" button is clicked', () => {
pdfIntegration = createPDFIntegration({ contentPartner: 'jstor' });
const banner = getBanner();
const closeButton = banner.shadowRoot.querySelector(
'button[data-testid=close-button]'
);
closeButton.click();
assert.isNull(getBanner());
});
context('when the PDF viewer content changes', () => { context('when the PDF viewer content changes', () => {
async function triggerUpdate() { async function triggerUpdate() {
const element = document.createElement('div'); const element = document.createElement('div');
......
...@@ -1248,6 +1248,22 @@ describe('Guest', () => { ...@@ -1248,6 +1248,22 @@ describe('Guest', () => {
assert.calledWith(sidebarRPC().connect, port1); assert.calledWith(sidebarRPC().connect, port1);
}); });
it('passes configuration to integration', () => {
const config = {
// Configuration options that should be forwarded to the integration
contentPartner: 'jstor',
// Other configuration
otherOption: 'test',
};
const guest = createGuest(config);
assert.calledOnce(fakeCreateIntegration);
assert.calledWith(fakeCreateIntegration, guest, {
contentPartner: 'jstor',
});
});
it('configures the BucketBarClient', () => { it('configures the BucketBarClient', () => {
const contentContainer = document.createElement('div'); const contentContainer = document.createElement('div');
fakeIntegration.contentContainer.returns(contentContainer); fakeIntegration.contentContainer.returns(contentContainer);
......
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