Skip to content

Commit 8f8b7b2

Browse files
committed
update tests and export
1 parent 3f634a6 commit 8f8b7b2

File tree

4 files changed

+61
-97
lines changed

4 files changed

+61
-97
lines changed

packages/compass-schema-validation/src/components/document-preview.spec.tsx

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,14 @@ import { expect } from 'chai';
55
import { DocumentPreview } from './document-preview';
66

77
describe('DocumentPreview [Component]', function () {
8-
context('when document loading state is initial', function () {
9-
it('renders a button to load a sample document', function () {
10-
const component = mount(<DocumentPreview loadingState="initial" />);
11-
expect(component.find('[data-testid="load-sample-document"]')).to.exist;
12-
});
13-
});
14-
15-
context('when document loading state is loading', function () {
16-
it('renders a spinner', function () {
17-
const component = mount(<DocumentPreview loadingState="loading" />);
18-
expect(component.find('[data-testid="load-sample-spinner"]')).to.exist;
19-
});
20-
});
21-
228
context('when document loading state is success', function () {
239
it('renders a document if there is one present', function () {
24-
const component = mount(
25-
<DocumentPreview loadingState="success" document={{}} />
26-
);
10+
const component = mount(<DocumentPreview document={{}} />);
2711
expect(component.find('HadronDocument')).to.exist;
2812
});
2913

3014
it('renders a no preview text when there is no document', function () {
31-
const component = mount(<DocumentPreview loadingState="success" />);
32-
expect(component).to.have.text('No Preview Documents');
33-
});
34-
});
35-
36-
context('when document loading state is error', function () {
37-
it('renders a no preview text', function () {
38-
const component = mount(<DocumentPreview loadingState="error" />);
15+
const component = mount(<DocumentPreview />);
3916
expect(component).to.have.text('No Preview Documents');
4017
});
4118
});

packages/compass-schema-validation/src/modules/sample-documents.spec.ts

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@ import reducer, {
44
INITIAL_STATE,
55
CLEAR_SAMPLE_DOCUMENTS,
66
clearSampleDocuments,
7-
fetchingValidDocument,
8-
FETCHING_VALID_DOCUMENT,
97
fetchedValidDocument,
108
FETCHED_VALID_DOCUMENT,
11-
fetchingInvalidDocument,
12-
FETCHING_INVALID_DOCUMENT,
139
fetchedInvalidDocument,
1410
FETCHED_INVALID_DOCUMENT,
1511
fetchingValidDocumentFailed,
1612
FETCHING_INVALID_DOCUMENT_FAILED,
1713
fetchingInvalidDocumentFailed,
1814
FETCHING_VALID_DOCUMENT_FAILED,
15+
fetchingSampleDocuments,
16+
FETCHING_SAMPLE_DOCUMENTS,
17+
type SampleDocumentState,
1918
} from './sample-documents';
2019

2120
const SAMPLE_DOCUMENT = {
@@ -31,14 +30,8 @@ describe('sample-documents module', function () {
3130
});
3231

3332
it('returns the FETCHING_VALID_DOCUMENT action', function () {
34-
expect(fetchingValidDocument()).to.deep.equal({
35-
type: FETCHING_VALID_DOCUMENT,
36-
});
37-
});
38-
39-
it('returns the FETCHING_INVALID_DOCUMENT action', function () {
40-
expect(fetchingInvalidDocument()).to.deep.equal({
41-
type: FETCHING_INVALID_DOCUMENT,
33+
expect(fetchingSampleDocuments()).to.deep.equal({
34+
type: FETCHING_SAMPLE_DOCUMENTS,
4235
});
4336
});
4437

@@ -93,66 +86,72 @@ describe('sample-documents module', function () {
9386
});
9487
});
9588

96-
context('when the action is FETCHING_VALID_DOCUMENT', function () {
89+
context('when the action is FETCHING_SAMPLE_DOCUMENTS', function () {
9790
it('returns a loading state', function () {
98-
const sampleDocuments = reducer(undefined, fetchingValidDocument());
91+
const sampleDocuments = reducer(undefined, fetchingSampleDocuments());
9992
expect(sampleDocuments.validDocumentState).to.equal('loading');
93+
expect(sampleDocuments.invalidDocumentState).to.equal('loading');
10094
});
10195
});
10296

103-
context('when the action is FETCHING_INVALID_DOCUMENT', function () {
104-
it('returns a loading state', function () {
105-
const sampleDocuments = reducer(undefined, fetchingInvalidDocument());
106-
expect(sampleDocuments.invalidDocumentState).to.equal('loading');
97+
context('fetch results', function () {
98+
let loadingState: SampleDocumentState;
99+
beforeEach(function () {
100+
loadingState = reducer(undefined, fetchingSampleDocuments());
107101
});
108-
});
109102

110-
context('when the action is FETCHED_VALID_DOCUMENT', function () {
111-
it('updates the state with the document', function () {
112-
for (const document of [null, undefined, SAMPLE_DOCUMENT] as any[]) {
113-
const sampleDocuments = reducer(
114-
undefined,
115-
fetchedValidDocument(document)
116-
);
117-
expect(sampleDocuments.validDocumentState).to.equal('success');
118-
expect(sampleDocuments.validDocument).to.deep.equal(document);
119-
}
103+
context('when the action is FETCHED_VALID_DOCUMENT', function () {
104+
it('updates the state with the document', function () {
105+
for (const document of [null, undefined, SAMPLE_DOCUMENT] as any[]) {
106+
const sampleDocuments = reducer(
107+
loadingState,
108+
fetchedValidDocument(document)
109+
);
110+
expect(sampleDocuments.validDocumentState).to.equal('success');
111+
expect(sampleDocuments.validDocument).to.deep.equal(document);
112+
expect(sampleDocuments.invalidDocumentState).to.equal('loading');
113+
}
114+
});
120115
});
121-
});
122116

123-
context('when the action is FETCHED_INVALID_DOCUMENT', function () {
124-
it('updates the state with the document', function () {
117+
context('when the action is FETCHED_INVALID_DOCUMENT', function () {
125118
for (const document of [null, undefined, SAMPLE_DOCUMENT] as any[]) {
126119
const sampleDocuments = reducer(
127-
undefined,
120+
loadingState,
128121
fetchedInvalidDocument(document)
129122
);
130123
expect(sampleDocuments.invalidDocumentState).to.equal('success');
131124
expect(sampleDocuments.invalidDocument).to.deep.equal(document);
125+
expect(sampleDocuments.validDocumentState).to.equal('loading');
132126
}
133127
});
134-
});
135128

136-
context('when the action is FETCHING_VALID_DOCUMENT_FAILED', function () {
137-
it('updates an error state', function () {
138-
const sampleDocuments = reducer(
139-
undefined,
140-
fetchingValidDocumentFailed()
141-
);
142-
expect(sampleDocuments.validDocumentState).to.equal('error');
143-
expect(sampleDocuments.validDocument).to.equal(undefined);
129+
context('when the action is FETCHING_VALID_DOCUMENT_FAILED', function () {
130+
it('updates an error state', function () {
131+
const sampleDocuments = reducer(
132+
loadingState,
133+
fetchingValidDocumentFailed()
134+
);
135+
expect(sampleDocuments.validDocumentState).to.equal('error');
136+
expect(sampleDocuments.validDocument).to.equal(undefined);
137+
expect(sampleDocuments.invalidDocumentState).to.equal('loading');
138+
});
144139
});
145-
});
146140

147-
context('when the action is FETCHING_INVALID_DOCUMENT_FAILED', function () {
148-
it('updates an error state', function () {
149-
const sampleDocuments = reducer(
150-
undefined,
151-
fetchingInvalidDocumentFailed()
152-
);
153-
expect(sampleDocuments.invalidDocumentState).to.equal('error');
154-
expect(sampleDocuments.invalidDocument).to.deep.equal(undefined);
155-
});
141+
context(
142+
'when the action is FETCHING_INVALID_DOCUMENT_FAILED',
143+
function () {
144+
it('updates an error state', function () {
145+
const sampleDocuments = reducer(
146+
loadingState,
147+
fetchingInvalidDocumentFailed()
148+
);
149+
expect(sampleDocuments.invalidDocumentState).to.equal('error');
150+
expect(sampleDocuments.invalidDocument).to.deep.equal(undefined);
151+
expect(sampleDocuments.validDocumentState).to.equal('loading');
152+
});
153+
}
154+
);
156155
});
157156
});
158157
});

packages/compass-schema-validation/src/modules/sample-documents.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,17 @@ interface FetchingInvalidDocumentFailedAction {
7474
type: typeof FETCHING_INVALID_DOCUMENT_FAILED;
7575
}
7676

77-
export type SampleDocumentNonInitialAction =
77+
type SampleDocumentNonInitialAction =
7878
| ClearSampleDocumentsAction
7979
| FetchedValidDocumentAction
8080
| FetchedInvalidDocumentAction
8181
| FetchingInvalidDocumentFailedAction
8282
| FetchingValidDocumentFailedAction;
8383

84+
export type SampleDocumentAction =
85+
| SampleDocumentNonInitialAction
86+
| FetchingSampleDocumentsAction;
87+
8488
/**
8589
* Action creators
8690
*/

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import {
99
validationActionChanged,
1010
validationLevelChanged,
1111
} from '../modules/validation';
12-
import {
13-
fetchValidDocument,
14-
fetchInvalidDocument,
15-
} from '../modules/sample-documents';
12+
import { fetchSampleDocuments } from '../modules/sample-documents';
1613
import { stringify as javascriptStringify } from 'javascript-stringify';
1714
import type { Store } from 'redux';
1815
import type { RootAction, RootState } from '../modules';
@@ -157,7 +154,7 @@ describe('Schema Validation Store', function () {
157154
});
158155
});
159156

160-
context('when the action is fetch valid sample documents', function () {
157+
context('when the action is fetch sample documents', function () {
161158
it('updates the sample document loading in state', function (done) {
162159
expect(store.getState().sampleDocuments.validDocumentState).to.equal(
163160
'initial'
@@ -167,25 +164,12 @@ describe('Schema Validation Store', function () {
167164
expect(store.getState().sampleDocuments.validDocumentState).to.equal(
168165
'loading'
169166
);
170-
done();
171-
});
172-
store.dispatch(fetchValidDocument() as any);
173-
});
174-
});
175-
176-
context('when the action is fetch invalid sample documents', function () {
177-
it('updates the sample document loading in state', function (done) {
178-
expect(store.getState().sampleDocuments.invalidDocumentState).to.equal(
179-
'initial'
180-
);
181-
const unsubscribe = store.subscribe(() => {
182-
unsubscribe();
183167
expect(
184168
store.getState().sampleDocuments.invalidDocumentState
185169
).to.equal('loading');
186170
done();
187171
});
188-
store.dispatch(fetchInvalidDocument() as any);
172+
store.dispatch(fetchSampleDocuments() as any);
189173
});
190174
});
191175

0 commit comments

Comments
 (0)