diff --git a/app/assets/javascripts/initializers/initializeOnboardingTaskCard.js.erb b/app/assets/javascripts/initializers/initializeOnboardingTaskCard.js.erb
index 8b96a490e..8cca5de3e 100644
--- a/app/assets/javascripts/initializers/initializeOnboardingTaskCard.js.erb
+++ b/app/assets/javascripts/initializers/initializeOnboardingTaskCard.js.erb
@@ -8,8 +8,7 @@ function initializeOnboardingTaskCard() {
if (localStorage.getItem('task-card-closed') === 'yes') { return }
var taskCard = document.getElementsByClassName("onboarding-task-card")[0];
-
- if (taskCard == null) { return }
+ if (taskCard == null) { return } // This guard against both null and undefined taskCard
var createdAt = new Date(userData().created_at);
var now = new Date();
diff --git a/app/javascript/onboarding/Onboarding.jsx b/app/javascript/onboarding/Onboarding.jsx
index e597e931b..dcfae56c3 100644
--- a/app/javascript/onboarding/Onboarding.jsx
+++ b/app/javascript/onboarding/Onboarding.jsx
@@ -3,7 +3,6 @@ import { h, Component } from 'preact';
import IntroSlide from './components/IntroSlide';
import EmailPreferencesForm from './components/EmailPreferencesForm';
-import ClosingSlide from './components/ClosingSlide';
import FollowTags from './components/FollowTags';
import FollowUsers from './components/FollowUsers';
import ProfileForm from './components/ProfileForm';
@@ -24,7 +23,6 @@ export default class Onboarding extends Component {
ProfileForm,
FollowUsers,
EmailPreferencesForm,
- ClosingSlide,
];
this.slides = slides.map((SlideComponent) => (
@@ -47,6 +45,8 @@ export default class Onboarding extends Component {
this.setState({
currentSlide: nextSlide,
});
+ } else {
+ window.location.href = '/';
}
}
diff --git a/app/javascript/onboarding/__tests__/Onboarding.test.jsx b/app/javascript/onboarding/__tests__/Onboarding.test.jsx
index 98dd758b9..021acf027 100644
--- a/app/javascript/onboarding/__tests__/Onboarding.test.jsx
+++ b/app/javascript/onboarding/__tests__/Onboarding.test.jsx
@@ -302,6 +302,7 @@ describe('', () => {
describe('EmailPreferencesForm', () => {
let onboardingSlides;
+ const { location } = window;
const emailPreferencesFormIndex = 4;
beforeEach(() => {
@@ -311,18 +312,32 @@ describe('', () => {
);
});
+ afterEach(() => {
+ window.location = location;
+ });
+
test('renders properly', () => {
expect(onboardingSlides).toMatchSnapshot();
});
- test('should allow user to advance', async () => {
+ test('should redirect user when finished', async () => {
fetch.once({});
+ // Setup: Enable window.location to be writable.
+ const url = 'https://dummy.com/onboarding';
+ Object.defineProperty(window, 'location', {
+ value: { href: url },
+ writable: true,
+ });
+
+ expect(window.location.href).toBe(url);
onboardingSlides.find('.next-button').simulate('click');
await flushPromises();
+ // No longer advance slide.
expect(onboardingSlides.state().currentSlide).toBe(
- emailPreferencesFormIndex + 1,
+ emailPreferencesFormIndex,
);
+ expect(window.location.href).toBe('/');
});
it('should step backward', () => {
@@ -332,17 +347,4 @@ describe('', () => {
);
});
});
-
- describe('ClosingSlide', () => {
- let onboardingSlides;
- const closingSlideIndex = 5;
-
- beforeEach(() => {
- onboardingSlides = initializeSlides(closingSlideIndex, getUserData());
- });
-
- test('renders properly', () => {
- expect(onboardingSlides).toMatchSnapshot();
- });
- });
});
diff --git a/app/javascript/onboarding/__tests__/__snapshots__/Onboarding.test.jsx.snap b/app/javascript/onboarding/__tests__/__snapshots__/Onboarding.test.jsx.snap
index ef85e93d5..467736555 100644
--- a/app/javascript/onboarding/__tests__/__snapshots__/Onboarding.test.jsx.snap
+++ b/app/javascript/onboarding/__tests__/__snapshots__/Onboarding.test.jsx.snap
@@ -1,82 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[` ClosingSlide renders properly 1`] = `
-preact-render-spy (1 nodes)
--------
-
-
-
-
-`;
-
exports[` EmailPreferencesForm renders properly 1`] = `
preact-render-spy (1 nodes)
-------
diff --git a/app/javascript/onboarding/components/ClosingSlide.jsx b/app/javascript/onboarding/components/ClosingSlide.jsx
deleted file mode 100644
index 28ab63ac6..000000000
--- a/app/javascript/onboarding/components/ClosingSlide.jsx
+++ /dev/null
@@ -1,90 +0,0 @@
-import { h, Component } from 'preact';
-import PropTypes from 'prop-types';
-
-import { updateOnboarding } from '../utilities';
-
-class ClosingSlide extends Component {
- componentDidMount() {
- updateOnboarding('closing slide');
- }
-
- render() {
- const { previousLocation } = this.props;
-
- const previousLocationListElement = () => {
- if (
- previousLocation !== 'none' &&
- previousLocation !== null &&
- !previousLocation.startsWith('javascript')
- ) {
- return (
-
- Or go back to the page you were on before you signed up
- {previousLocation}
-
- );
- }
- return null;
- };
-
- return (
-
-
-
-
- You‘re a part of the community!
-
- {' '}
- π
-
-
- What next?
-
-
-
-
- {previousLocationListElement()}
-
-
- );
- }
-}
-
-ClosingSlide.propTypes = {
- previousLocation: PropTypes.string.isRequired,
-};
-
-export default ClosingSlide;