Skip to content

Commit ffad7a7

Browse files
committed
fixup: remove legacy format from modal, add test for change export format and default
1 parent f085652 commit ffad7a7

File tree

3 files changed

+37
-23
lines changed

3 files changed

+37
-23
lines changed

packages/compass-schema/src/components/export-schema-modal.tsx

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { type ChangeEvent, useCallback } from 'react';
22
import { connect } from 'react-redux';
33
import {
4-
Banner,
54
Button,
65
Code,
76
ModalBody,
@@ -30,10 +29,6 @@ const loaderStyles = css({
3029
marginTop: spacing[400],
3130
});
3231

33-
const legacyWarningStyles = css({
34-
marginTop: spacing[200],
35-
});
36-
3732
const contentContainerStyles = css({
3833
paddingTop: spacing[400],
3934
paddingBottom: spacing[400],
@@ -135,20 +130,6 @@ const ExportSchemaModal: React.FunctionComponent<{
135130
);
136131
})}
137132
</RadioBoxGroup>
138-
{exportFormat === 'legacyJSON' && (
139-
<Banner
140-
className={legacyWarningStyles}
141-
variant="warning"
142-
data-testid="legacy-export-json-warning"
143-
>
144-
<strong>
145-
The JSON Extended format is deprecated and will be removed in a
146-
future release.
147-
</strong>
148-
&nbsp;We&apos;re transitioning to a better format. Discover the new
149-
experience by selecting a relevant format from above.
150-
</Banner>
151-
)}
152133
<div className={contentContainerStyles}>
153134
{exportStatus === 'inprogress' && (
154135
<CancelLoader

packages/compass-schema/src/modules/schema-analysis.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,10 @@ describe('schema-analysis', function () {
160160
count: 2,
161161
};
162162

163-
const internalSchema = await schema!.getInternalSchema();
163+
if (!schema) {
164+
throw new Error('schema is nul');
165+
}
166+
const internalSchema = await schema.getInternalSchema();
164167
internalSchema.fields = internalSchema.fields.filter(
165168
({ path }) => !isInternalFieldPath(path[0])
166169
);

packages/compass-schema/src/stores/store.spec.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { activateSchemaPlugin } from './store';
22
import type { SchemaStore, SchemaPluginServices } from './store';
33
import AppRegistry, { createActivateHelpers } from 'hadron-app-registry';
44
import { expect } from 'chai';
5+
import { waitFor } from '@mongodb-js/testing-library-compass';
56

67
import { ANALYSIS_STATE_INITIAL } from '../constants/analysis-states';
78
import { createSandboxFromDefaultPreferences } from 'compass-preferences-model';
@@ -10,7 +11,10 @@ import type { FieldStoreService } from '@mongodb-js/compass-field-store';
1011
import { createNoopTrack } from '@mongodb-js/compass-telemetry/provider';
1112
import { startAnalysis, stopAnalysis } from './schema-analysis-reducer';
1213
import Sinon from 'sinon';
13-
import { changeExportSchemaFormat } from './schema-export-reducer';
14+
import {
15+
changeExportSchemaFormat,
16+
openExportSchema,
17+
} from './schema-export-reducer';
1418

1519
const dummyLogger = createNoopLogger('TEST');
1620
const 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

Comments
 (0)