Skip to content

Commit

Permalink
fix(shell): persist shell input; prevent tab from blinking; fix telem…
Browse files Browse the repository at this point in the history
…etry (#5996)
  • Loading branch information
gribnoysup authored Jul 11, 2024
1 parent 3540c03 commit 5f9a88f
Show file tree
Hide file tree
Showing 16 changed files with 395 additions and 724 deletions.
8 changes: 5 additions & 3 deletions package-lock.json

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

7 changes: 4 additions & 3 deletions packages/compass-shell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,23 @@
"reformat": "npm run eslint . -- --fix && npm run prettier -- --write ."
},
"dependencies": {
"@mongodb-js/compass-workspaces": "^0.16.0",
"@mongodb-js/compass-components": "^1.27.0",
"@mongodb-js/compass-connections": "^1.35.0",
"@mongodb-js/compass-logging": "^1.4.0",
"@mongodb-js/compass-telemetry": "^1.1.0",
"@mongodb-js/compass-user-data": "^0.3.0",
"@mongodb-js/compass-utils": "^0.6.6",
"@mongodb-js/compass-workspaces": "^0.16.0",
"@mongosh/browser-repl": "^2.2.12",
"@mongosh/logging": "^2.2.12",
"@mongosh/node-runtime-worker-thread": "^2.2.12",
"bson": "^6.7.0",
"compass-preferences-model": "^2.24.0",
"hadron-app-registry": "^9.2.0",
"prop-types": "^15.7.2",
"react": "^17.0.2",
"react-redux": "^8.1.3",
"redux": "^4.2.1"
"redux": "^4.2.1",
"redux-thunk": "^2.4.2"
},
"devDependencies": {
"@mongodb-js/connection-storage": "^0.15.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ const fakeRuntime = {
describe('CompassShell', function () {
context('when rendered', function () {
let wrapper;
let emitShellOpenedSpy;

beforeEach(function () {
emitShellOpenedSpy = sinon.spy();

wrapper = mount(
<CompassShell
initialHistory={[]}
onHistoryChange={() => undefined}
runtime={fakeRuntime}
emitShellPluginOpened={emitShellOpenedSpy}
enableShell
/>
);
Expand All @@ -49,23 +47,19 @@ describe('CompassShell', function () {
getComputedStyle(shellDomNode).getPropertyValue('display');
expect(shellDisplayStyle).to.equal('none');
});

context('when is it expanded', function () {
it('calls the function prop emitShellPluginOpened', function () {
expect(emitShellOpenedSpy.calledOnce).to.equal(false);

wrapper.setState({ height: 300 });
wrapper.update();

expect(emitShellOpenedSpy.calledOnce).to.equal(true);
});
});
});

context('when rendered expanded', function () {
context('when runtime property is not present', function () {
it('does not render a shell if runtime is null', function () {
const wrapper = mount(<CompassShell runtime={null} enableShell />);
const wrapper = mount(
<CompassShell
initialHistory={[]}
onHistoryChange={() => undefined}
runtime={null}
enableShell
/>
);
try {
wrapper.setState({ height: 300 });
wrapper.update();
Expand All @@ -82,8 +76,9 @@ describe('CompassShell', function () {
beforeEach(function () {
wrapper = mount(
<CompassShell
initialHistory={[]}
onHistoryChange={() => undefined}
runtime={fakeRuntime}
emitShellPluginOpened={() => {}}
enableShell
/>
);
Expand Down Expand Up @@ -128,8 +123,9 @@ describe('CompassShell', function () {
it('renders the inital output', function () {
const wrapper = mount(
<CompassShell
initialHistory={[]}
onHistoryChange={() => undefined}
runtime={fakeRuntime}
emitShellPluginOpened={() => {}}
shellOutput={[
{
type: 'output',
Expand Down Expand Up @@ -159,7 +155,12 @@ describe('CompassShell', function () {
context('when historyStorage is not present', function () {
it('passes an empty history to the Shell', function () {
const wrapper = shallow(
<CompassShell runtime={fakeRuntime} enableShell />
<CompassShell
initialHistory={[]}
onHistoryChange={() => undefined}
runtime={fakeRuntime}
enableShell
/>
);

expect(wrapper.find(Shell).prop('initialHistory')).to.deep.equal([]);
Expand All @@ -174,8 +175,9 @@ describe('CompassShell', function () {
beforeEach(function () {
wrapper = mount(
<CompassShell
initialHistory={[]}
onHistoryChange={() => undefined}
runtime={fakeRuntime}
emitShellPluginOpened={() => {}}
enableShell
/>
);
Expand Down Expand Up @@ -221,22 +223,14 @@ describe('CompassShell', function () {
});

context('when historyStorage is present', function () {
let fakeStorage;

beforeEach(function () {
fakeStorage = {
load: sinon.spy(() => Promise.resolve([])),
save: sinon.spy(() => Promise.resolve()),
};
});
const history = ['line1'];

it('passes the loaded history as initialHistory to Shell', async function () {
fakeStorage.load = sinon.spy(() => Promise.resolve(['line1']));

const wrapper = shallow(
<CompassShell
runtime={{} as any}
historyStorage={fakeStorage}
initialHistory={history}
onHistoryChange={() => undefined}
enableShell
/>
);
Expand All @@ -251,10 +245,13 @@ describe('CompassShell', function () {
});

it('saves the history when history changes', async function () {
const changeSpy = sinon.spy();

const wrapper = shallow(
<CompassShell
runtime={{} as any}
historyStorage={fakeStorage}
initialHistory={[]}
onHistoryChange={changeSpy}
enableShell
/>
);
Expand All @@ -264,7 +261,7 @@ describe('CompassShell', function () {
const onHistoryChanged = wrapper.find(Shell).prop('onHistoryChanged');
onHistoryChanged(['line1']);

expect(fakeStorage.save.calledWith(['line1'])).to.equal(true);
expect(changeSpy).to.have.been.calledOnceWith(['line1']);

wrapper.unmount();
});
Expand All @@ -291,22 +288,20 @@ describe('CompassShell', function () {
});

context('resize actions', function () {
let onOpenShellSpy;
let wrapper;

beforeEach(function () {
onOpenShellSpy = sinon.spy();
wrapper = mount(
<CompassShell
initialHistory={[]}
onHistoryChange={() => undefined}
runtime={fakeRuntime}
emitShellPluginOpened={onOpenShellSpy}
enableShell
/>
);
});
afterEach(function () {
wrapper.unmount();
onOpenShellSpy = null;
wrapper = null;
});

Expand Down Expand Up @@ -379,10 +374,6 @@ describe('CompassShell', function () {
expect(shellDisplayStyle).to.equal('none');
});

it('does not calls the function prop emitShellPluginOpened', function () {
expect(onOpenShellSpy.called).to.equal(false);
});

context('when it hits the resize threshold', function () {
beforeEach(function () {
wrapper.setState({ height: 151 });
Expand All @@ -395,10 +386,6 @@ describe('CompassShell', function () {
).to.equal(151);
expect(wrapper.state('height')).to.equal(151);
});

it('calls the function prop emitShellPluginOpened', function () {
expect(onOpenShellSpy.calledOnce).to.equal(true);
});
});
});
});
Expand Down
Loading

0 comments on commit 5f9a88f

Please sign in to comment.