Skip to content

Commit

Permalink
fixup: fix connection-form tests for FileInput change
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax committed Oct 25, 2024
1 parent 9c27dd7 commit 982b11f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 24 deletions.
14 changes: 14 additions & 0 deletions packages/compass-components/src/components/file-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@ export const FileInputBackendProvider: React.FunctionComponent<{
);
};

export function createJSDomFileInputDummyBackend(): () => FileInputBackend {
return () => ({
openFileChooser() {
return;
},
onFilesChosen() {
return () => void 0;
},
getPathForFile(file: File) {
return (file as any).path;
},
});
}

// Use as:
//
// import * as electronRemote from '@electron/remote';
Expand Down
1 change: 1 addition & 0 deletions packages/compass-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type {
} from './components/file-input';
import FileInput, {
createElectronFileInputBackend,
createJSDomFileInputDummyBackend,
FileInputBackendProvider,
} from './components/file-input';
import { OptionsToggle } from './components/options-toggle';
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-e2e-tests/tests/in-use-encryption.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ describe('CSFLE / QE', function () {
}
});

it('can read QE data stored in a mongodb 6 database', async function () {
it.only('can read QE data stored in a mongodb 6 database', async function () {
// connect without QE and insert some fixture data that we generated against a 6.x database using the shell
await browser.connectWithConnectionForm({
hosts: [CONNECTION_HOSTS],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { Binary } from 'bson';

import ConnectionForm from '../../../';
import { getNextKmsProviderName } from './kms-provider-content';
import { FileInputBackendProvider } from '@mongodb-js/compass-components';
import { createJSDomFileInputDummyBackend } from '@mongodb-js/compass-components/lib/components/file-input';

const openAdvancedTab = async (
tabId: 'general' | 'authentication' | 'tls' | 'proxy' | 'advanced' | 'csfle'
Expand Down Expand Up @@ -85,20 +87,24 @@ describe('In-Use Encryption', function () {
};

render(
<ConnectionForm
initialConnectionInfo={{
id: 'conn-1',
connectionOptions: {
connectionString: 'mongodb://localhost:27017',
},
}}
onSaveAndConnectClicked={(connectionInfo) => {
connectSpy(connectionInfo.connectionOptions);
}}
onSaveClicked={() => {
return Promise.resolve();
}}
/>
<FileInputBackendProvider
createFileInputBackend={createJSDomFileInputDummyBackend()}
>
<ConnectionForm
initialConnectionInfo={{
id: 'conn-1',
connectionOptions: {
connectionString: 'mongodb://localhost:27017',
},
}}
onSaveAndConnectClicked={(connectionInfo) => {
connectSpy(connectionInfo.connectionOptions);
}}
onSaveClicked={() => {
return Promise.resolve();
}}
/>
</FileInputBackendProvider>
);

expect(connectSpy).not.to.have.been.called;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import type { SSHConnectionOptions } from '../../../utils/connection-ssh-handler
import SSHTunnelIdentity from './ssh-tunnel-identity';
import type { ConnectionFormError } from '../../../utils/validation';
import { errorMessageByFieldName } from '../../../utils/validation';
import { FileInputBackendProvider } from '@mongodb-js/compass-components';
import { createJSDomFileInputDummyBackend } from '@mongodb-js/compass-components/lib/components/file-input';

const formFields: {
key: keyof SSHConnectionOptions;
Expand Down Expand Up @@ -49,11 +51,15 @@ describe('SSHTunnelIdentity', function () {
updateConnectionFormFieldSpy = sinon.spy();

render(
<SSHTunnelIdentity
errors={[]}
sshTunnelOptions={sshTunnelOptions}
updateConnectionFormField={updateConnectionFormFieldSpy}
/>
<FileInputBackendProvider
createFileInputBackend={createJSDomFileInputDummyBackend()}
>
<SSHTunnelIdentity
errors={[]}
sshTunnelOptions={sshTunnelOptions}
updateConnectionFormField={updateConnectionFormFieldSpy}
/>
</FileInputBackendProvider>
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import sinon from 'sinon';
import ConnectionStringUrl from 'mongodb-connection-string-url';

import SSLTab, { getTLSOptionForConnectionString } from './tls-ssl-tab';
import { FileInputBackendProvider } from '@mongodb-js/compass-components';
import { createJSDomFileInputDummyBackend } from '@mongodb-js/compass-components/lib/components/file-input';

describe('SchemaInput', function () {
let updateConnectionFormFieldSpy: sinon.SinonSpy;
Expand All @@ -28,10 +30,14 @@ describe('SchemaInput', function () {
'mongodb+srv://0ranges:p!neapp1es@localhost/?ssl=true'
);
const component = render(
<SSLTab
connectionStringUrl={testUrl}
updateConnectionFormField={updateConnectionFormFieldSpy}
/>
<FileInputBackendProvider
createFileInputBackend={createJSDomFileInputDummyBackend()}
>
<SSLTab
connectionStringUrl={testUrl}
updateConnectionFormField={updateConnectionFormFieldSpy}
/>
</FileInputBackendProvider>
);
rerender = component.rerender;
});
Expand Down

0 comments on commit 982b11f

Please sign in to comment.