Skip to content

Commit

Permalink
feature: adapt the connection form component to the new design guidel…
Browse files Browse the repository at this point in the history
…ines COMPASS-7652 (#5514)

* new design

* chore: put the new color palette under the feature toggle

* chore: interact with the form

* chore: use glyphs on the option

* chore: checking why it resets

* chore: fixed wierd behaviour of useReducer

* chore: can save connections

* chore: add test to reducer

* chore: fix the connect button

* chore: add todo marker

* chore: add tests to the form

* chore: linting issues

* chore: linting issues

* chore: fix typing issues

* chore: add tests to color names

* chore: remove exclusive test

* chore: linting issues

* chore: package.json merge conflict

* chore: update package-lock

* chore: fix tests

* chore: beware of race conditions

* chore: fix tests

* chore: be pretty

* chore: move to inner scope

* chore: fix copy
  • Loading branch information
kmruiz committed Mar 6, 2024
1 parent 2a270bd commit 403e8e3
Show file tree
Hide file tree
Showing 10 changed files with 733 additions and 64 deletions.
1 change: 1 addition & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions packages/compass-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export {
} from './components/content-with-fallback';
export { InlineDefinition } from './components/inline-definition';
import type { glyphs } from '@leafygreen-ui/icon';
export { createGlyphComponent, createIconComponent } from '@leafygreen-ui/icon';
export {
SignalPopover,
SignalHooksProvider,
Expand Down
1 change: 1 addition & 0 deletions packages/connection-form/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"peerDependencies": {
"@mongodb-js/compass-components": "^1.22.1",
"@mongodb-js/compass-editor": "^0.21.1",
"compass-preferences-model": "^2.11.1",
"react": "^17.0.2"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,71 @@ function ConnectFormActions({
);
}

export type ConnectionFormModalActionsProps = {
errors: ConnectionFormError[];
warnings: ConnectionFormWarning[];

onCancel(): void;
onSave(): void;
onConnect(): void;
};

export function ConnectionFormModalActions({
errors,
warnings,
onCancel,
onSave,
onConnect,
}: ConnectionFormModalActionsProps): React.ReactElement {
return (
<div className={cx(formActionStyles)}>
{warnings.length > 0 && (
<div className={formActionItemStyles}>
<WarningSummary
data-testid="connection-warnings-summary"
warnings={warnings.map((warning) => warning.message)}
/>
</div>
)}
{errors.length > 0 && (
<div className={formActionItemStyles}>
<ErrorSummary
data-testid="connection-error-summary"
errors={errors.map((error) => error.message)}
/>
</div>
)}
<div className={cx(formActionItemStyles, formActionButtonsStyles)}>
<Button
data-testid="save-connection-button"
variant={ButtonVariant.Default}
disabled={false}
onClick={onCancel}
>
Cancel
</Button>

<div className={saveAndConnectStyles}>
<Button
data-testid="save-and-connect-button"
variant={ButtonVariant.PrimaryOutline}
disabled={false}
onClick={onSave}
>
Save
</Button>
</div>

<Button
data-testid="connect-button"
variant={ButtonVariant.Primary}
onClick={onConnect}
>
Connect
</Button>
</div>
</div>
);
}

export default ConnectFormActions;
114 changes: 97 additions & 17 deletions packages/connection-form/src/components/connection-form.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import {
cleanup,
fireEvent,
getByText,
waitFor,
} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { expect } from 'chai';

import type { PreferencesAccess } from 'compass-preferences-model';
import { createSandboxFromDefaultPreferences } from 'compass-preferences-model';
import { PreferencesProvider } from 'compass-preferences-model/provider';
import ConnectionForm from './connection-form';
import type { ConnectionFormProps } from './connection-form';
import Sinon from 'sinon';
Expand All @@ -28,23 +32,31 @@ const noop = (): any => {
const saveAndConnectText = 'Save & Connect';
const favoriteText = 'FAVORITE';

function renderForm(props: Partial<ConnectionFormProps> = {}) {
return render(
<ConnectionForm
onConnectClicked={noop}
initialConnectionInfo={{
id: 'test',
connectionOptions: {
connectionString: 'mongodb://pineapple:orangutans@localhost:27019',
},
}}
onSaveConnectionClicked={noop}
{...props}
/>
);
}

describe('ConnectionForm Component', function () {
let preferences: PreferencesAccess;
function renderForm(props: Partial<ConnectionFormProps> = {}) {
return render(
<PreferencesProvider value={preferences}>
<ConnectionForm
onConnectClicked={noop}
initialConnectionInfo={{
id: 'test',
connectionOptions: {
connectionString:
'mongodb://pineapple:orangutans@localhost:27019',
},
}}
onSaveConnectionClicked={noop}
{...props}
/>
</PreferencesProvider>
);
}

beforeEach(async function () {
preferences = await createSandboxFromDefaultPreferences();
});

afterEach(function () {
cleanup();
});
Expand Down Expand Up @@ -363,4 +375,72 @@ describe('ConnectionForm Component', function () {

expect(() => screen.getByText(saveAndConnectText)).to.throw;
});

context('when multiple connection management is enabled', function () {
beforeEach(async function () {
await preferences.savePreferences({
enableNewMultipleConnectionSystem: true,
});
renderForm({
initialConnectionInfo: DEFAULT_CONNECTION,
preferences: {
protectConnectionStringsForNewConnections: false,
protectConnectionStrings: false,
},
});
});

it('should not show the old favorite button', function () {
expect(screen.queryByTestId('edit-favorite-icon-button')).to.be.null;
});

describe('name input', function () {
it('should sync with the href of the connection string unless it has been edited', async function () {
const connectionString = screen.getByTestId('connectionString');
userEvent.clear(connectionString);

await waitFor(() => expect(connectionString.value).to.equal(''));

userEvent.paste(connectionString, 'mongodb://myserver:27017/');

await waitFor(() =>
expect(connectionString.value).to.equal('mongodb://myserver:27017/')
);

const personalizationName = screen.getByTestId(
'personalization-name-input'
);
expect(personalizationName.value).to.equal('myserver:27017');
});

it('should not sync with the href of the connection string when it has been edited', async function () {
const connectionString = screen.getByTestId('connectionString');
const personalizationName = screen.getByTestId(
'personalization-name-input'
);

userEvent.clear(personalizationName);
userEvent.clear(connectionString);

await waitFor(() => {
expect(personalizationName.value).to.equal('');
expect(connectionString.value).to.equal('');
});

userEvent.paste(personalizationName, 'my happy name');

await waitFor(() =>
expect(personalizationName.value).to.equal('my happy name')
);

userEvent.paste(connectionString, 'mongodb://webscale:27017/');

await waitFor(() =>
expect(connectionString.value).to.equal('mongodb://webscale:27017/')
);

expect(personalizationName.value).to.equal('my happy name');
});
});
});
});
Loading

0 comments on commit 403e8e3

Please sign in to comment.