Skip to content

Commit d8df6cf

Browse files
committed
use constant instead of util function for getting button label
1 parent fd32c05 commit d8df6cf

File tree

4 files changed

+17
-36
lines changed

4 files changed

+17
-36
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { MockDataGeneratorStep } from './types';
2+
3+
export const StepButtonLabelMap = {
4+
[MockDataGeneratorStep.AI_DISCLAIMER]: 'Use Natural Language',
5+
[MockDataGeneratorStep.SCHEMA_CONFIRMATION]: 'Confirm',
6+
[MockDataGeneratorStep.SCHEMA_EDITOR]: 'Next',
7+
[MockDataGeneratorStep.DOCUMENT_COUNT]: 'Next',
8+
[MockDataGeneratorStep.PREVIEW_DATA]: 'Generate Script',
9+
[MockDataGeneratorStep.GENERATE_DATA]: 'Done',
10+
} as const;

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { render, screen } from '@mongodb-js/testing-library-compass';
44
import Sinon from 'sinon';
55
import MockDataGeneratorModal from './mock-data-generator-modal';
66
import { MockDataGeneratorStep } from './types';
7+
import { StepButtonLabelMap } from './constants';
78

89
describe('MockDataGeneratorModal', () => {
910
const sandbox = Sinon.createSandbox();
@@ -87,20 +88,9 @@ describe('MockDataGeneratorModal', () => {
8788
it('renders the next step button with the correct label on each step', () => {
8889
renderModal();
8990

90-
expect(screen.getByTestId('next-step-button')).to.have.text(
91-
'Use Natural Language'
92-
);
93-
screen.getByTestId('next-step-button').click();
94-
expect(screen.getByTestId('next-step-button')).to.have.text('Confirm');
95-
screen.getByTestId('next-step-button').click();
96-
expect(screen.getByTestId('next-step-button')).to.have.text('Next');
97-
screen.getByTestId('next-step-button').click();
98-
expect(screen.getByTestId('next-step-button')).to.have.text('Next');
99-
screen.getByTestId('next-step-button').click();
100-
expect(screen.getByTestId('next-step-button')).to.have.text(
101-
'Generate Script'
102-
);
103-
screen.getByTestId('next-step-button').click();
104-
expect(screen.getByTestId('next-step-button')).to.have.text('Done');
91+
Object.values(StepButtonLabelMap).forEach((label) => {
92+
expect(screen.getByTestId('next-step-button')).to.have.text(label);
93+
screen.getByTestId('next-step-button').click();
94+
});
10595
});
10696
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
ButtonVariant,
1010
} from '@mongodb-js/compass-components';
1111
import { MockDataGeneratorStep } from './types';
12-
import { getNextStepButtonLabel } from './utils';
12+
import { StepButtonLabelMap } from './constants';
1313

1414
const footerStyles = css`
1515
flex-direction: row;
@@ -84,7 +84,7 @@ const MockDataGeneratorModal = ({
8484
onClick={onNext}
8585
data-testid="next-step-button"
8686
>
87-
{getNextStepButtonLabel(currentStep)}
87+
{StepButtonLabelMap[currentStep]}
8888
</Button>
8989
</div>
9090
</ModalFooter>

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

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)