Skip to content

Commit 5f9a88f

Browse files
authored
fix(shell): persist shell input; prevent tab from blinking; fix telemetry (#5996)
1 parent 3540c03 commit 5f9a88f

File tree

16 files changed

+395
-724
lines changed

16 files changed

+395
-724
lines changed

package-lock.json

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

packages/compass-shell/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,23 @@
4949
"reformat": "npm run eslint . -- --fix && npm run prettier -- --write ."
5050
},
5151
"dependencies": {
52-
"@mongodb-js/compass-workspaces": "^0.16.0",
5352
"@mongodb-js/compass-components": "^1.27.0",
5453
"@mongodb-js/compass-connections": "^1.35.0",
5554
"@mongodb-js/compass-logging": "^1.4.0",
5655
"@mongodb-js/compass-telemetry": "^1.1.0",
5756
"@mongodb-js/compass-user-data": "^0.3.0",
5857
"@mongodb-js/compass-utils": "^0.6.6",
58+
"@mongodb-js/compass-workspaces": "^0.16.0",
5959
"@mongosh/browser-repl": "^2.2.12",
6060
"@mongosh/logging": "^2.2.12",
6161
"@mongosh/node-runtime-worker-thread": "^2.2.12",
62+
"bson": "^6.7.0",
6263
"compass-preferences-model": "^2.24.0",
6364
"hadron-app-registry": "^9.2.0",
64-
"prop-types": "^15.7.2",
6565
"react": "^17.0.2",
6666
"react-redux": "^8.1.3",
67-
"redux": "^4.2.1"
67+
"redux": "^4.2.1",
68+
"redux-thunk": "^2.4.2"
6869
},
6970
"devDependencies": {
7071
"@mongodb-js/connection-storage": "^0.15.0",

packages/compass-shell/src/components/compass-shell/compass-shell.spec.tsx

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ const fakeRuntime = {
2222
describe('CompassShell', function () {
2323
context('when rendered', function () {
2424
let wrapper;
25-
let emitShellOpenedSpy;
2625

2726
beforeEach(function () {
28-
emitShellOpenedSpy = sinon.spy();
29-
3027
wrapper = mount(
3128
<CompassShell
29+
initialHistory={[]}
30+
onHistoryChange={() => undefined}
3231
runtime={fakeRuntime}
33-
emitShellPluginOpened={emitShellOpenedSpy}
3432
enableShell
3533
/>
3634
);
@@ -49,23 +47,19 @@ describe('CompassShell', function () {
4947
getComputedStyle(shellDomNode).getPropertyValue('display');
5048
expect(shellDisplayStyle).to.equal('none');
5149
});
52-
53-
context('when is it expanded', function () {
54-
it('calls the function prop emitShellPluginOpened', function () {
55-
expect(emitShellOpenedSpy.calledOnce).to.equal(false);
56-
57-
wrapper.setState({ height: 300 });
58-
wrapper.update();
59-
60-
expect(emitShellOpenedSpy.calledOnce).to.equal(true);
61-
});
62-
});
6350
});
6451

6552
context('when rendered expanded', function () {
6653
context('when runtime property is not present', function () {
6754
it('does not render a shell if runtime is null', function () {
68-
const wrapper = mount(<CompassShell runtime={null} enableShell />);
55+
const wrapper = mount(
56+
<CompassShell
57+
initialHistory={[]}
58+
onHistoryChange={() => undefined}
59+
runtime={null}
60+
enableShell
61+
/>
62+
);
6963
try {
7064
wrapper.setState({ height: 300 });
7165
wrapper.update();
@@ -82,8 +76,9 @@ describe('CompassShell', function () {
8276
beforeEach(function () {
8377
wrapper = mount(
8478
<CompassShell
79+
initialHistory={[]}
80+
onHistoryChange={() => undefined}
8581
runtime={fakeRuntime}
86-
emitShellPluginOpened={() => {}}
8782
enableShell
8883
/>
8984
);
@@ -128,8 +123,9 @@ describe('CompassShell', function () {
128123
it('renders the inital output', function () {
129124
const wrapper = mount(
130125
<CompassShell
126+
initialHistory={[]}
127+
onHistoryChange={() => undefined}
131128
runtime={fakeRuntime}
132-
emitShellPluginOpened={() => {}}
133129
shellOutput={[
134130
{
135131
type: 'output',
@@ -159,7 +155,12 @@ describe('CompassShell', function () {
159155
context('when historyStorage is not present', function () {
160156
it('passes an empty history to the Shell', function () {
161157
const wrapper = shallow(
162-
<CompassShell runtime={fakeRuntime} enableShell />
158+
<CompassShell
159+
initialHistory={[]}
160+
onHistoryChange={() => undefined}
161+
runtime={fakeRuntime}
162+
enableShell
163+
/>
163164
);
164165

165166
expect(wrapper.find(Shell).prop('initialHistory')).to.deep.equal([]);
@@ -174,8 +175,9 @@ describe('CompassShell', function () {
174175
beforeEach(function () {
175176
wrapper = mount(
176177
<CompassShell
178+
initialHistory={[]}
179+
onHistoryChange={() => undefined}
177180
runtime={fakeRuntime}
178-
emitShellPluginOpened={() => {}}
179181
enableShell
180182
/>
181183
);
@@ -221,22 +223,14 @@ describe('CompassShell', function () {
221223
});
222224

223225
context('when historyStorage is present', function () {
224-
let fakeStorage;
225-
226-
beforeEach(function () {
227-
fakeStorage = {
228-
load: sinon.spy(() => Promise.resolve([])),
229-
save: sinon.spy(() => Promise.resolve()),
230-
};
231-
});
226+
const history = ['line1'];
232227

233228
it('passes the loaded history as initialHistory to Shell', async function () {
234-
fakeStorage.load = sinon.spy(() => Promise.resolve(['line1']));
235-
236229
const wrapper = shallow(
237230
<CompassShell
238231
runtime={{} as any}
239-
historyStorage={fakeStorage}
232+
initialHistory={history}
233+
onHistoryChange={() => undefined}
240234
enableShell
241235
/>
242236
);
@@ -251,10 +245,13 @@ describe('CompassShell', function () {
251245
});
252246

253247
it('saves the history when history changes', async function () {
248+
const changeSpy = sinon.spy();
249+
254250
const wrapper = shallow(
255251
<CompassShell
256252
runtime={{} as any}
257-
historyStorage={fakeStorage}
253+
initialHistory={[]}
254+
onHistoryChange={changeSpy}
258255
enableShell
259256
/>
260257
);
@@ -264,7 +261,7 @@ describe('CompassShell', function () {
264261
const onHistoryChanged = wrapper.find(Shell).prop('onHistoryChanged');
265262
onHistoryChanged(['line1']);
266263

267-
expect(fakeStorage.save.calledWith(['line1'])).to.equal(true);
264+
expect(changeSpy).to.have.been.calledOnceWith(['line1']);
268265

269266
wrapper.unmount();
270267
});
@@ -291,22 +288,20 @@ describe('CompassShell', function () {
291288
});
292289

293290
context('resize actions', function () {
294-
let onOpenShellSpy;
295291
let wrapper;
296292

297293
beforeEach(function () {
298-
onOpenShellSpy = sinon.spy();
299294
wrapper = mount(
300295
<CompassShell
296+
initialHistory={[]}
297+
onHistoryChange={() => undefined}
301298
runtime={fakeRuntime}
302-
emitShellPluginOpened={onOpenShellSpy}
303299
enableShell
304300
/>
305301
);
306302
});
307303
afterEach(function () {
308304
wrapper.unmount();
309-
onOpenShellSpy = null;
310305
wrapper = null;
311306
});
312307

@@ -379,10 +374,6 @@ describe('CompassShell', function () {
379374
expect(shellDisplayStyle).to.equal('none');
380375
});
381376

382-
it('does not calls the function prop emitShellPluginOpened', function () {
383-
expect(onOpenShellSpy.called).to.equal(false);
384-
});
385-
386377
context('when it hits the resize threshold', function () {
387378
beforeEach(function () {
388379
wrapper.setState({ height: 151 });
@@ -395,10 +386,6 @@ describe('CompassShell', function () {
395386
).to.equal(151);
396387
expect(wrapper.state('height')).to.equal(151);
397388
});
398-
399-
it('calls the function prop emitShellPluginOpened', function () {
400-
expect(onOpenShellSpy.calledOnce).to.equal(true);
401-
});
402389
});
403390
});
404391
});

0 commit comments

Comments
 (0)