Skip to content

Commit 7e17a9f

Browse files
committed
Merge branch 'COMPASS-9523-move-export-state-to-redux' of https://github.com/mongodb-js/compass into COMPASS-9523-move-export-state-to-redux
2 parents ae0d002 + 3e33a52 commit 7e17a9f

23 files changed

+1231
-79
lines changed

package-lock.json

Lines changed: 167 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-components/src/components/actions/dropdown-menu-button.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import { actionTestId } from './utils';
1111
import { ActionGlyph } from './action-glyph';
1212
import { isSeparatorMenuAction, type MenuAction } from './item-action-menu';
1313

14-
const hiddenOnNarrowStyles = css({
15-
[`@container ${WorkspaceContainer.toolbarContainerQueryName} (width < 900px)`]:
16-
{
17-
display: 'none',
18-
},
19-
});
14+
const getHiddenOnNarrowStyles = (narrowBreakpoint: string) =>
15+
css({
16+
[`@container ${WorkspaceContainer.toolbarContainerQueryName} (width < ${narrowBreakpoint})`]:
17+
{
18+
display: 'none',
19+
},
20+
});
2021

2122
export type DropdownMenuButtonProps<Action extends string> = {
2223
actions: MenuAction<Action>[];
@@ -29,6 +30,7 @@ export type DropdownMenuButtonProps<Action extends string> = {
2930
buttonText: string;
3031
buttonProps: ButtonProps & React.ButtonHTMLAttributes<HTMLButtonElement>;
3132
hideOnNarrow?: boolean;
33+
narrowBreakpoint?: string;
3234
};
3335

3436
export function DropdownMenuButton<Action extends string>({
@@ -42,6 +44,7 @@ export function DropdownMenuButton<Action extends string>({
4244
iconSize = ItemActionButtonSize.Default,
4345
'data-testid': dataTestId,
4446
hideOnNarrow = true,
47+
narrowBreakpoint = '900px',
4548
}: DropdownMenuButtonProps<Action>) {
4649
// This ref is used by the Menu component to calculate the height and position
4750
// of the menu.
@@ -97,7 +100,13 @@ export function DropdownMenuButton<Action extends string>({
97100
{...buttonProps}
98101
>
99102
{buttonText && (
100-
<span className={hideOnNarrow ? hiddenOnNarrowStyles : undefined}>
103+
<span
104+
className={
105+
hideOnNarrow
106+
? getHiddenOnNarrowStyles(narrowBreakpoint)
107+
: undefined
108+
}
109+
>
101110
{buttonText}
102111
</span>
103112
)}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import React from 'react';
2+
import { render, screen, userEvent } from '@mongodb-js/testing-library-compass';
3+
import { expect } from 'chai';
4+
import sinon from 'sinon';
5+
import HadronDocument from 'hadron-document';
6+
import { HadronElement } from './element';
7+
import type { Element } from 'hadron-document';
8+
9+
describe('HadronElement', function () {
10+
describe('context menu', function () {
11+
let doc: HadronDocument;
12+
let element: Element;
13+
let windowOpenStub: sinon.SinonStub;
14+
let clipboardWriteTextStub: sinon.SinonStub;
15+
16+
beforeEach(function () {
17+
doc = new HadronDocument({ field: 'value' });
18+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
19+
element = doc.elements.at(0)!;
20+
windowOpenStub = sinon.stub(window, 'open');
21+
clipboardWriteTextStub = sinon.stub(navigator.clipboard, 'writeText');
22+
});
23+
24+
afterEach(function () {
25+
windowOpenStub.restore();
26+
clipboardWriteTextStub.restore();
27+
});
28+
29+
it('copies field and value when "Copy field & value" is clicked', function () {
30+
render(
31+
<HadronElement
32+
value={element}
33+
editable={true}
34+
editingEnabled={true}
35+
lineNumberSize={1}
36+
onAddElement={() => {}}
37+
/>
38+
);
39+
40+
// Open context menu and click the copy option
41+
const elementNode = screen.getByTestId('hadron-document-element');
42+
userEvent.click(elementNode, { button: 2 });
43+
userEvent.click(screen.getByText('Copy field & value'), undefined, {
44+
skipPointerEventsCheck: true,
45+
});
46+
47+
expect(clipboardWriteTextStub).to.have.been.calledWith('field: "value"');
48+
});
49+
50+
it('shows "Open URL in browser" for URL string values', function () {
51+
const urlDoc = new HadronDocument({ link: 'https://mongodb.com' });
52+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
53+
const urlElement = urlDoc.elements.at(0)!;
54+
55+
render(
56+
<HadronElement
57+
value={urlElement}
58+
editable={true}
59+
editingEnabled={true}
60+
lineNumberSize={1}
61+
onAddElement={() => {}}
62+
/>
63+
);
64+
65+
// Open context menu
66+
const elementNode = screen.getByTestId('hadron-document-element');
67+
userEvent.click(elementNode, { button: 2 });
68+
69+
// Check if the menu item exists
70+
expect(screen.getByText('Open URL in browser')).to.exist;
71+
});
72+
73+
it('opens URL in new tab when "Open URL in browser" is clicked', function () {
74+
const urlDoc = new HadronDocument({ link: 'https://mongodb.com' });
75+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
76+
const urlElement = urlDoc.elements.at(0)!;
77+
78+
render(
79+
<HadronElement
80+
value={urlElement}
81+
editable={true}
82+
editingEnabled={true}
83+
lineNumberSize={1}
84+
onAddElement={() => {}}
85+
/>
86+
);
87+
88+
// Open context menu and click the open URL option
89+
const elementNode = screen.getByTestId('hadron-document-element');
90+
userEvent.click(elementNode, { button: 2 });
91+
userEvent.click(screen.getByText('Open URL in browser'), undefined, {
92+
skipPointerEventsCheck: true,
93+
});
94+
95+
expect(windowOpenStub).to.have.been.calledWith(
96+
'https://mongodb.com',
97+
'_blank',
98+
'noopener'
99+
);
100+
});
101+
102+
it('does not show "Open URL in browser" for non-URL string values', function () {
103+
render(
104+
<HadronElement
105+
value={element}
106+
editable={true}
107+
editingEnabled={true}
108+
lineNumberSize={1}
109+
onAddElement={() => {}}
110+
/>
111+
);
112+
113+
// Open context menu
114+
const elementNode = screen.getByTestId('hadron-document-element');
115+
userEvent.click(elementNode, { button: 2 });
116+
117+
// Check that the menu item doesn't exist
118+
expect(screen.queryByText('Open URL in browser')).to.not.exist;
119+
});
120+
});
121+
});

0 commit comments

Comments
 (0)