Skip to content

Commit 3cb7fcf

Browse files
committed
added tests
1 parent 2a4a846 commit 3cb7fcf

File tree

2 files changed

+75
-5
lines changed

2 files changed

+75
-5
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React from 'react';
2+
import { render, screen } from '@mongodb-js/testing-library-compass';
3+
import IndexFlowSection from './index-flow-section';
4+
import { expect } from 'chai';
5+
6+
describe('IndexFlowSection', () => {
7+
const renderComponent = (createIndexFieldsComponent?: JSX.Element) => {
8+
render(
9+
<IndexFlowSection
10+
createIndexFieldsComponent={createIndexFieldsComponent ?? null}
11+
/>
12+
);
13+
};
14+
it('renders the Input Index header', () => {
15+
renderComponent();
16+
expect(screen.getByText('Input Index')).to.exist;
17+
});
18+
19+
it('renders the Code Equivalent toggle', () => {
20+
renderComponent();
21+
expect(screen.getByLabelText('Toggle Code Equivalent')).to.exist;
22+
});
23+
24+
it('renders the Show me covered queries button', () => {
25+
renderComponent();
26+
expect(screen.getByText('Show me covered queries')).to.exist;
27+
});
28+
29+
it('renders the Covered Queries header', () => {
30+
renderComponent();
31+
expect(screen.getByText('Covered Queries')).to.exist;
32+
});
33+
34+
it('renders the provided createIndexFieldsComponent', () => {
35+
const mockComponent = (
36+
<div data-testid="mock-component">Mock Component</div>
37+
);
38+
renderComponent(mockComponent);
39+
expect(screen.getByTestId('mock-component')).to.exist;
40+
});
41+
42+
it('renders the covered queries examples', () => {
43+
renderComponent();
44+
expect(screen.getByTestId('index-flow-section-covered-queries-examples')).to
45+
.exist;
46+
});
47+
48+
it('renders the optimal query examples', () => {
49+
renderComponent();
50+
expect(screen.getByTestId('index-flow-section-optimal-query-examples')).to
51+
.exist;
52+
});
53+
54+
it('renders the Learn More link', () => {
55+
renderComponent();
56+
const link = screen.getByText('Learn More');
57+
expect(link).to.exist;
58+
});
59+
});

packages/compass-indexes/src/components/create-index-form/index-flow-section.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ const infoWithCircleIconStyles = css({
6767
marginLeft: spacing[200],
6868
});
6969

70+
export type IndexFlowSectionProps = {
71+
createIndexFieldsComponent: JSX.Element | null;
72+
};
73+
7074
const IndexFlowSection = ({
7175
createIndexFieldsComponent,
72-
}: {
73-
createIndexFieldsComponent: JSX.Element | null;
74-
}) => {
76+
}: IndexFlowSectionProps) => {
7577
return (
7678
<div>
7779
<div
@@ -130,6 +132,7 @@ const IndexFlowSection = ({
130132
<Icon
131133
glyph="InfoWithCircle"
132134
className={cx(infoWithCircleIconStyles, flexContainerStyles)}
135+
data-testid="index-flow-section-covered-queries-tooltip"
133136
/>
134137
</span>
135138
}
@@ -145,7 +148,11 @@ const IndexFlowSection = ({
145148

146149
<div className={coveredQueriesCalloutStyles}>
147150
{/* Covered Queries, clean up with actual covered queries examples in CLOUDP-311782 */}
148-
<Body baseFontSize={13} className={codeStyles}>
151+
<Body
152+
baseFontSize={13}
153+
className={codeStyles}
154+
data-testid="index-flow-section-covered-queries-examples"
155+
>
149156
{`{ awards.wins:3 }`} <br />
150157
{`{ awards.wins:3, imdb.rating:5 }`} <br />
151158
{`{ awards.wins:3, imdb.rating:5, awards.nominations:8 }`} <br />
@@ -156,7 +163,11 @@ const IndexFlowSection = ({
156163
optimal for queries that have this pattern:
157164
</u>
158165
{/* Optimal queries, clean up with actual optimal queries in CLOUDP-311783 */}
159-
<Body baseFontSize={13} className={codeStyles}>
166+
<Body
167+
baseFontSize={13}
168+
className={codeStyles}
169+
data-testid="index-flow-section-optimal-query-examples"
170+
>
160171
{`{ awards.wins : 5, imdb.rating: {$gt : 5} }.sort({ awards.nominations : 1 }`}
161172
</Body>
162173
</p>

0 commit comments

Comments
 (0)