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
6dc6a8d0
Unverified
Commit
6dc6a8d0
authored
Apr 20, 2018
by
Robert Knight
Committed by
GitHub
Apr 20, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #724 from hypothesis/fix-focused-group-comparison
Fix group focus change checks
parents
cfe352ba
8a05a367
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
5 deletions
+43
-5
groups.js
src/sidebar/services/groups.js
+7
-5
groups-test.js
src/sidebar/services/test/groups-test.js
+14
-0
groups.js
src/sidebar/store/modules/groups.js
+10
-0
groups-test.js
src/sidebar/store/modules/test/groups-test.js
+12
-0
No files found.
src/sidebar/services/groups.js
View file @
6dc6a8d0
...
@@ -113,14 +113,16 @@ function groups($rootScope, store, api, isSidebar, localStorage, serviceUrl, ses
...
@@ -113,14 +113,16 @@ function groups($rootScope, store, api, isSidebar, localStorage, serviceUrl, ses
}
}
// Persist the focused group to storage when it changes.
// Persist the focused group to storage when it changes.
var
prevFocused
=
store
.
focusedGroup
();
var
prevFocused
Id
=
store
.
focusedGroupId
();
store
.
subscribe
(()
=>
{
store
.
subscribe
(()
=>
{
var
focused
=
store
.
focusedGroup
();
var
focusedId
=
store
.
focusedGroupId
();
if
(
focused
&&
focused
!==
prevFocused
)
{
if
(
focusedId
!==
prevFocusedId
)
{
localStorage
.
setItem
(
STORAGE_KEY
,
focused
.
id
);
prevFocusedId
=
focusedId
;
localStorage
.
setItem
(
STORAGE_KEY
,
focusedId
);
// Emit the `GROUP_FOCUSED` event for code that still relies on it.
// Emit the `GROUP_FOCUSED` event for code that still relies on it.
$rootScope
.
$broadcast
(
events
.
GROUP_FOCUSED
,
focused
.
i
d
);
$rootScope
.
$broadcast
(
events
.
GROUP_FOCUSED
,
focused
I
d
);
}
}
});
});
...
...
src/sidebar/services/test/groups-test.js
View file @
6dc6a8d0
...
@@ -49,6 +49,10 @@ describe('groups', function() {
...
@@ -49,6 +49,10 @@ describe('groups', function() {
searchUris
()
{
searchUris
()
{
return
this
.
getState
().
searchUris
;
return
this
.
getState
().
searchUris
;
},
},
focusedGroupId
()
{
var
group
=
this
.
getState
().
focusedGroup
;
return
group
?
group
.
id
:
null
;
},
});
});
fakeSession
=
sessionWithThreeGroups
();
fakeSession
=
sessionWithThreeGroups
();
fakeIsSidebar
=
true
;
fakeIsSidebar
=
true
;
...
@@ -211,6 +215,16 @@ describe('groups', function() {
...
@@ -211,6 +215,16 @@ describe('groups', function() {
assert
.
calledWith
(
fakeRootScope
.
$broadcast
,
events
.
GROUP_FOCUSED
,
dummyGroups
[
1
].
id
);
assert
.
calledWith
(
fakeRootScope
.
$broadcast
,
events
.
GROUP_FOCUSED
,
dummyGroups
[
1
].
id
);
});
});
it
(
'does not emit GROUP_FOCUSED if the focused group did not change'
,
()
=>
{
service
();
fakeStore
.
setState
({
groups
:
dummyGroups
,
focusedGroup
:
dummyGroups
[
1
]
});
fakeRootScope
.
$broadcast
.
reset
();
fakeStore
.
setState
({
groups
:
dummyGroups
,
focusedGroup
:
dummyGroups
[
1
]
});
assert
.
notCalled
(
fakeRootScope
.
$broadcast
);
});
});
});
describe
(
'#leave'
,
function
()
{
describe
(
'#leave'
,
function
()
{
...
...
src/sidebar/store/modules/groups.js
View file @
6dc6a8d0
...
@@ -82,6 +82,15 @@ function focusedGroup(state) {
...
@@ -82,6 +82,15 @@ function focusedGroup(state) {
return
getGroup
(
state
,
state
.
focusedGroupId
);
return
getGroup
(
state
,
state
.
focusedGroupId
);
}
}
/**
* Return the current focused group ID or `null`.
*
* @return {string|null}
*/
function
focusedGroupId
(
state
)
{
return
state
.
focusedGroupId
;
}
/**
/**
* Return the list of all groups.
* Return the list of all groups.
*
*
...
@@ -111,5 +120,6 @@ module.exports = {
...
@@ -111,5 +120,6 @@ module.exports = {
allGroups
,
allGroups
,
getGroup
,
getGroup
,
focusedGroup
,
focusedGroup
,
focusedGroupId
,
},
},
};
};
src/sidebar/store/modules/test/groups-test.js
View file @
6dc6a8d0
...
@@ -82,4 +82,16 @@ describe('sidebar.store.modules.groups', () => {
...
@@ -82,4 +82,16 @@ describe('sidebar.store.modules.groups', () => {
assert
.
deepEqual
(
store
.
focusedGroup
(),
privateGroup
);
assert
.
deepEqual
(
store
.
focusedGroup
(),
privateGroup
);
});
});
});
});
describe
(
'focusedGroupId'
,
()
=>
{
it
(
'returns `null` if no group is focused'
,
()
=>
{
assert
.
equal
(
store
.
focusedGroupId
(),
null
);
});
it
(
'returns the focused group ID if a group has been focused'
,
()
=>
{
store
.
loadGroups
([
privateGroup
]);
store
.
focusGroup
(
privateGroup
.
id
);
assert
.
equal
(
store
.
focusedGroupId
(),
privateGroup
.
id
);
});
});
});
});
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