Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
297a943
feat(compass-context-menu): add a headless context menu package
gagik May 20, 2025
6838513
wip
gagik May 21, 2025
8e30a83
fix: add tests
gagik May 21, 2025
7d17984
fix: add tests and fix types
gagik May 21, 2025
6004593
refactor: minor stylistic changes
gagik May 21, 2025
43023f4
fix: export types and rename MenuItem
gagik May 22, 2025
971b0fd
fix: basic UI implementation
gagik May 22, 2025
0ad7a63
fix: use React.RefCallback
gagik May 22, 2025
aa9f0cf
fix: switch to item-based organization
gagik May 23, 2025
58df56a
fix: cleanup and switch to menu prop
gagik May 23, 2025
a54c738
refactor: use item groups instead of React elements, use wrapper, kee…
gagik May 23, 2025
731ac13
Merge branch 'gagik/headless-context-menu' of github.com:mongodb-js/c…
gagik May 23, 2025
56d11b6
fix: revert test environment
gagik May 23, 2025
743f068
fix: justify start to make it prefer right way popups and remove comment
gagik May 23, 2025
ab14b78
fix: remove redundant context import
gagik May 23, 2025
1d279ca
feat(compass-context-menu): add a headless context menu package
gagik May 20, 2025
1efdb2e
wip
gagik May 21, 2025
0f5303b
fix: add tests
gagik May 21, 2025
33b2a41
fix: add tests and fix types
gagik May 21, 2025
4a2f032
refactor: minor stylistic changes
gagik May 21, 2025
8e1feb3
fix: export types and rename MenuItem
gagik May 22, 2025
1f55000
fix: use React.RefCallback
gagik May 22, 2025
9618e8e
refactor: use item groups instead of React elements, use wrapper, kee…
gagik May 23, 2025
ca1fb86
fix: delete redundant context menu
gagik May 23, 2025
a285d63
Merge branch 'gagik/headless-context-menu' of github.com:mongodb-js/c…
gagik May 23, 2025
aacdf1d
feat(compass-context-menu): add a headless context menu package
gagik May 20, 2025
cb99706
wip
gagik May 21, 2025
da22b51
fix: add tests
gagik May 21, 2025
78ff94c
fix: add tests and fix types
gagik May 21, 2025
a24e89c
refactor: minor stylistic changes
gagik May 21, 2025
f3869ea
fix: export types and rename MenuItem
gagik May 22, 2025
c2d9ac1
fix: use React.RefCallback
gagik May 22, 2025
1c6ef03
refactor: use item groups instead of React elements, use wrapper, kee…
gagik May 23, 2025
3d14d6d
fix: delete redundant context menu
gagik May 23, 2025
ee658e1
fix: remove unused dep
gagik Jun 2, 2025
a173aae
Merge branch 'gagik/headless-context-menu' of github.com:mongodb-js/c…
gagik Jun 2, 2025
59d82d6
test: compas crud
gagik Jun 6, 2025
1ad46a7
fix: enforce no nesting, adjsut enzyme test and move setup to testing…
gagik Jun 10, 2025
4730c18
fix: add tests and fix bug with menu auto-closing
gagik Jun 10, 2025
eb65769
fix: enforce no nesting, adjsut enzyme test and move setup to testing…
gagik Jun 10, 2025
37dff3a
fix: separate type import
gagik Jun 10, 2025
61e39c3
fix: remove redundant providers
gagik Jun 10, 2025
3c3cf13
Merge branch 'gagik/context-menu-compass-ui' of github.com:mongodb-js…
gagik Jun 10, 2025
97dd158
fix: remove unnecesary order change
gagik Jun 10, 2025
220a300
fix: move to compass components provider
gagik Jun 10, 2025
74f3d6e
fix: remove unintended deletion
gagik Jun 10, 2025
4f05381
fix: adjust tests
gagik Jun 10, 2025
8deaaac
Merge branch 'gagik/context-menu-compass-ui' of github.com:mongodb-js…
gagik Jun 10, 2025
3f6e8ac
fix: use compass components provider
gagik Jun 10, 2025
2863676
fix: use a shared hook and minimize test duplication
gagik Jun 10, 2025
458276b
Merge branch 'main' of github.com:mongodb-js/compass into gagik/colle…
gagik Jun 17, 2025
0236593
fix: use the shared hook
gagik Jun 17, 2025
7ced8fc
refactor: turn cell render into a functional component
gagik Jun 16, 2025
5d932a0
refactor: untangle usage of nested if statements
gagik Jun 16, 2025
fc6068e
fix: use CellState wherever possible
gagik Jun 17, 2025
16bf358
wip
gagik Jun 17, 2025
73bfc31
wip
gagik Jun 18, 2025
4ad7231
Merge branch 'main' of github.com:mongodb-js/compass into gagik/conte…
gagik Jun 18, 2025
cbb0656
Merge branch 'main' of github.com:mongodb-js/compass into gagik/headl…
gagik Jun 18, 2025
c6d7b03
Merge branch 'gagik/headless-context-menu' of github.com:mongodb-js/c…
gagik Jun 18, 2025
6b6e398
fix: throw early on
gagik Jun 18, 2025
17c05f0
Merge branch 'main' of github.com:mongodb-js/compass into gagik/conte…
gagik Jun 19, 2025
6dadf25
fix: correct wrapper use
gagik Jun 19, 2025
a62690b
Merge branch 'main' of github.com:mongodb-js/compass into gagik/conte…
gagik Jun 19, 2025
4dafa7b
fix: use render directly for compass-context-menu
gagik Jun 19, 2025
915c597
fix: use testingLibrary's render
gagik Jun 19, 2025
8f306e4
feat: memoize items for context menu
gagik Jun 19, 2025
aa52fb7
fix: adjust dependencies
gagik Jun 19, 2025
fb9c599
fix: support nesting
gagik Jun 19, 2025
ce464c8
Merge branch 'gagik/context-menu-compass-ui' of github.com:mongodb-js…
gagik Jun 19, 2025
3885366
Squash merge of crud related changes from gagik/collection-tab
kraenhansen Jul 3, 2025
02d7a2e
Fix copy field & value
kraenhansen Jul 3, 2025
ac8572d
Fix enzyme tests
kraenhansen Jul 3, 2025
197d0ed
fix: remove duplicated ref passing
gagik Jul 3, 2025
1a66462
Merge branch 'main' of github.com:mongodb-js/compass into gagik/table…
gagik Jul 3, 2025
94078ac
Merge branch 'gagik/collection-tab' of github.com:mongodb-js/compass …
gagik Jul 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 167 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import React from 'react';
import { render, screen, userEvent } from '@mongodb-js/testing-library-compass';
import { expect } from 'chai';
import sinon from 'sinon';
import HadronDocument from 'hadron-document';
import { HadronElement } from './element';
import type { Element } from 'hadron-document';

describe('HadronElement', function () {
describe('context menu', function () {
let doc: HadronDocument;
let element: Element;
let windowOpenStub: sinon.SinonStub;
let clipboardWriteTextStub: sinon.SinonStub;

beforeEach(function () {
doc = new HadronDocument({ field: 'value' });
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
element = doc.elements.at(0)!;
windowOpenStub = sinon.stub(window, 'open');
clipboardWriteTextStub = sinon.stub(navigator.clipboard, 'writeText');
});

afterEach(function () {
windowOpenStub.restore();
clipboardWriteTextStub.restore();
});

it('copies field and value when "Copy field & value" is clicked', function () {
render(
<HadronElement
value={element}
editable={true}
editingEnabled={true}
lineNumberSize={1}
onAddElement={() => {}}
/>
);

// Open context menu and click the copy option
const elementNode = screen.getByTestId('hadron-document-element');
userEvent.click(elementNode, { button: 2 });
userEvent.click(screen.getByText('Copy field & value'), undefined, {
skipPointerEventsCheck: true,
});

expect(clipboardWriteTextStub).to.have.been.calledWith('field: "value"');
});

it('shows "Open URL in browser" for URL string values', function () {
const urlDoc = new HadronDocument({ link: 'https://mongodb.com' });
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const urlElement = urlDoc.elements.at(0)!;

render(
<HadronElement
value={urlElement}
editable={true}
editingEnabled={true}
lineNumberSize={1}
onAddElement={() => {}}
/>
);

// Open context menu
const elementNode = screen.getByTestId('hadron-document-element');
userEvent.click(elementNode, { button: 2 });

// Check if the menu item exists
expect(screen.getByText('Open URL in browser')).to.exist;
});

it('opens URL in new tab when "Open URL in browser" is clicked', function () {
const urlDoc = new HadronDocument({ link: 'https://mongodb.com' });
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const urlElement = urlDoc.elements.at(0)!;

render(
<HadronElement
value={urlElement}
editable={true}
editingEnabled={true}
lineNumberSize={1}
onAddElement={() => {}}
/>
);

// Open context menu and click the open URL option
const elementNode = screen.getByTestId('hadron-document-element');
userEvent.click(elementNode, { button: 2 });
userEvent.click(screen.getByText('Open URL in browser'), undefined, {
skipPointerEventsCheck: true,
});

expect(windowOpenStub).to.have.been.calledWith(
'https://mongodb.com',
'_blank',
'noopener'
);
});

it('does not show "Open URL in browser" for non-URL string values', function () {
render(
<HadronElement
value={element}
editable={true}
editingEnabled={true}
lineNumberSize={1}
onAddElement={() => {}}
/>
);

// Open context menu
const elementNode = screen.getByTestId('hadron-document-element');
userEvent.click(elementNode, { button: 2 });

// Check that the menu item doesn't exist
expect(screen.queryByText('Open URL in browser')).to.not.exist;
});
});
});
Loading