Skip to content

Commit 2f900ab

Browse files
committed
fix: add tests
1 parent f0b6cf8 commit 2f900ab

File tree

4 files changed

+61
-52
lines changed

4 files changed

+61
-52
lines changed

configs/testing-library-compass/src/index.tsx

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ import {
4545
ReadOnlyPreferenceAccess,
4646
} from 'compass-preferences-model/provider';
4747
import { TelemetryProvider } from '@mongodb-js/compass-telemetry/provider';
48-
import {
49-
CompassComponentsProvider,
50-
ContextMenuProvider,
51-
} from '@mongodb-js/compass-components';
48+
import { CompassComponentsProvider } from '@mongodb-js/compass-components';
5249
import {
5350
TestEnvCurrentConnectionContext,
5451
ConnectionInfoProvider,
@@ -352,43 +349,41 @@ function createWrapper(
352349
<PreferencesProvider value={wrapperState.preferences}>
353350
<LoggerProvider value={logger}>
354351
<TelemetryProvider options={telemetryOptions}>
355-
<ContextMenuProvider>
356-
<ConnectionStorageProvider
357-
value={wrapperState.connectionStorage}
358-
>
359-
<ConnectFnProvider connect={wrapperState.connect}>
360-
<CompassConnections
361-
appName={options.appName ?? 'TEST'}
362-
onFailToLoadConnections={
363-
options.onFailToLoadConnections ??
364-
(() => {
365-
// noop
366-
})
367-
}
368-
onExtraConnectionDataRequest={
369-
options.onExtraConnectionDataRequest ??
370-
(() => {
371-
return Promise.resolve([{}, null] as [any, null]);
372-
})
373-
}
374-
onAutoconnectInfoRequest={
375-
options.onAutoconnectInfoRequest
376-
}
377-
preloadStorageConnectionInfos={connections}
378-
>
379-
<StoreGetter>
380-
<TestEnvCurrentConnectionContext.Provider
381-
value={TEST_ENV_CURRENT_CONNECTION}
382-
>
383-
<TestingLibraryWrapper {...props}>
384-
{children}
385-
</TestingLibraryWrapper>
386-
</TestEnvCurrentConnectionContext.Provider>
387-
</StoreGetter>
388-
</CompassConnections>
389-
</ConnectFnProvider>
390-
</ConnectionStorageProvider>
391-
</ContextMenuProvider>
352+
<ConnectionStorageProvider
353+
value={wrapperState.connectionStorage}
354+
>
355+
<ConnectFnProvider connect={wrapperState.connect}>
356+
<CompassConnections
357+
appName={options.appName ?? 'TEST'}
358+
onFailToLoadConnections={
359+
options.onFailToLoadConnections ??
360+
(() => {
361+
// noop
362+
})
363+
}
364+
onExtraConnectionDataRequest={
365+
options.onExtraConnectionDataRequest ??
366+
(() => {
367+
return Promise.resolve([{}, null] as [any, null]);
368+
})
369+
}
370+
onAutoconnectInfoRequest={
371+
options.onAutoconnectInfoRequest
372+
}
373+
preloadStorageConnectionInfos={connections}
374+
>
375+
<StoreGetter>
376+
<TestEnvCurrentConnectionContext.Provider
377+
value={TEST_ENV_CURRENT_CONNECTION}
378+
>
379+
<TestingLibraryWrapper {...props}>
380+
{children}
381+
</TestingLibraryWrapper>
382+
</TestEnvCurrentConnectionContext.Provider>
383+
</StoreGetter>
384+
</CompassConnections>
385+
</ConnectFnProvider>
386+
</ConnectionStorageProvider>
392387
</TelemetryProvider>
393388
</LoggerProvider>
394389
</PreferencesProvider>

packages/compass-components/src/components/context-menu.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export function ContextMenu({ menu }: ContextMenuWrapperProps) {
4949
}
5050
}}
5151
justify="start"
52-
data-testid="context-menu"
5352
>
5453
{itemGroups.map(
5554
(itemGroup: ContextMenuItemGroup, groupIndex: number) => {

packages/compass-crud/src/components/crud-toolbar.spec.tsx

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -527,19 +527,19 @@ describe('CrudToolbar Component', function () {
527527
await preferences.savePreferences({ enableImportExport: true });
528528
});
529529

530-
it('should open context menu on right click', async function () {
530+
it('should open context menu on right click', function () {
531531
renderCrudToolbar();
532532

533533
const toolbar = screen.getByTestId('query-bar').closest('div');
534-
await userEvent.pointer({ target: toolbar!, keys: '[MouseRight]' });
534+
userEvent.click(toolbar!, { button: 2 });
535535

536536
const contextMenu = screen.getByTestId('context-menu');
537537
expect(within(contextMenu).getByText('Expand all documents')).to.be
538538
.visible;
539539
expect(within(contextMenu).getByText('Refresh')).to.be.visible;
540540
});
541541

542-
it('should call onExpandAllClicked when "Expand all documents" is clicked', async function () {
542+
it('should call onExpandAllClicked when "Expand all documents" is clicked', function () {
543543
const onExpandAllClicked = sinon.spy();
544544
renderCrudToolbar({ onExpandAllClicked });
545545

@@ -555,20 +555,36 @@ describe('CrudToolbar Component', function () {
555555
expect(onExpandAllClicked).to.have.been.calledOnce;
556556
});
557557

558-
it('should call onCollapseAllClicked when "Collapse all documents" is clicked', function () {
559-
const onCollapseAllClicked = sinon.spy();
560-
renderCrudToolbar({ onCollapseAllClicked });
558+
it('should show collapse all documents if all documents were previously expanded', function () {
559+
renderCrudToolbar();
561560

562-
const toolbar = screen.getByTestId('query-bar').closest('div');
563-
userEvent.click(toolbar!, { button: 2 });
561+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
562+
const toolbar = screen.getByTestId('query-bar').closest('div')!;
563+
userEvent.click(toolbar, { button: 2 });
564564

565565
const contextMenu = screen.getByTestId('context-menu');
566+
567+
// No Collapse all documents should be shown
568+
expect(within(contextMenu).queryByText('Collapse all documents')).to.not
569+
.exist;
570+
571+
// Click expand all documents
572+
const expandMenuItem = within(contextMenu).getByText(
573+
'Expand all documents'
574+
);
575+
userEvent.click(expandMenuItem);
576+
577+
// Right click again to open the context menu
578+
userEvent.click(toolbar, { button: 2 });
579+
580+
// Now it should show collapse all documents
566581
const collapseMenuItem = within(contextMenu).getByText(
567582
'Collapse all documents'
568583
);
569584
userEvent.click(collapseMenuItem);
570585

571-
expect(onCollapseAllClicked).to.have.been.calledOnce;
586+
expect(within(contextMenu).getByText('Collapse all documents')).to.be
587+
.visible;
572588
});
573589

574590
it('should call insertDataHandler with "import-file" when "Import JSON or CSV file" is clicked', function () {

packages/compass-crud/src/components/crud-toolbar.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import UpdateMenu from './update-data-menu';
2424
import DeleteMenu from './delete-data-menu';
2525
import { QueryBar } from '@mongodb-js/compass-query-bar';
2626
import { useConnectionInfoRef } from '@mongodb-js/compass-connections/provider';
27-
import { ContextMenuProvider } from '@mongodb-js/compass-components';
2827

2928
const crudQueryBarStyles = css({
3029
width: '100%',

0 commit comments

Comments
 (0)