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
e7a363ab
Unverified
Commit
e7a363ab
authored
Aug 22, 2019
by
Robert Knight
Committed by
GitHub
Aug 22, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1317 from hypothesis/namespace-direct-linked-module
Namespace the direct-linked module
parents
4bc0827e
f89877a0
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
98 additions
and
35 deletions
+98
-35
sidebar-content.js
src/sidebar/components/sidebar-content.js
+2
-2
groups.js
src/sidebar/services/groups.js
+4
-2
groups-test.js
src/sidebar/services/test/groups-test.js
+70
-20
direct-linked.js
src/sidebar/store/modules/direct-linked.js
+1
-0
direct-linked-test.js
src/sidebar/store/modules/test/direct-linked-test.js
+12
-8
index-test.js
src/sidebar/store/test/index-test.js
+5
-3
fake-redux-store.js
src/sidebar/test/fake-redux-store.js
+4
-0
No files found.
src/sidebar/components/sidebar-content.js
View file @
e7a363ab
...
...
@@ -151,7 +151,7 @@ function SidebarContentController(
this
.
scrollTo
=
scrollToAnnotation
;
this
.
selectedGroupUnavailable
=
function
()
{
return
store
.
get
State
()
.
directLinkedGroupFetchFailed
;
return
store
.
get
RootState
().
directLinked
.
directLinkedGroupFetchFailed
;
};
this
.
selectedAnnotationUnavailable
=
function
()
{
...
...
@@ -169,7 +169,7 @@ function SidebarContentController(
// If user has not landed on a direct linked annotation
// don't show the CTA.
if
(
!
store
.
get
State
()
.
directLinkedAnnotationId
)
{
if
(
!
store
.
get
RootState
().
directLinked
.
directLinkedAnnotationId
)
{
return
false
;
}
...
...
src/sidebar/services/groups.js
View file @
e7a363ab
...
...
@@ -179,7 +179,8 @@ function groups(
// If there is a direct-linked annotation, fetch the annotation in case
// the associated group has not already been fetched and we need to make
// an additional request for it.
const
directLinkedAnnId
=
store
.
getState
().
directLinkedAnnotationId
;
const
directLinkedAnnId
=
store
.
getRootState
().
directLinked
.
directLinkedAnnotationId
;
let
directLinkedAnnApi
=
null
;
if
(
directLinkedAnnId
)
{
directLinkedAnnApi
=
api
.
annotation
...
...
@@ -193,7 +194,8 @@ function groups(
// If there is a direct-linked group, add an API request to get that
// particular group since it may not be in the set of groups that are
// fetched by other requests.
const
directLinkedGroupId
=
store
.
getState
().
directLinkedGroupId
;
const
directLinkedGroupId
=
store
.
getRootState
().
directLinked
.
directLinkedGroupId
;
let
directLinkedGroupApi
=
null
;
if
(
directLinkedGroupId
)
{
directLinkedGroupApi
=
fetchGroup
({
...
...
src/sidebar/services/test/groups-test.js
View file @
e7a363ab
...
...
@@ -60,8 +60,10 @@ describe('groups', function() {
mainFrame
:
{
uri
:
'http://example.org'
},
focusedGroup
:
null
,
groups
:
[],
directLinkedGroupId
:
null
,
directLinkedAnnotationId
:
null
,
directLinked
:
{
directLinkedGroupId
:
null
,
directLinkedAnnotationId
:
null
,
},
},
{
focusGroup
:
sinon
.
stub
(),
...
...
@@ -164,7 +166,9 @@ describe('groups', function() {
scopes
:
{
enforced
:
true
,
uri_patterns
:
[
'http://foo.com'
]
},
};
fakeStore
.
setState
({
directLinkedGroupId
:
outOfScopeEnforcedGroup
.
id
,
directLinked
:
{
directLinkedGroupId
:
outOfScopeEnforcedGroup
.
id
,
},
});
fakeApi
.
group
.
read
.
returns
(
Promise
.
resolve
(
outOfScopeEnforcedGroup
));
return
svc
.
load
().
then
(
groups
=>
{
...
...
@@ -180,7 +184,11 @@ describe('groups', function() {
it
(
'catches error from api.group.read request'
,
()
=>
{
const
svc
=
service
();
fakeLocalStorage
.
getItem
.
returns
(
dummyGroups
[
0
].
id
);
fakeStore
.
setState
({
directLinkedGroupId
:
'does-not-exist'
});
fakeStore
.
setState
({
directLinked
:
{
directLinkedGroupId
:
'does-not-exist'
,
},
});
fakeApi
.
group
.
read
.
returns
(
Promise
.
reject
(
new
Error
(
...
...
@@ -219,7 +227,11 @@ describe('groups', function() {
const
svc
=
service
();
// Set the direct-linked group to dummyGroups[0].
fakeStore
.
setState
({
directLinkedGroupId
:
dummyGroups
[
0
].
id
});
fakeStore
.
setState
({
directLinkedGroupId
:
{
directLinkedGroupId
:
dummyGroups
[
0
].
id
,
},
});
fakeApi
.
group
.
read
.
returns
(
Promise
.
resolve
(
dummyGroups
[
0
]));
// Include the dummyGroups[0] in the featured groups.
...
...
@@ -235,7 +247,11 @@ describe('groups', function() {
it
(
'combines groups from all 3 endpoints if there is a selectedGroup'
,
()
=>
{
const
svc
=
service
();
fakeStore
.
setState
({
directLinkedGroupId
:
'selected-id'
});
fakeStore
.
setState
({
directLinked
:
{
directLinkedGroupId
:
'selected-id'
,
},
});
const
groups
=
[
{
id
:
'groupa'
,
name
:
'GroupA'
},
{
id
:
'groupb'
,
name
:
'GroupB'
},
...
...
@@ -254,7 +270,11 @@ describe('groups', function() {
it
(
'passes the direct-linked group id from the store to the api.group.read call'
,
()
=>
{
const
svc
=
service
();
fakeStore
.
setState
({
directLinkedGroupId
:
'selected-id'
});
fakeStore
.
setState
({
directLinked
:
{
directLinkedGroupId
:
'selected-id'
,
},
});
const
group
=
{
id
:
'selected-id'
,
name
:
'Selected Group'
};
fakeApi
.
profile
.
groups
.
read
.
returns
(
Promise
.
resolve
([]));
...
...
@@ -284,7 +304,11 @@ describe('groups', function() {
fakeApi
.
groups
.
list
.
returns
(
Promise
.
resolve
([{
id
:
'groupa'
,
name
:
'GroupA'
}])
);
fakeStore
.
setState
({
directLinkedGroupId
:
'group-id'
});
fakeStore
.
setState
({
directLinked
:
{
directLinkedGroupId
:
'group-id'
,
},
});
return
svc
.
load
().
then
(()
=>
{
assert
.
calledWith
(
...
...
@@ -313,8 +337,10 @@ describe('groups', function() {
it
(
"sets the direct-linked annotation's group to take precedence over the group saved in local storage and the direct-linked group"
,
()
=>
{
const
svc
=
service
();
fakeStore
.
setState
({
directLinkedAnnotationId
:
'ann-id'
,
directLinkedGroupId
:
dummyGroups
[
1
].
id
,
directLinked
:
{
directLinkedAnnotationId
:
'ann-id'
,
directLinkedGroupId
:
dummyGroups
[
1
].
id
,
},
});
fakeLocalStorage
.
getItem
.
returns
(
dummyGroups
[
0
].
id
);
fakeApi
.
groups
.
list
.
returns
(
Promise
.
resolve
(
dummyGroups
));
...
...
@@ -331,7 +357,11 @@ describe('groups', function() {
it
(
"sets the focused group to the direct-linked annotation's group"
,
()
=>
{
const
svc
=
service
();
fakeStore
.
setState
({
directLinkedAnnotationId
:
'ann-id'
});
fakeStore
.
setState
({
directLinked
:
{
directLinkedAnnotationId
:
'ann-id'
,
},
});
fakeApi
.
groups
.
list
.
returns
(
Promise
.
resolve
(
dummyGroups
));
fakeLocalStorage
.
getItem
.
returns
(
dummyGroups
[
0
].
id
);
fakeApi
.
annotation
.
get
.
returns
(
...
...
@@ -347,7 +377,11 @@ describe('groups', function() {
it
(
'sets the direct-linked group to take precedence over the group saved in local storage'
,
()
=>
{
const
svc
=
service
();
fakeStore
.
setState
({
directLinkedGroupId
:
dummyGroups
[
1
].
id
});
fakeStore
.
setState
({
directLinked
:
{
directLinkedGroupId
:
dummyGroups
[
1
].
id
,
},
});
fakeLocalStorage
.
getItem
.
returns
(
dummyGroups
[
0
].
id
);
fakeApi
.
groups
.
list
.
returns
(
Promise
.
resolve
(
dummyGroups
));
return
svc
.
load
().
then
(()
=>
{
...
...
@@ -357,7 +391,11 @@ describe('groups', function() {
it
(
'sets the focused group to the direct-linked group'
,
()
=>
{
const
svc
=
service
();
fakeStore
.
setState
({
directLinkedGroupId
:
dummyGroups
[
1
].
id
});
fakeStore
.
setState
({
directLinked
:
{
directLinkedGroupId
:
dummyGroups
[
1
].
id
,
},
});
fakeApi
.
groups
.
list
.
returns
(
Promise
.
resolve
(
dummyGroups
));
return
svc
.
load
().
then
(()
=>
{
assert
.
calledWith
(
fakeStore
.
focusGroup
,
dummyGroups
[
1
].
id
);
...
...
@@ -366,7 +404,11 @@ describe('groups', function() {
it
(
'clears the directLinkedGroupFetchFailed state if loading a direct-linked group'
,
()
=>
{
const
svc
=
service
();
fakeStore
.
setState
({
directLinkedGroupId
:
dummyGroups
[
1
].
id
});
fakeStore
.
setState
({
directLinked
:
{
directLinkedGroupId
:
dummyGroups
[
1
].
id
,
},
});
fakeApi
.
groups
.
list
.
returns
(
Promise
.
resolve
(
dummyGroups
));
return
svc
.
load
().
then
(()
=>
{
assert
.
called
(
fakeStore
.
clearDirectLinkedGroupFetchFailed
);
...
...
@@ -501,7 +543,11 @@ describe('groups', function() {
it
(
"includes the direct-linked annotation's group when it is not in the normal list of groups"
,
()
=>
{
const
svc
=
service
();
fakeStore
.
setState
({
directLinkedAnnotationId
:
'ann-id'
});
fakeStore
.
setState
({
directLinked
:
{
directLinkedAnnotationId
:
'ann-id'
,
},
});
fakeApi
.
profile
.
groups
.
read
.
returns
(
Promise
.
resolve
([]));
fakeApi
.
groups
.
list
.
returns
(
...
...
@@ -534,8 +580,10 @@ describe('groups', function() {
const
svc
=
service
();
fakeStore
.
setState
({
directLinkedGroupId
:
'out-of-scope'
,
directLinkedAnnotationId
:
'ann-id'
,
directLinked
:
{
directLinkedGroupId
:
'out-of-scope'
,
directLinkedAnnotationId
:
'ann-id'
,
},
});
fakeApi
.
profile
.
groups
.
read
.
returns
(
Promise
.
resolve
([]));
...
...
@@ -573,8 +621,10 @@ describe('groups', function() {
const
svc
=
service
();
fakeStore
.
setState
({
directLinkedGroupId
:
'__world__'
,
directLinkedAnnotationId
:
null
,
directLinked
:
{
directLinkedGroupId
:
'__world__'
,
directLinkedAnnotationId
:
null
,
},
});
fakeApi
.
profile
.
groups
.
read
.
returns
(
Promise
.
resolve
([]));
...
...
@@ -614,7 +664,7 @@ describe('groups', function() {
})
);
fakeStore
.
setState
({
directLinked
AnnotationId
:
'direct-linked-ann'
,
directLinked
:
{
directLinkedAnnotationId
:
'direct-linked-ann'
}
,
});
}
...
...
src/sidebar/store/modules/direct-linked.js
View file @
e7a363ab
...
...
@@ -129,6 +129,7 @@ function clearDirectLinkedIds() {
module
.
exports
=
{
init
,
namespace
:
'directLinked'
,
update
,
actions
:
{
setDirectLinkedGroupFetchFailed
,
...
...
src/sidebar/store/modules/test/direct-linked-test.js
View file @
e7a363ab
...
...
@@ -7,6 +7,10 @@ describe('sidebar/store/modules/direct-linked', () => {
let
store
;
let
fakeSettings
=
{};
const
getDirectLinkedState
=
()
=>
{
return
store
.
getRootState
().
directLinked
;
};
beforeEach
(()
=>
{
store
=
createStore
([
directLinked
],
[
fakeSettings
]);
});
...
...
@@ -15,7 +19,7 @@ describe('sidebar/store/modules/direct-linked', () => {
it
(
'sets directLinkedGroupFetchFailed to true'
,
()
=>
{
store
.
setDirectLinkedGroupFetchFailed
();
assert
.
isTrue
(
store
.
get
State
().
directLinkedGroupFetchFailed
);
assert
.
isTrue
(
getDirectLinked
State
().
directLinkedGroupFetchFailed
);
});
});
...
...
@@ -25,7 +29,7 @@ describe('sidebar/store/modules/direct-linked', () => {
store
.
clearDirectLinkedGroupFetchFailed
();
assert
.
isFalse
(
store
.
get
State
().
directLinkedGroupFetchFailed
);
assert
.
isFalse
(
getDirectLinked
State
().
directLinkedGroupFetchFailed
);
});
});
...
...
@@ -34,14 +38,14 @@ describe('sidebar/store/modules/direct-linked', () => {
store
=
createStore
([
directLinked
],
[
fakeSettings
]);
assert
.
equal
(
store
.
get
State
().
directLinkedAnnotationId
,
'ann-id'
);
assert
.
equal
(
getDirectLinked
State
().
directLinkedAnnotationId
,
'ann-id'
);
});
describe
(
'setDirectLinkedAnnotationId'
,
()
=>
{
it
(
'sets directLinkedAnnotationId to the specified annotation id'
,
()
=>
{
store
.
setDirectLinkedAnnotationId
(
'ann-id'
);
assert
.
equal
(
store
.
get
State
().
directLinkedAnnotationId
,
'ann-id'
);
assert
.
equal
(
getDirectLinked
State
().
directLinkedAnnotationId
,
'ann-id'
);
});
});
...
...
@@ -50,14 +54,14 @@ describe('sidebar/store/modules/direct-linked', () => {
store
=
createStore
([
directLinked
],
[
fakeSettings
]);
assert
.
equal
(
store
.
get
State
().
directLinkedGroupId
,
'group-id'
);
assert
.
equal
(
getDirectLinked
State
().
directLinkedGroupId
,
'group-id'
);
});
describe
(
'setDirectLinkedGroupId'
,
()
=>
{
it
(
'sets directLinkedGroupId to the specified group id'
,
()
=>
{
store
.
setDirectLinkedGroupId
(
'group-id'
);
assert
.
equal
(
store
.
get
State
().
directLinkedGroupId
,
'group-id'
);
assert
.
equal
(
getDirectLinked
State
().
directLinkedGroupId
,
'group-id'
);
});
});
...
...
@@ -68,8 +72,8 @@ describe('sidebar/store/modules/direct-linked', () => {
store
.
clearDirectLinkedIds
();
assert
.
equal
(
store
.
get
State
().
directLinkedAnnotationId
,
null
);
assert
.
equal
(
store
.
get
State
().
directLinkedGroupId
,
null
);
assert
.
equal
(
getDirectLinked
State
().
directLinkedAnnotationId
,
null
);
assert
.
equal
(
getDirectLinked
State
().
directLinkedGroupId
,
null
);
});
});
});
src/sidebar/store/test/index-test.js
View file @
e7a363ab
...
...
@@ -76,17 +76,19 @@ describe('store', function() {
it
(
'sets `directLinkedGroupFetchFailed` to false'
,
()
=>
{
store
.
clearSelection
();
assert
.
isFalse
(
store
.
getState
().
directLinkedGroupFetchFailed
);
assert
.
isFalse
(
store
.
getRootState
().
directLinked
.
directLinkedGroupFetchFailed
);
});
it
(
'sets `directLinkedAnnotationId` to null'
,
()
=>
{
store
.
clearSelection
();
assert
.
isNull
(
store
.
get
State
()
.
directLinkedAnnotationId
);
assert
.
isNull
(
store
.
get
RootState
().
directLinked
.
directLinkedAnnotationId
);
});
it
(
'sets `directLinkedGroupId` to null'
,
()
=>
{
store
.
clearSelection
();
assert
.
isNull
(
store
.
get
State
()
.
directLinkedGroupId
);
assert
.
isNull
(
store
.
get
RootState
().
directLinked
.
directLinkedGroupId
);
});
it
(
'sets `sortKey` to default annotation sort key if set to Orphans'
,
()
=>
{
...
...
src/sidebar/test/fake-redux-store.js
View file @
e7a363ab
...
...
@@ -24,6 +24,10 @@ function fakeStore(initialState, methods) {
const
store
=
redux
.
createStore
(
update
,
initialState
);
store
.
getRootState
=
()
=>
{
return
store
.
getState
();
};
store
.
setState
=
function
(
state
)
{
store
.
dispatch
({
type
:
'SET_STATE'
,
state
:
state
});
};
...
...
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