Skip to content

Commit e36b798

Browse files
committed
address comments
1 parent b99c7eb commit e36b798

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

packages/compass-collection/src/components/mock-data-generator-modal/mock-data-generator-modal.spec.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { StepButtonLabelMap } from './constants';
88

99
describe('MockDataGeneratorModal', () => {
1010
const sandbox = Sinon.createSandbox();
11-
let setIsOpen: Sinon.SinonSpy;
11+
let onOpenChange: Sinon.SinonSpy;
1212

1313
beforeEach(() => {
14-
setIsOpen = sandbox.spy();
14+
onOpenChange = sandbox.spy();
1515
});
1616

1717
afterEach(() => {
@@ -23,15 +23,15 @@ describe('MockDataGeneratorModal', () => {
2323
currentStep = MockDataGeneratorStep.AI_DISCLAIMER,
2424
} = {}) {
2525
function MockDataGeneratorModalWrapper() {
26-
const [currentStepStateMock, setCurrentStepStateMock] =
26+
const [currentStepStateMock, onCurrentStepChangeStateMock] =
2727
React.useState<MockDataGeneratorStep>(currentStep);
2828
return (
2929
<MockDataGeneratorModal
3030
isOpen={isOpen}
31-
setIsOpen={setIsOpen}
31+
onOpenChange={onOpenChange}
3232
currentStep={currentStepStateMock}
33-
setCurrentStep={(step) => {
34-
setCurrentStepStateMock(step);
33+
onCurrentStepChange={(step) => {
34+
onCurrentStepChangeStateMock(step);
3535
}}
3636
/>
3737
);
@@ -51,20 +51,20 @@ describe('MockDataGeneratorModal', () => {
5151
expect(screen.queryByTestId('generate-mock-data-modal')).to.not.exist;
5252
});
5353

54-
it('calls setIsOpen(false) when the modal is closed', () => {
54+
it('calls onOpenChange(false) when the modal is closed', () => {
5555
renderModal();
5656

5757
screen.getByLabelText('Close modal').click();
5858

59-
expect(setIsOpen.calledOnceWith(false)).to.be.true;
59+
expect(onOpenChange.calledOnceWith(false)).to.be.true;
6060
});
6161

62-
it('calls setIsOpen(false) when the cancel button is clicked', () => {
62+
it('calls onOpenChange(false) when the cancel button is clicked', () => {
6363
renderModal();
6464

6565
screen.getByText('Cancel').click();
6666

67-
expect(setIsOpen.calledOnceWith(false)).to.be.true;
67+
expect(onOpenChange.calledOnceWith(false)).to.be.true;
6868
});
6969

7070
it('disables the Back button on the first step', () => {
@@ -76,9 +76,9 @@ describe('MockDataGeneratorModal', () => {
7676
});
7777

7878
describe('when rendering the modal in a specific step', () => {
79-
const steps = Object.values(MockDataGeneratorStep).filter(
80-
(step) => typeof step === 'number'
81-
) as MockDataGeneratorStep[];
79+
const steps = Object.keys(
80+
StepButtonLabelMap
81+
) as unknown as MockDataGeneratorStep[];
8282

8383
steps.forEach((currentStep) => {
8484
it(`renders the button with the correct label when the user is in step "${currentStep}"`, () => {

packages/compass-collection/src/components/mock-data-generator-modal/mock-data-generator-modal.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import React from 'react';
22

3-
import { css, ModalBody, ModalHeader } from '@mongodb-js/compass-components';
3+
import {
4+
css,
5+
ModalBody,
6+
ModalHeader,
7+
spacing,
8+
} from '@mongodb-js/compass-components';
49

510
import {
611
Button,
@@ -18,51 +23,51 @@ const footerStyles = css`
1823

1924
const rightButtonsStyles = css`
2025
display: flex;
21-
gap: 8px;
26+
gap: ${spacing[200]}px;
2227
flex-direction: row;
2328
`;
2429

2530
interface Props {
2631
isOpen: boolean;
27-
setIsOpen: (isOpen: boolean) => void;
32+
onOpenChange: (isOpen: boolean) => void;
2833
currentStep: MockDataGeneratorStep;
29-
setCurrentStep: (step: MockDataGeneratorStep) => void;
34+
onCurrentStepChange: (step: MockDataGeneratorStep) => void;
3035
}
3136

3237
const MockDataGeneratorModal = ({
3338
isOpen,
34-
setIsOpen,
39+
onOpenChange,
3540
currentStep,
36-
setCurrentStep,
41+
onCurrentStepChange,
3742
}: Props) => {
3843
const resetState = () => {
39-
setCurrentStep(MockDataGeneratorStep.AI_DISCLAIMER);
44+
onCurrentStepChange(MockDataGeneratorStep.AI_DISCLAIMER);
4045
};
4146

4247
const onNext = () => {
4348
if (currentStep < MockDataGeneratorStep.GENERATE_DATA) {
44-
setCurrentStep(currentStep + 1);
49+
onCurrentStepChange(currentStep + 1);
4550
} else {
46-
setIsOpen(false);
51+
onOpenChange(false);
4752
resetState();
4853
}
4954
};
5055

5156
const onBack = () => {
5257
if (currentStep > MockDataGeneratorStep.AI_DISCLAIMER) {
53-
setCurrentStep(currentStep - 1);
58+
onCurrentStepChange(currentStep - 1);
5459
}
5560
};
5661

5762
const onCancel = () => {
58-
setIsOpen(false);
63+
onOpenChange(false);
5964
resetState();
6065
};
6166

6267
return (
6368
<Modal
6469
open={isOpen}
65-
setOpen={(open) => setIsOpen(open)}
70+
setOpen={(open) => onOpenChange(open)}
6671
data-testid="generate-mock-data-modal"
6772
>
6873
<ModalHeader title="Generate Mock Data" />

0 commit comments

Comments
 (0)