Skip to content

Commit

Permalink
add edit and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Anemy committed Jan 11, 2024
1 parent d43a374 commit 5deb989
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 151 deletions.
63 changes: 63 additions & 0 deletions src/test/suite/connectionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
TEST_USER_PASSWORD,
} from './dbTestHelper';
import type { LoadedConnection } from '../../storage/connectionStorage';
import ConnectionString from 'mongodb-connection-string-url';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { version } = require('../../../package.json');
Expand Down Expand Up @@ -592,6 +593,68 @@ suite('Connection Controller Test Suite', function () {
assert.strictEqual(name, 'new connection name');
});

test('a saved to workspace connection can be updated and loaded', async () => {
await testConnectionController.loadSavedConnections();
await vscode.workspace
.getConfiguration('mdb.connectionSaving')
.update(
'defaultConnectionSavingLocation',
DefaultSavingLocations.Workspace
);
await testConnectionController.addNewConnectionStringAndConnect(
TEST_DATABASE_URI
);

const workspaceStoreConnections = testStorageController.get(
StorageVariables.WORKSPACE_SAVED_CONNECTIONS,
StorageLocation.WORKSPACE
);

assert.strictEqual(Object.keys(workspaceStoreConnections).length, 1);

const connectionId =
testConnectionController.getActiveConnectionId() || 'zz';

const updatedConnectionString = new ConnectionString(TEST_DATABASE_URI);
updatedConnectionString.searchParams.set('connectTimeoutMS', '5000');
const updateSuccess =
await testConnectionController.updateConnectionAndConnect({
connectionId,
connectionOptions: {
connectionString: updatedConnectionString.toString(),
},
});

assert.strictEqual(updateSuccess, true);

await testConnectionController.disconnect();

testConnectionController.clearAllConnections();

assert.strictEqual(
testConnectionController.getSavedConnections().length,
0
);

// Activate (which will load the past connection).
await testConnectionController.loadSavedConnections();

assert.strictEqual(
testConnectionController.getSavedConnections().length,
1
);

const id = testConnectionController.getSavedConnections()[0].id;
const connectTimeoutMS = new ConnectionString(
testConnectionController.getSavedConnections()[0].connectionOptions.connectionString
).searchParams.get('connectTimeoutMS');
const name = testConnectionController._connections[id || 'x'].name;

assert.strictEqual(name, 'localhost:27088');
// Ensure it's updated.
assert.strictEqual(connectTimeoutMS, '5000');
});

test('ConnectionQuickPicks workspace connections list is displayed in the alphanumerical case insensitive order', async () => {
await vscode.workspace
.getConfiguration('mdb.connectionSaving')
Expand Down
26 changes: 26 additions & 0 deletions src/test/suite/views/webview-app/overview-page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,32 @@ describe('OverviewPage test suite', function () {
expect(screen.queryByTestId(connectionFormTestId)).to.not.exist;
});

it('should show the connection form and the connection name when an editing request happens', function () {
render(<OverviewPage />);

expect(screen.queryByTestId(connectionFormTestId)).to.not.exist;
expect(screen.queryByText('pineapple')).to.not.exist;

act(() => {
window.dispatchEvent(
new MessageEvent('message', {
data: {
command: MESSAGE_TYPES.OPEN_EDIT_CONNECTION,
connection: {
id: 'test',
name: 'pineapple',
connectionOptions: {
connectionString: 'mongodb://localhost:27017',
},
},
},
})
);
});
expect(screen.getByTestId(connectionFormTestId)).to.exist;
expect(screen.getByText('pineapple')).to.exist;
});

it('should not display results from other connection attempts', function () {
render(<OverviewPage />);
screen.getByText('Open form').click();
Expand Down
Loading

0 comments on commit 5deb989

Please sign in to comment.