Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
d0039747
Commit
d0039747
authored
Mar 14, 2022
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add and update tests for JSTOR content banner
parent
c052cd18
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
83 additions
and
6 deletions
+83
-6
ContentPartnerBanner.js
src/annotator/components/ContentPartnerBanner.js
+3
-1
ContentPartnerBanner-test.js
src/annotator/components/test/ContentPartnerBanner-test.js
+24
-0
index-test.js
src/annotator/config/test/index-test.js
+4
-1
index-test.js
src/annotator/integrations/test/index-test.js
+13
-0
pdf-test.js
src/annotator/integrations/test/pdf-test.js
+23
-4
guest-test.js
src/annotator/test/guest-test.js
+16
-0
No files found.
src/annotator/components/ContentPartnerBanner.js
View file @
d0039747
...
@@ -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
>
);
);
...
...
src/annotator/components/test/ContentPartnerBanner-test.js
0 → 100644
View file @
d0039747
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
);
});
});
src/annotator/config/test/index-test.js
View file @
d0039747
...
@@ -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'
,
...
...
src/annotator/integrations/test/index-test.js
View file @
d0039747
...
@@ -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'
);
...
...
src/annotator/integrations/test/pdf-test.js
View file @
d0039747
...
@@ -214,7 +214,7 @@ describe('annotator/integrations/pdf', () => {
...
@@ -214,7 +214,7 @@ describe('annotator/integrations/pdf', () => {
});
});
});
});
function
get
Warning
Banner
()
{
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
(
get
Warning
Banner
());
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
(
get
Warning
Banner
());
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
=
get
Warning
Banner
();
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'
);
...
...
src/annotator/test/guest-test.js
View file @
d0039747
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment