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
25502a3b
Commit
25502a3b
authored
Dec 14, 2021
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Dec 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support filtering groups through `changeFocusModeUser` RPC method
parent
84d66163
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
5 deletions
+96
-5
cross-origin-rpc.js
src/sidebar/cross-origin-rpc.js
+11
-1
cross-origin-rpc-test.js
src/sidebar/test/cross-origin-rpc-test.js
+85
-4
No files found.
src/sidebar/cross-origin-rpc.js
View file @
25502a3b
...
...
@@ -25,7 +25,17 @@ let preStartQueue = [];
*/
const
registeredMethods
=
store
=>
{
return
{
changeFocusModeUser
:
store
.
changeFocusModeUser
,
/** @param {FocusUserInfo} userInfo */
changeFocusModeUser
:
userInfo
=>
{
store
.
changeFocusModeUser
(
userInfo
);
const
groupIds
=
userInfo
?.
groups
??
[];
const
filteredGroupIds
=
normalizeGroupIds
(
groupIds
,
store
.
allGroups
());
if
(
groupIds
.
length
&&
!
filteredGroupIds
.
length
)
{
console
.
error
(
'No matching groups found in list of filtered group IDs'
);
}
store
.
filterGroups
(
filteredGroupIds
);
},
};
};
...
...
src/sidebar/test/cross-origin-rpc-test.js
View file @
25502a3b
...
...
@@ -11,6 +11,7 @@ class FakeWindow {
}
describe
(
'sidebar/cross-origin-rpc'
,
()
=>
{
let
fakeNormalizeGroupIds
;
let
fakeStore
;
let
fakeWarnOnce
;
let
fakeWindow
;
...
...
@@ -19,9 +20,13 @@ describe('sidebar/cross-origin-rpc', () => {
beforeEach
(()
=>
{
fakeStore
=
{
allGroups
:
sinon
.
stub
().
returns
([]),
changeFocusModeUser
:
sinon
.
stub
(),
filterGroups
:
sinon
.
stub
(),
};
fakeNormalizeGroupIds
=
sinon
.
stub
().
returns
([
'1'
,
'2'
]);
frame
=
{
postMessage
:
sinon
.
stub
()
};
fakeWindow
=
new
FakeWindow
();
...
...
@@ -32,6 +37,7 @@ describe('sidebar/cross-origin-rpc', () => {
fakeWarnOnce
=
sinon
.
stub
();
$imports
.
$mock
({
'./helpers/groups'
:
{
normalizeGroupIds
:
fakeNormalizeGroupIds
},
'../shared/warn-once'
:
fakeWarnOnce
,
});
});
...
...
@@ -64,6 +70,83 @@ describe('sidebar/cross-origin-rpc', () => {
);
});
describe
(
'changeFocusModeUser'
,
()
=>
{
function
callRPC
(
params
)
{
fakeWindow
.
emitter
.
emit
(
'message'
,
{
data
:
{
jsonrpc
:
'2.0'
,
method
:
'changeFocusModeUser'
,
id
:
42
,
params
,
},
origin
:
'https://allowed1.com'
,
source
:
frame
,
});
}
beforeEach
(()
=>
{
sinon
.
stub
(
console
,
'error'
);
});
afterEach
(()
=>
{
console
.
error
.
restore
();
});
it
(
'sets the focused user'
,
()
=>
{
startServer
(
fakeStore
,
settings
,
fakeWindow
);
callRPC
([{
username
:
'foobar'
,
displayName
:
'Simon Says'
}]);
assert
.
calledWith
(
fakeStore
.
changeFocusModeUser
,
sinon
.
match
({
username
:
'foobar'
,
displayName
:
'Simon Says'
})
);
});
context
(
'groups provided'
,
()
=>
{
it
(
'normalizes any provided group IDs and sets filtered groups'
,
()
=>
{
startServer
(
fakeStore
,
settings
,
fakeWindow
);
fakeStore
.
allGroups
.
returns
([
'1'
,
'2'
,
'3'
]);
fakeNormalizeGroupIds
.
returns
([
'1'
,
'2'
]);
callRPC
([{
groups
:
[
'1'
,
'2'
,
'3'
,
'4'
]
}]);
assert
.
calledWith
(
fakeNormalizeGroupIds
,
[
'1'
,
'2'
,
'3'
,
'4'
],
[
'1'
,
'2'
,
'3'
]
);
assert
.
calledWith
(
fakeStore
.
filterGroups
,
[
'1'
,
'2'
]);
assert
.
notCalled
(
console
.
error
);
});
it
(
'logs an error if there are provided group IDs but none match any known groups'
,
()
=>
{
startServer
(
fakeStore
,
settings
,
fakeWindow
);
fakeNormalizeGroupIds
.
returns
([]);
callRPC
([{
groups
:
[
'1'
,
'2'
,
'3'
]
}]);
assert
.
calledWith
(
console
.
error
,
'No matching groups found in list of filtered group IDs'
);
assert
.
calledWith
(
fakeStore
.
filterGroups
,
[]);
});
});
context
(
'no groups provided'
,
()
=>
{
it
(
'sets filtered groups to an empty set'
,
()
=>
{
startServer
(
fakeStore
,
settings
,
fakeWindow
);
fakeNormalizeGroupIds
.
returns
([]);
callRPC
([{
groups
:
[]
}]);
assert
.
calledWith
(
fakeStore
.
filterGroups
,
[]);
assert
.
notCalled
(
console
.
error
);
});
});
});
it
(
'calls the registered method with the provided params'
,
()
=>
{
startServer
(
fakeStore
,
settings
,
fakeWindow
);
...
...
@@ -78,9 +161,7 @@ describe('sidebar/cross-origin-rpc', () => {
source
:
frame
,
});
assert
.
isTrue
(
fakeStore
.
changeFocusModeUser
.
calledWithExactly
(
'one'
,
'two'
)
);
assert
.
isTrue
(
fakeStore
.
changeFocusModeUser
.
calledWithExactly
(
'one'
));
});
it
(
'calls the registered method with no params'
,
()
=>
{
...
...
@@ -95,7 +176,7 @@ describe('sidebar/cross-origin-rpc', () => {
origin
:
'https://allowed1.com'
,
source
:
frame
,
});
assert
.
isTrue
(
fakeStore
.
changeFocusModeUser
.
calledWithExactly
());
assert
.
isTrue
(
fakeStore
.
changeFocusModeUser
.
calledWithExactly
(
undefined
));
});
it
(
'does not call the unregistered method'
,
()
=>
{
...
...
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