@@ -2,35 +2,82 @@ import React from 'react';
22import { render , screen } from '@mongodb-js/testing-library-compass' ;
33import QueryFlowSection from './query-flow-section' ;
44import { expect } from 'chai' ;
5+ import { Provider } from 'react-redux' ;
6+ import { setupStore } from '../../../test/setup-store' ;
7+ import { ActionTypes } from '../../modules/create-index' ;
58
69describe ( 'QueryFlowSection' , ( ) => {
10+ let store ;
711 const renderComponent = ( ) => {
12+ store = setupStore ( ) ;
13+
814 render (
9- < QueryFlowSection
10- schemaFields = { [ ] }
11- serverVersion = "5.0.0"
12- dbName = { 'fakeDBName' }
13- collectionName = { 'fakeCollectionName' }
14- />
15+ < Provider store = { store } >
16+ < QueryFlowSection
17+ schemaFields = { [ ] }
18+ serverVersion = "5.0.0"
19+ dbName = { 'fakeDBName' }
20+ collectionName = { 'fakeCollectionName' }
21+ />
22+ </ Provider >
1523 ) ;
1624 } ;
17- it ( 'renders the input query section with a code editor' , ( ) => {
18- renderComponent ( ) ;
19- const codeEditor = screen . getByTestId ( 'query-flow-section-code-editor' ) ;
20- expect ( codeEditor ) . to . be . visible ;
25+
26+ describe ( 'in the initial state' , ( ) => {
27+ beforeEach ( ( ) => {
28+ renderComponent ( ) ;
29+ } ) ;
30+ it ( 'renders the input query section with a code editor' , ( ) => {
31+ const codeEditor = screen . getByTestId ( 'query-flow-section-code-editor' ) ;
32+ expect ( codeEditor ) . to . be . visible ;
33+ } ) ;
34+
35+ it ( 'renders the "Show suggested index" button' , ( ) => {
36+ const buttonElement = screen . getByText ( 'Show suggested index' ) ;
37+ expect ( buttonElement ) . to . be . visible ;
38+ } ) ;
39+ it ( 'does not render the suggested index section with formatted index code' , ( ) => {
40+ const codeElement = screen . queryByTestId (
41+ 'query-flow-section-suggested-index'
42+ ) ;
43+ expect ( codeElement ) . to . be . null ;
44+ } ) ;
2145 } ) ;
2246
23- it ( 'renders the "Show suggested index" button' , ( ) => {
24- renderComponent ( ) ;
25- const buttonElement = screen . getByText ( 'Show suggested index' ) ;
26- expect ( buttonElement ) . to . be . visible ;
47+ describe ( 'when fetching for index suggestions' , ( ) => {
48+ beforeEach ( ( ) => {
49+ renderComponent ( ) ;
50+
51+ store . dispatch ( {
52+ type : ActionTypes . SuggestedIndexesRequested ,
53+ } ) ;
54+ } ) ;
55+ it ( 'renders the suggested index section with formatted index code' , ( ) => {
56+ const loader = screen . getByTestId ( 'query-flow-section-code-loader' ) ;
57+ expect ( loader ) . to . be . visible ;
58+ } ) ;
2759 } ) ;
2860
29- it ( 'renders the suggested index section with formatted index code' , ( ) => {
30- renderComponent ( ) ;
31- const codeElement = screen . getByTestId (
32- 'query-flow-section-suggested-index'
33- ) ;
34- expect ( codeElement ) . to . be . visible ;
61+ describe ( 'when index suggestions is fetched' , ( ) => {
62+ beforeEach ( async ( ) => {
63+ renderComponent ( ) ;
64+
65+ await store . dispatch ( {
66+ type : ActionTypes . SuggestedIndexesFetched ,
67+ sampleDocs : [ ] ,
68+ indexSuggestions : { a : 1 , b : 2 } ,
69+ fetchingSuggestionsError : null ,
70+ indexSuggestionsState : 'success' ,
71+ } ) ;
72+ } ) ;
73+
74+ it ( 'renders the suggested index section with formatted index code' , ( ) => {
75+ const codeElement = screen . getByTestId (
76+ 'query-flow-section-suggested-index'
77+ ) ;
78+ expect ( codeElement ) . to . be . visible ;
79+
80+ // TODO: create tests to see that db name, collection name, and queries show up
81+ } ) ;
3582 } ) ;
3683} ) ;
0 commit comments