Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
8d29b435
Commit
8d29b435
authored
May 27, 2019
by
Martin Wortschack
Committed by
Fatih Acet
May 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update onboarding utils
- Add more constants - Add specs for onboarding utils
parent
840b6f01
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
144 additions
and
28 deletions
+144
-28
ee/app/assets/javascripts/onboarding/constants.js
ee/app/assets/javascripts/onboarding/constants.js
+14
-2
ee/app/assets/javascripts/onboarding/onboarding_welcome/components/welcome_page.vue
...onboarding/onboarding_welcome/components/welcome_page.vue
+4
-3
ee/app/assets/javascripts/onboarding/utils.js
ee/app/assets/javascripts/onboarding/utils.js
+43
-23
ee/spec/javascripts/onboarding/utils_spec.js
ee/spec/javascripts/onboarding/utils_spec.js
+83
-0
No files found.
ee/app/assets/javascripts/onboarding/constants.js
View file @
8d29b435
const
STORAGE_KEY
=
'
onboarding_state
'
;
export
const
ONBOARDING_DISMISSED_COOKIE_NAME
=
'
onboarding_dismissed
'
;
export
default
STORAGE_KEY
;
export
const
STORAGE_KEY
=
'
onboarding_state
'
;
export
const
AVAILABLE_TOURS
=
{
GUIDED_GITLAB_TOUR
:
1
,
CREATE_PROJECT_TOUR
:
2
,
INVITE_COLLEAGUES_TOUR
:
3
,
};
export
const
ONBOARDING_PROPS_DEFAULTS
=
{
tourKey
:
AVAILABLE_TOURS
.
GUIDED_GITLAB_TOUR
,
lastStepIndex
:
-
1
,
createdProjectPath
:
''
,
};
ee/app/assets/javascripts/onboarding/onboarding_welcome/components/welcome_page.vue
View file @
8d29b435
...
...
@@ -3,7 +3,7 @@ import { __ } from '~/locale';
import
{
GlLink
,
GlPopover
}
from
'
@gitlab/ui
'
;
import
UserAvatarImage
from
'
~/vue_shared/components/user_avatar/user_avatar_image.vue
'
;
import
{
redirectTo
}
from
'
~/lib/utils/url_utility
'
;
import
{
resetOnboardingLocalStorage
,
updateLocalStorage
}
from
'
./../../utils
'
;
import
onboardingUtils
from
'
./../../utils
'
;
export
default
{
components
:
{
...
...
@@ -48,11 +48,12 @@ export default {
},
methods
:
{
startTour
()
{
resetOnboardingLocalStorage
();
onboardingUtils
.
resetOnboardingLocalStorage
();
onboardingUtils
.
updateOnboardingDismissed
(
false
);
redirectTo
(
this
.
projectFullPath
);
},
skipTour
()
{
updateLocalStorage
({
dismissed
:
true
}
);
onboardingUtils
.
updateOnboardingDismissed
(
true
);
redirectTo
(
this
.
skipUrl
);
},
},
...
...
ee/app/assets/javascripts/onboarding/utils.js
View file @
8d29b435
import
STORAGE_KEY
from
'
./constants
'
;
import
Cookies
from
'
js-cookie
'
;
import
AccessorUtilities
from
'
~/lib/utils/accessor
'
;
import
{
ONBOARDING_DISMISSED_COOKIE_NAME
,
STORAGE_KEY
,
ONBOARDING_PROPS_DEFAULTS
,
}
from
'
./constants
'
;
const
isOnboardingDismissed
=
()
=>
Cookies
.
get
(
ONBOARDING_DISMISSED_COOKIE_NAME
)
===
'
true
'
;
const
updateOnboardingDismissed
=
dismissed
=>
Cookies
.
set
(
ONBOARDING_DISMISSED_COOKIE_NAME
,
dismissed
);
const
resetOnboardingLocalStorage
=
()
=>
{
if
(
AccessorUtilities
.
isLocalStorageAccessSafe
())
{
localStorage
.
setItem
(
STORAGE_KEY
,
JSON
.
stringify
(
ONBOARDING_PROPS_DEFAULTS
));
}
};
/**
* onboarding_state:
* activeTour: Number
* dismissed: Boolean
*/
const
getOnboardingLocalStorageState
=
()
=>
{
if
(
AccessorUtilities
.
isLocalStorageAccessSafe
())
{
return
JSON
.
parse
(
localStorage
.
getItem
(
STORAGE_KEY
));
}
const
ONBOARDING_PROPS_DEFAULTS
=
{
activeTourKey
:
1
,
dismissed
:
false
,
return
ONBOARDING_PROPS_DEFAULTS
;
};
export
const
resetOnboardingLocalStorage
=
()
=>
{
localStorage
.
setItem
(
STORAGE_KEY
,
JSON
.
stringify
(
ONBOARDING_PROPS_DEFAULTS
));
}
;
const
updateLocalStorage
=
updatedProps
=>
{
if
(
AccessorUtilities
.
isLocalStorageAccessSafe
())
{
let
currentState
=
getOnboardingLocalStorageState
()
;
export
const
getOnboardingLocalStorageState
=
()
=>
JSON
.
parse
(
localStorage
.
getItem
(
STORAGE_KEY
));
if
(
!
currentState
)
{
currentState
=
resetOnboardingLocalStorage
();
}
export
const
updateLocalStorage
=
updatedProps
=>
{
let
currentState
=
getOnboardingLocalStorageState
();
const
onboardingState
=
{
...
currentState
,
...
updatedProps
,
};
if
(
!
currentState
)
{
currentState
=
resetOnboardingLocalStorage
();
localStorage
.
setItem
(
STORAGE_KEY
,
JSON
.
stringify
(
onboardingState
));
}
};
const
onboardingState
=
{
...
currentState
,
...
updatedProps
,
};
localStorage
.
setItem
(
STORAGE_KEY
,
JSON
.
stringify
(
onboardingState
));
const
onboardingUtils
=
{
isOnboardingDismissed
,
updateOnboardingDismissed
,
resetOnboardingLocalStorage
,
getOnboardingLocalStorageState
,
updateLocalStorage
,
};
export
default
onboardingUtils
;
ee/spec/javascripts/onboarding/utils_spec.js
0 → 100644
View file @
8d29b435
import
Cookies
from
'
js-cookie
'
;
import
AccessorUtilities
from
'
~/lib/utils/accessor
'
;
import
{
ONBOARDING_DISMISSED_COOKIE_NAME
,
STORAGE_KEY
,
ONBOARDING_PROPS_DEFAULTS
,
}
from
'
ee/onboarding/constants
'
;
import
onboardingUtils
from
'
ee/onboarding/utils
'
;
describe
(
'
User onboarding utils
'
,
()
=>
{
beforeEach
(()
=>
{
Cookies
.
remove
(
ONBOARDING_DISMISSED_COOKIE_NAME
);
onboardingUtils
.
resetOnboardingLocalStorage
();
spyOn
(
AccessorUtilities
,
'
isLocalStorageAccessSafe
'
).
and
.
returnValue
(
true
);
});
describe
(
'
isOnboardingDismissed
'
,
()
=>
{
it
(
'
return true if the cookie value is true
'
,
()
=>
{
Cookies
.
set
(
ONBOARDING_DISMISSED_COOKIE_NAME
,
true
);
expect
(
onboardingUtils
.
isOnboardingDismissed
()).
toBe
(
true
);
});
it
(
'
return false if the cookie is not set
'
,
()
=>
{
expect
(
onboardingUtils
.
isOnboardingDismissed
()).
toBe
(
false
);
});
});
describe
(
'
updateOnboardingDismissed
'
,
()
=>
{
it
(
'
set the dismissed state on the cookie
'
,
()
=>
{
const
dismissed
=
true
;
Cookies
.
set
(
ONBOARDING_DISMISSED_COOKIE_NAME
,
dismissed
);
expect
(
Cookies
.
get
(
ONBOARDING_DISMISSED_COOKIE_NAME
)).
toBe
(
`
${
dismissed
}
`
);
});
});
describe
(
'
resetOnboardingLocalStorage
'
,
()
=>
{
it
(
'
resets the onboarding props in the localStorage to the default
'
,
()
=>
{
const
modified
=
{
tourKey
:
2
,
lastStepIndex
:
5
,
createdProjectPath
:
'
foo
'
,
};
localStorage
.
setItem
(
STORAGE_KEY
,
JSON
.
stringify
(
modified
));
onboardingUtils
.
resetOnboardingLocalStorage
();
expect
(
JSON
.
parse
(
localStorage
.
getItem
(
STORAGE_KEY
))).
toEqual
(
ONBOARDING_PROPS_DEFAULTS
);
});
});
describe
(
'
getOnboardingLocalStorageState
'
,
()
=>
{
it
(
'
retrieves the proper values from localStorage
'
,
()
=>
{
const
modified
=
{
tourKey
:
2
,
lastStepIndex
:
5
,
createdProjectPath
:
'
foo
'
,
};
localStorage
.
setItem
(
STORAGE_KEY
,
JSON
.
stringify
(
modified
));
expect
(
onboardingUtils
.
getOnboardingLocalStorageState
()).
toEqual
(
modified
);
});
});
describe
(
'
updateLocalStorage
'
,
()
=>
{
it
(
'
updates the onboarding state on the localStorage
'
,
()
=>
{
spyOn
(
localStorage
,
'
setItem
'
);
const
modified
=
{
tourKey
:
2
,
lastStepIndex
:
5
,
createdProjectPath
:
'
foo
'
,
};
onboardingUtils
.
updateLocalStorage
(
modified
);
expect
(
localStorage
.
setItem
).
toHaveBeenCalledWith
(
STORAGE_KEY
,
JSON
.
stringify
(
modified
));
});
});
});
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