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
64ad7b38
Commit
64ad7b38
authored
Nov 03, 2019
by
Lyza Danger Gardner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine util for determining whether to auto-display tutorial
parent
160b8923
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
15 deletions
+117
-15
session-util.js
src/sidebar/util/session-util.js
+32
-0
session-util-test.js
src/sidebar/util/test/session-util-test.js
+85
-15
No files found.
src/sidebar/util/session-util.js
View file @
64ad7b38
'use strict'
;
'use strict'
;
const
serviceConfig
=
require
(
'../service-config'
);
/**
/**
* Returns true if the sidebar tutorial has to be shown to a user for a given session.
* Returns true if the sidebar tutorial has to be shown to a user for a given session.
* @deprecated To be removed once preact help/tutorial panel is in place
*/
*/
function
shouldShowSidebarTutorial
(
sessionState
)
{
function
shouldShowSidebarTutorial
(
sessionState
)
{
if
(
sessionState
.
preferences
.
show_sidebar_tutorial
)
{
if
(
sessionState
.
preferences
.
show_sidebar_tutorial
)
{
...
@@ -10,6 +13,35 @@ function shouldShowSidebarTutorial(sessionState) {
...
@@ -10,6 +13,35 @@ function shouldShowSidebarTutorial(sessionState) {
return
false
;
return
false
;
}
}
/**
* The following things must all be true for the tutorial component to auto-display
* on app launch:
* - The app must be operating within the "sidebar" (i.e. not single-annotation
* or stream mode); AND
* - No configuration is present in `settings.services` indicating
* that the host wants to handle its own help requests (i.e. no event handler
* is provided to intercept the default help panel), AND
* - A user profile is loaded in the current state that indicates a `true` value
* for the `show_sidebar_tutorial` preference (i.e. the tutorial has not been
* dismissed by this user yet). This implies the presence of a profile, which
* in turn implies that there is an authenticated user.
*
* @param {boolean} isSidebar - is the app currently displayed in a sidebar?
* @param {Object} sessionState - `session` state from the store
* @param {Object} settings - app configuration/settings
* @return {boolean} - Tutorial panel should be displayed automatically
*/
function
shouldAutoDisplayTutorial
(
isSidebar
,
sessionState
,
settings
)
{
const
shouldShowBasedOnProfile
=
typeof
sessionState
.
preferences
===
'object'
&&
!!
sessionState
.
preferences
.
show_sidebar_tutorial
;
const
service
=
serviceConfig
(
settings
)
||
{};
return
(
isSidebar
&&
!
service
.
onHelpRequestProvided
&&
shouldShowBasedOnProfile
);
}
module
.
exports
=
{
module
.
exports
=
{
shouldShowSidebarTutorial
:
shouldShowSidebarTutorial
,
shouldShowSidebarTutorial
:
shouldShowSidebarTutorial
,
shouldAutoDisplayTutorial
:
shouldAutoDisplayTutorial
,
};
};
src/sidebar/util/test/session-util-test.js
View file @
64ad7b38
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
const
sessionUtil
=
require
(
'../session-util'
);
const
sessionUtil
=
require
(
'../session-util'
);
describe
(
'sessionUtil.shouldShowSidebarTutorial'
,
function
()
{
describe
(
'sidebar.util.session-util'
,
()
=>
{
describe
(
'#shouldShowSidebarTutorial'
,
()
=>
{
it
(
'shows sidebar tutorial if the settings object has the show_sidebar_tutorial key set'
,
function
()
{
it
(
'shows sidebar tutorial if the settings object has the show_sidebar_tutorial key set'
,
function
()
{
const
sessionState
=
{
const
sessionState
=
{
preferences
:
{
preferences
:
{
...
@@ -22,4 +23,73 @@ describe('sessionUtil.shouldShowSidebarTutorial', function() {
...
@@ -22,4 +23,73 @@ describe('sessionUtil.shouldShowSidebarTutorial', function() {
assert
.
isFalse
(
sessionUtil
.
shouldShowSidebarTutorial
(
sessionState
));
assert
.
isFalse
(
sessionUtil
.
shouldShowSidebarTutorial
(
sessionState
));
});
});
});
describe
(
'#shouldAutoDisplayTutorial'
,
()
=>
{
[
{
// The only "true" state
description
:
'in sidebar with loaded user preference to show tutorial'
,
isSidebar
:
true
,
sessionState
:
{
preferences
:
{
show_sidebar_tutorial
:
true
}
},
settings
:
{},
expected
:
true
,
},
{
description
:
'in sidebar with no loaded user profile'
,
isSidebar
:
true
,
sessionState
:
{},
settings
:
{},
expected
:
false
,
},
{
description
:
'not in sidebar with no loaded user profile'
,
isSidebar
:
false
,
sessionState
:
{},
settings
:
{},
expected
:
false
,
},
{
description
:
'in sidebar with loaded user preference not to show tutorial'
,
isSidebar
:
true
,
sessionState
:
{
preferences
:
{
show_sidebar_tutorial
:
false
}
},
settings
:
{},
expected
:
false
,
},
{
description
:
'in sidebar with loaded user preference to show tutorial and configured help service'
,
isSidebar
:
true
,
sessionState
:
{
preferences
:
{
show_sidebar_tutorial
:
true
}
},
settings
:
{
services
:
[{
onHelpRequestProvided
:
true
}]
},
expected
:
false
,
},
{
description
:
'not in sidebar with loaded user preference to show tutorial and configured help service'
,
isSidebar
:
false
,
sessionState
:
{
preferences
:
{
show_sidebar_tutorial
:
true
}
},
settings
:
{
services
:
[{
onHelpRequestProvided
:
true
}]
},
expected
:
false
,
},
{
description
:
'not in sidebar with no loaded user profile and configured help service'
,
isSidebar
:
false
,
sessionState
:
{},
settings
:
{
services
:
[{
onHelpRequestProvided
:
true
}]
},
expected
:
false
,
},
].
forEach
(
fixture
=>
{
it
(
`should calculate auto-display to be
${
fixture
.
expected
}
when
${
fixture
.
description
}
`
,
()
=>
{
const
shouldDisplay
=
sessionUtil
.
shouldAutoDisplayTutorial
(
fixture
.
isSidebar
,
fixture
.
sessionState
,
fixture
.
settings
);
assert
.
equal
(
shouldDisplay
,
fixture
.
expected
);
});
});
});
});
});
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