@@ -3,54 +3,113 @@ import React from 'react';
3
3
import { render , screen } from '@mongodb-js/testing-library-compass' ;
4
4
import Sinon from 'sinon' ;
5
5
import MockDataGeneratorModal from './mock-data-generator-modal' ;
6
- import { MockDataGeneratorSteps } from './types.ts ' ;
6
+ import { MockDataGeneratorStep } from './types' ;
7
7
8
- describe ( 'MockDataGeneratorModal' , function ( ) {
8
+ describe ( 'MockDataGeneratorModal' , ( ) => {
9
9
const sandbox = Sinon . createSandbox ( ) ;
10
10
let setIsOpen : Sinon . SinonSpy ;
11
11
12
- beforeEach ( function ( ) {
12
+ beforeEach ( ( ) => {
13
13
setIsOpen = sandbox . spy ( ) ;
14
14
} ) ;
15
15
16
- afterEach ( function ( ) {
16
+ afterEach ( ( ) => {
17
17
sandbox . restore ( ) ;
18
18
} ) ;
19
19
20
- const renderModal = ( ) => {
21
- return render (
22
- < MockDataGeneratorModal isOpen = { true } setIsOpen = { setIsOpen } />
23
- ) ;
24
- } ;
20
+ function renderModal ( {
21
+ isOpen = true ,
22
+ currentStep = MockDataGeneratorStep . AI_DISCLAIMER ,
23
+ } = { } ) {
24
+ function MockDataGeneratorModalWrapper ( ) {
25
+ const [ currentStepStateMock , setCurrentStepStateMock ] =
26
+ React . useState < MockDataGeneratorStep > ( currentStep ) ;
27
+ return (
28
+ < MockDataGeneratorModal
29
+ isOpen = { isOpen }
30
+ setIsOpen = { setIsOpen }
31
+ currentStep = { currentStepStateMock }
32
+ setCurrentStep = { ( step ) => {
33
+ setCurrentStepStateMock ( step ) ;
34
+ } }
35
+ />
36
+ ) ;
37
+ }
38
+ return render ( < MockDataGeneratorModalWrapper /> ) ;
39
+ }
25
40
26
- it ( 'renders the modal when isOpen is true' , function ( ) {
41
+ it ( 'renders the modal when isOpen is true' , ( ) => {
27
42
renderModal ( ) ;
28
43
29
44
expect ( screen . getByTestId ( 'generate-mock-data-modal' ) ) . to . exist ;
30
45
} ) ;
31
46
32
- it ( 'calls setIsOpen(false) when the modal is closed' , function ( ) {
47
+ it ( 'does not render the modal when isOpen is false' , ( ) => {
48
+ renderModal ( { isOpen : false } ) ;
49
+
50
+ expect ( screen . queryByTestId ( 'generate-mock-data-modal' ) ) . to . not . exist ;
51
+ } ) ;
52
+
53
+ it ( 'renders the correct step when currentStep is set' , ( ) => {
54
+ renderModal ( { currentStep : MockDataGeneratorStep . SCHEMA_CONFIRMATION } ) ;
55
+
56
+ expect (
57
+ screen . getByTestId (
58
+ `generate-mock-data-step-${ MockDataGeneratorStep . SCHEMA_CONFIRMATION } `
59
+ )
60
+ ) . to . exist ;
61
+ } ) ;
62
+
63
+ it ( 'calls setIsOpen(false) when the modal is closed' , ( ) => {
33
64
renderModal ( ) ;
34
65
35
66
screen . getByLabelText ( 'Close modal' ) . click ( ) ;
36
67
37
68
expect ( setIsOpen . calledOnceWith ( false ) ) . to . be . true ;
38
69
} ) ;
39
70
40
- it ( 'calls setIsOpen(false) when the cancel button is clicked' , function ( ) {
71
+ it ( 'calls setIsOpen(false) when the cancel button is clicked' , ( ) => {
41
72
renderModal ( ) ;
42
73
43
74
screen . getByText ( 'Cancel' ) . click ( ) ;
44
75
45
76
expect ( setIsOpen . calledOnceWith ( false ) ) . to . be . true ;
46
77
} ) ;
47
78
48
- it ( 'renders the first step by default' , function ( ) {
79
+ it ( 'disables the Back button on the first step' , ( ) => {
80
+ renderModal ( ) ;
81
+
82
+ expect (
83
+ screen . getByRole ( 'button' , { name : 'Back' } ) . getAttribute ( 'aria-disabled' )
84
+ ) . to . equal ( 'true' ) ;
85
+ } ) ;
86
+
87
+ it ( 'renders the next step button with the correct label on each step' , ( ) => {
88
+ renderModal ( ) ;
89
+
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' ) ;
105
+ } ) ;
106
+
107
+ it ( 'renders the first step by default' , ( ) => {
49
108
renderModal ( ) ;
50
109
51
110
expect (
52
111
screen . getByTestId (
53
- `generate-mock-data-step-${ MockDataGeneratorSteps . AI_DISCLAIMER } `
112
+ `generate-mock-data-step-${ MockDataGeneratorStep . AI_DISCLAIMER } `
54
113
)
55
114
) . to . exist ;
56
115
} ) ;
0 commit comments