@@ -2,6 +2,7 @@ import { activateSchemaPlugin } from './store';
22import type { SchemaStore , SchemaPluginServices } from './store' ;
33import AppRegistry , { createActivateHelpers } from 'hadron-app-registry' ;
44import { expect } from 'chai' ;
5+ import { waitFor } from '@mongodb-js/testing-library-compass' ;
56
67import { ANALYSIS_STATE_INITIAL } from '../constants/analysis-states' ;
78import { createSandboxFromDefaultPreferences } from 'compass-preferences-model' ;
@@ -10,7 +11,10 @@ import type { FieldStoreService } from '@mongodb-js/compass-field-store';
1011import { createNoopTrack } from '@mongodb-js/compass-telemetry/provider' ;
1112import { startAnalysis , stopAnalysis } from './schema-analysis-reducer' ;
1213import Sinon from 'sinon' ;
13- import { changeExportSchemaFormat } from './schema-export-reducer' ;
14+ import {
15+ changeExportSchemaFormat ,
16+ openExportSchema ,
17+ } from './schema-export-reducer' ;
1418
1519const dummyLogger = createNoopLogger ( 'TEST' ) ;
1620const dummyTrack = createNoopTrack ( ) ;
@@ -135,10 +139,18 @@ describe('Schema Store', function () {
135139 await store . dispatch ( startAnalysis ( ) ) ;
136140 } ) ;
137141
138- it ( 'runs schema export formatting with the analyzed schema' , async function ( ) {
142+ it ( 'runs schema export formatting with the analyzed schema when opened ' , async function ( ) {
139143 sampleStub . resolves ( [ { name : 'Hans' } , { name : 'Greta' } ] ) ;
140- await store . dispatch ( changeExportSchemaFormat ( 'standardJSON' ) ) ;
141144 expect ( sampleStub ) . to . have . been . called ;
145+ expect ( store . getState ( ) . schemaExport . exportStatus ) . to . equal (
146+ 'inprogress'
147+ ) ;
148+ store . dispatch ( openExportSchema ( ) ) ;
149+ await waitFor ( ( ) => {
150+ expect ( store . getState ( ) . schemaExport . exportStatus ) . to . equal (
151+ 'complete'
152+ ) ;
153+ } ) ;
142154 const { exportStatus, errorMessage, exportedSchema } =
143155 store . getState ( ) . schemaExport ;
144156 expect ( exportStatus ) . to . equal ( 'complete' ) ;
@@ -153,6 +165,24 @@ describe('Schema Store', function () {
153165 name : { type : 'string' } ,
154166 } ) ;
155167 } ) ;
168+
169+ it ( 'runs schema export formatting with a new format' , async function ( ) {
170+ sampleStub . resolves ( [ { name : 'Hans' } , { name : 'Greta' } ] ) ;
171+ await store . dispatch ( changeExportSchemaFormat ( 'mongoDBJSON' ) ) ;
172+ expect ( sampleStub ) . to . have . been . called ;
173+ const { exportStatus, errorMessage, exportedSchema } =
174+ store . getState ( ) . schemaExport ;
175+ expect ( exportStatus ) . to . equal ( 'complete' ) ;
176+ expect ( ! ! errorMessage ) . to . be . false ;
177+ expect ( exportedSchema ) . not . to . be . undefined ;
178+ expect ( JSON . parse ( exportedSchema ! ) . type ) . to . equal ( undefined ) ;
179+ expect ( JSON . parse ( exportedSchema ! ) . bsonType ) . to . equal ( 'object' ) ;
180+ expect ( JSON . parse ( exportedSchema ! ) [ '$schema' ] ) . to . equal ( undefined ) ;
181+ expect ( JSON . parse ( exportedSchema ! ) . required ) . to . deep . equal ( [ 'name' ] ) ;
182+ expect ( JSON . parse ( exportedSchema ! ) . properties ) . to . deep . equal ( {
183+ name : { bsonType : 'string' } ,
184+ } ) ;
185+ } ) ;
156186 } ) ;
157187 } ) ;
158188
0 commit comments