Skip to content

Commit 7e0901b

Browse files
mfranciscDevtools
andauthored
fixes for spinner and phone verification flow
Co-authored-by: Devtools <devtools@redhat.com>
1 parent 072cfb6 commit 7e0901b

7 files changed

Lines changed: 33 additions & 20 deletions

File tree

workspaces/sandbox/plugins/sandbox/src/components/Modals/PhoneVerificationModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export const PhoneVerificationModal: React.FC<PhoneVerificationModalProps> = ({
101101
const handleEditPhoneNumber = () => {
102102
setPhoneNumber(undefined);
103103
setEnterOTP(false);
104+
setOtp(['', '', '', '', '', '']);
104105
};
105106

106107
const handleResendCode = async () => {

workspaces/sandbox/plugins/sandbox/src/components/Modals/PhoneVerificationSteps/PhoneNumberStep.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,8 @@ export const PhoneNumberStep: React.FC<PhoneNumberFormProps> = ({
187187
>
188188
<RPNInput
189189
required
190-
defaultCountry="ES"
190+
defaultCountry={country || 'ES'}
191191
label="Phone number"
192-
placeholder="(000) 000 0000"
193192
value={phoneNumber}
194193
onChange={setPhoneNumber}
195194
inputComponent={PhoneInputField}

workspaces/sandbox/plugins/sandbox/src/components/Modals/PhoneVerificationSteps/VerificationCodeStep.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export const VerificationCodeStep: React.FC<VerificationCodeProps> = ({
6262
const inputRefs = useRef<any>([]);
6363

6464
useEffect(() => {
65+
// Focus on the first input box when modal opens
6566
if (!otp[0]) {
6667
// Focus on the first input box when modal opens
6768
setTimeout(() => inputRefs.current[0]?.focus(), 100);
@@ -153,6 +154,7 @@ export const VerificationCodeStep: React.FC<VerificationCodeProps> = ({
153154
{otp.map((digit, index) => (
154155
<TextField
155156
key={index}
157+
data-testid="opt-inputs"
156158
value={digit}
157159
onChange={e => handleChange(index, e)}
158160
onKeyDown={e =>

workspaces/sandbox/plugins/sandbox/src/components/Modals/PhoneVerificationSteps/__tests__/VerificationCodeStep.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ describe('VerificationCodeStep', () => {
7777
// submit phone button should be there
7878
const submitButton = screen.getAllByTestId('submit-opt-button');
7979
expect(submitButton).toHaveLength(1);
80+
// opt inputs are there
81+
const optInputFields = screen.getAllByTestId('opt-inputs');
82+
expect(optInputFields).toHaveLength(5);
8083
// resend opt should be there
8184
const resendOptLink = screen.getAllByTestId('resend-code-link');
8285
expect(resendOptLink).toHaveLength(1);

workspaces/sandbox/plugins/sandbox/src/components/Modals/__tests__/PhoneVerificationModal.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ describe('PhoneVerificationModal', () => {
8383
);
8484
};
8585

86+
test('should open the modal', () => {
87+
renderComponent();
88+
89+
expect(screen.getByText("Let's verify you")).toBeInTheDocument();
90+
expect(
91+
screen.getByText(
92+
"Enter your phone number and we'll send you a text message with a verification code.",
93+
),
94+
).toBeInTheDocument();
95+
});
96+
8697
test('should handle modal close', () => {
8798
renderComponent();
8899

workspaces/sandbox/plugins/sandbox/src/components/SandboxCatalog/SandboxCatalogCardButton.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ export const SandboxCatalogCardButton: React.FC<
3737
> = ({ link, id, handleTryButtonClick, theme, refetchingUserData }) => {
3838
const { loading, userFound, verificationRequired, userReady, ansibleStatus } =
3939
useSandboxContext();
40+
const [clicked, setClicked] = React.useState(false);
41+
42+
const handleClick = () => {
43+
if (!clicked) setClicked(true);
44+
handleTryButtonClick(id);
45+
};
4046

4147
const label = (() => {
4248
if (id === Product.AAP) {
@@ -56,9 +62,9 @@ export const SandboxCatalogCardButton: React.FC<
5662

5763
let endIcon;
5864
if (
59-
loading ||
60-
(userFound && !userReady && !verificationRequired) ||
61-
refetchingUserData
65+
(loading && clicked) ||
66+
(userFound && !userReady && !verificationRequired && clicked) ||
67+
(refetchingUserData && clicked)
6268
) {
6369
endIcon = <CircularProgress size={20} />;
6470
} else if (id !== Product.AAP) {
@@ -90,7 +96,7 @@ export const SandboxCatalogCardButton: React.FC<
9096
variant="outlined"
9197
onClick={() => {
9298
if (!loading) {
93-
handleTryButtonClick(id);
99+
handleClick();
94100
}
95101
}}
96102
endIcon={endIcon}

workspaces/sandbox/plugins/sandbox/src/components/SandboxCatalog/__tests__/SandboxCatalogCardButton.test.tsx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
import React from 'react';
1817
import { render, screen, fireEvent } from '@testing-library/react';
1918
import { ThemeProvider, createTheme } from '@mui/material/styles';
@@ -107,27 +106,19 @@ describe('SandboxCatalogCardButton', () => {
107106
expect(screen.getByText('Reprovision')).toBeInTheDocument();
108107
});
109108

110-
it('shows loading spinner when loading is true', () => {
111-
mockUseSandboxContext.mockReturnValue({
112-
loading: true,
113-
userFound: false,
114-
userReady: false,
115-
ansibleStatus: AnsibleStatus.UNKNOWN,
116-
} as any);
117-
118-
renderButton();
119-
expect(screen.getByRole('progressbar')).toBeInTheDocument();
120-
});
121-
122-
it('shows loading spinner when userFound is true but userReady is false', () => {
109+
it('button was clicked - shows loading spinner when userFound is true but userReady is false', async () => {
123110
mockUseSandboxContext.mockReturnValue({
124111
loading: false,
125112
userFound: true,
126113
userReady: false,
127114
ansibleStatus: AnsibleStatus.UNKNOWN,
115+
verificationRequired: false,
128116
} as any);
129117

130118
renderButton();
119+
const button = screen.getByRole('button');
120+
fireEvent.click(button);
121+
131122
expect(screen.getByRole('progressbar')).toBeInTheDocument();
132123
});
133124

0 commit comments

Comments
 (0)