Skip to content

Commit d0e460d

Browse files
committed
update tests
1 parent 010de5a commit d0e460d

File tree

3 files changed

+45
-16
lines changed

3 files changed

+45
-16
lines changed
Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,46 @@
11
import React from 'react';
2-
import { mount } from 'enzyme';
2+
import { render, screen } from '@mongodb-js/testing-library-compass';
33
import { expect } from 'chai';
44
import { SampleDocuments } from './sample-documents';
55
import { Provider } from 'react-redux';
66
import { configureStore } from '../stores/store';
7+
import { INITIAL_STATE } from '../modules';
78

89
describe('SampleDocuments [Component]', function () {
9-
it('renders a valid and invalid document preview', function () {
10+
it('initial state : renders the CTA', function () {
1011
const store = configureStore({}, {} as any);
11-
const component = mount(
12+
render(
1213
<Provider store={store}>
1314
<SampleDocuments />
1415
</Provider>
1516
);
1617

17-
expect(component.find('[data-testid="matching-documents"]')).to.exist;
18-
expect(component.find('[data-testid="notmatching-documents"]')).to.exist;
18+
expect(screen.getByRole('button', { name: 'Preview documents' })).to.be
19+
.visible;
20+
});
21+
22+
it('non initial state : renders a valid and invalid document preview', function () {
23+
const store = configureStore(
24+
{
25+
...INITIAL_STATE,
26+
sampleDocuments: {
27+
validDocumentState: 'loading',
28+
invalidDocumentState: 'loading',
29+
validDocument: undefined,
30+
invalidDocument: undefined,
31+
},
32+
},
33+
{} as any
34+
);
35+
render(
36+
<Provider store={store}>
37+
<SampleDocuments />
38+
</Provider>
39+
);
40+
41+
expect(screen.queryByRole('button', { name: 'Preview documents' })).not.to
42+
.exist;
43+
expect(screen.getByTestId('matching-documents')).to.be.visible;
44+
expect(screen.getByTestId('notmatching-documents')).to.be.visible;
1945
});
2046
});

packages/compass-schema-validation/src/components/sample-documents.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const sampleDocumentsSectionStyles = css({
2727
flexDirection: 'column',
2828
gap: spacing[200],
2929
border: `1px solid ${palette.gray.light2}`,
30-
borderRadius: spacing[400],
30+
borderRadius: spacing[200],
3131
padding: spacing[400],
3232
});
3333

@@ -77,8 +77,9 @@ const initialStateContainerStyles = css({
7777
display: 'flex',
7878
flexDirection: 'column',
7979
alignItems: 'center',
80+
justifyContent: 'center',
81+
height: '228px', // using the same space as the previews
8082
gap: spacing[300],
81-
marginTop: spacing[400],
8283
});
8384

8485
const previewHeaderStyles = css({

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,17 @@ describe('sample-documents module', function () {
115115
});
116116

117117
context('when the action is FETCHED_INVALID_DOCUMENT', function () {
118-
for (const document of [null, undefined, SAMPLE_DOCUMENT] as any[]) {
119-
const sampleDocuments = reducer(
120-
loadingState,
121-
fetchedInvalidDocument(document)
122-
);
123-
expect(sampleDocuments.invalidDocumentState).to.equal('success');
124-
expect(sampleDocuments.invalidDocument).to.deep.equal(document);
125-
expect(sampleDocuments.validDocumentState).to.equal('loading');
126-
}
118+
it('updates the invalid document state', function () {
119+
for (const document of [null, undefined, SAMPLE_DOCUMENT] as any[]) {
120+
const sampleDocuments = reducer(
121+
loadingState,
122+
fetchedInvalidDocument(document)
123+
);
124+
expect(sampleDocuments.invalidDocumentState).to.equal('success');
125+
expect(sampleDocuments.invalidDocument).to.deep.equal(document);
126+
expect(sampleDocuments.validDocumentState).to.equal('loading');
127+
}
128+
});
127129
});
128130

129131
context('when the action is FETCHING_VALID_DOCUMENT_FAILED', function () {

0 commit comments

Comments
 (0)