From 1227568beed71068c550b7a3317a8842fa220d33 Mon Sep 17 00:00:00 2001 From: Stanislav Lunyachek Date: Sat, 21 Oct 2023 22:06:24 +0300 Subject: [PATCH] fix: Prevent wrong appearance of skeleton after second tab click --- src/common-components/ThirdPartyAuth.jsx | 10 +++++----- src/logistration/Logistration.jsx | 7 +++++-- src/logistration/Logistration.test.jsx | 12 +++++++++++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/common-components/ThirdPartyAuth.jsx b/src/common-components/ThirdPartyAuth.jsx index dfe1a48297..3b78203605 100644 --- a/src/common-components/ThirdPartyAuth.jsx +++ b/src/common-components/ThirdPartyAuth.jsx @@ -6,6 +6,7 @@ import { Hyperlink, Icon, } from '@openedx/paragon'; import { Institution } from '@openedx/paragon/icons'; +import classNames from 'classnames'; import PropTypes from 'prop-types'; import Skeleton from 'react-loading-skeleton'; @@ -18,7 +19,6 @@ import { RenderInstitutionButton, SocialAuthProviders, } from './index'; -import classNames from "classnames"; /** * This component renders the Single sign-on (SSO) buttons for the providers passed. @@ -50,9 +50,9 @@ const ThirdPartyAuth = (props) => { {(isLoginPage && !isEnterpriseLoginDisabled && isSocialAuthActive) && ( @@ -61,7 +61,7 @@ const ThirdPartyAuth = (props) => { )} - {thirdPartyAuthApiStatus === PENDING_STATE || true ? ( + {thirdPartyAuthApiStatus === PENDING_STATE ? (
diff --git a/src/logistration/Logistration.jsx b/src/logistration/Logistration.jsx index 971f146f9c..cc41d5e15d 100644 --- a/src/logistration/Logistration.jsx +++ b/src/logistration/Logistration.jsx @@ -70,7 +70,10 @@ const Logistration = (props) => { setInstitutionLogin(!institutionLogin); }; - const handleOnSelect = (tabKey) => { + const handleOnSelect = (tabKey, currentTab) => { + if (tabKey === currentTab) { + return; + } sendTrackEvent(`edx.bi.${tabKey.replace('/', '')}_form.toggled`, { category: 'user-engagement' }); props.clearThirdPartyAuthContextErrorMessage(); if (tabKey === LOGIN_PAGE) { @@ -122,7 +125,7 @@ const Logistration = (props) => { ); } return ( - + handleOnSelect(tabKey, selectedPage)}> diff --git a/src/logistration/Logistration.test.jsx b/src/logistration/Logistration.test.jsx index 3b231d2276..10d33f6c14 100644 --- a/src/logistration/Logistration.test.jsx +++ b/src/logistration/Logistration.test.jsx @@ -264,9 +264,11 @@ describe('Logistration', () => { fireEvent.click(container.querySelector('a[data-rb-event-key="/login"]')); expect(store.dispatch).toHaveBeenCalledWith(backupRegistrationForm()); }); + it('should fire action to backup login form on tab click', () => { store.dispatch = jest.fn(store.dispatch); - const { container } = render(reduxWrapper()); + const props = { selectedPage: LOGIN_PAGE }; + const { container } = render(reduxWrapper()); fireEvent.click(container.querySelector('a[data-rb-event-key="/register"]')); expect(store.dispatch).toHaveBeenCalledWith(backupLoginForm()); }); @@ -277,4 +279,12 @@ describe('Logistration', () => { fireEvent.click(container.querySelector('a[data-rb-event-key="/login"]')); expect(store.dispatch).toHaveBeenCalledWith(clearThirdPartyAuthContextErrorMessage()); }); + + it('should do nothing when user clicks on the same tab (login/register) again', () => { + const { container } = render(reduxWrapper()); + // While staying on the registration form, clicking the register tab again + fireEvent.click(container.querySelector('a[data-rb-event-key="/register"]')); + + expect(sendTrackEvent).not.toHaveBeenCalledWith('edx.bi.register.toggled', { category: 'user-engagement' }); + }); });