Skip to content

Commit 7c5ac4b

Browse files
committed
add tests and exclude table view
1 parent 686fd8a commit 7c5ac4b

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ describe('CrudToolbar Component', function () {
7171
onResetClicked={noop}
7272
onUpdateButtonClicked={noop}
7373
onDeleteButtonClicked={noop}
74+
onExpandAllClicked={noop}
75+
onCollapseAllClicked={noop}
7476
openExportFileDialog={noop}
7577
outdated={false}
7678
page={0}
@@ -368,6 +370,51 @@ describe('CrudToolbar Component', function () {
368370
});
369371
});
370372

373+
describe.only('expand controls', function () {
374+
describe('table view', function () {
375+
it('should be disabled', function () {
376+
renderCrudToolbar({
377+
activeDocumentView: 'Table',
378+
});
379+
380+
expect(screen.getByTitle('Expand Controls')).to.have.attribute(
381+
'aria-disabled',
382+
'true'
383+
);
384+
});
385+
});
386+
387+
describe('other views', function () {
388+
it('should provide "Expand all documents"', function () {
389+
const onExpandAllClicked = sinon.spy();
390+
renderCrudToolbar({
391+
activeDocumentView: 'JSON',
392+
onExpandAllClicked,
393+
});
394+
395+
userEvent.click(screen.getByTitle('Expand Controls'));
396+
const expandAllBtn = screen.getByText('Expand all documents');
397+
expect(expandAllBtn).to.be.visible;
398+
userEvent.click(expandAllBtn);
399+
expect(onExpandAllClicked).to.have.been.called;
400+
});
401+
402+
it('should provide "Collapse all documents"', function () {
403+
const onCollapseAllClicked = sinon.spy();
404+
renderCrudToolbar({
405+
activeDocumentView: 'JSON',
406+
onCollapseAllClicked,
407+
});
408+
409+
userEvent.click(screen.getByTitle('Expand Controls'));
410+
const collapseAllBtn = screen.getByText('Collapse all documents');
411+
expect(collapseAllBtn).to.be.visible;
412+
userEvent.click(collapseAllBtn);
413+
expect(onCollapseAllClicked).to.have.been.called;
414+
});
415+
});
416+
});
417+
371418
it('should not render the outdated message', function () {
372419
renderCrudToolbar();
373420

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ const CrudToolbar: React.FunctionComponent<CrudToolbarProps> = ({
302302
<ExpandControl
303303
onExpandAll={onExpandAllClicked}
304304
onCollapseAll={onCollapseAllClicked}
305+
activeView={activeDocumentView}
305306
/>
306307

307308
<ViewSwitcher

packages/compass-crud/src/components/expand-control.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { Button, Icon, Menu, MenuItem } from '@mongodb-js/compass-components';
22
import React from 'react';
3+
import { type DocumentView } from '../stores/crud-store';
34

45
interface ExpandControlProps {
6+
activeView: DocumentView;
57
onExpandAll: () => void;
68
onCollapseAll: () => void;
79
}
810

911
const ExpandControl: React.FunctionComponent<ExpandControlProps> = ({
12+
activeView,
1013
onExpandAll,
1114
onCollapseAll,
1215
}) => {
@@ -17,6 +20,7 @@ const ExpandControl: React.FunctionComponent<ExpandControlProps> = ({
1720
size="xsmall"
1821
aria-label="Expand Controls"
1922
title="Expand Controls"
23+
disabled={activeView === 'Table'}
2024
>
2125
<Icon glyph="CaretDown" />
2226
</Button>

0 commit comments

Comments
 (0)