Skip to content

Commit 2de9e85

Browse files
committed
tests
1 parent bf62a66 commit 2de9e85

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

packages/compass-connections/src/components/legacy-connections.spec.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ describe.skip('Connections Component', function () {
288288
});
289289

290290
it('should enable the connect button', function () {
291-
const connectButton = screen.getByText('Connect');
291+
const connectButton = screen.getByRole('button', {
292+
name: 'Save & Connect',
293+
});
292294
expect(connectButton).to.not.match('disabled');
293295
});
294296

packages/connection-form/src/components/connection-form-modal-actions.spec.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('<ConnectionFormModalActions />', function () {
3030
expect(screen.getByText('Error!')).to.be.visible;
3131
});
3232

33-
describe('Connect Button', function () {
33+
describe('Save&Connect Button', function () {
3434
it('should call onSaveAndConnect function', function () {
3535
const onSaveAndConnectSpy = sinon.spy();
3636
render(
@@ -41,7 +41,9 @@ describe('<ConnectionFormModalActions />', function () {
4141
onSaveAndConnect={onSaveAndConnectSpy}
4242
></ConnectionFormModalActions>
4343
);
44-
const connectButton = screen.getByRole('button', { name: 'Connect' });
44+
const connectButton = screen.getByRole('button', {
45+
name: 'Save & Connect',
46+
});
4547
userEvent.click(connectButton);
4648

4749
expect(onSaveAndConnectSpy).to.have.been.calledOnce;
@@ -54,7 +56,8 @@ describe('<ConnectionFormModalActions />', function () {
5456
warnings={[]}
5557
></ConnectionFormModalActions>
5658
);
57-
expect(screen.queryByRole('button', { name: 'Connect' })).to.not.exist;
59+
expect(screen.queryByRole('button', { name: 'Save & Connect' })).to.not
60+
.exist;
5861
});
5962
});
6063

packages/connection-form/src/components/connection-form.spec.tsx

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ describe('ConnectionForm Component', function () {
3939
connectionString: 'mongodb://pineapple:orangutans@localhost:27019',
4040
},
4141
}}
42-
onSaveClicked={noop}
4342
{...props}
4443
/>
4544
);
@@ -54,10 +53,55 @@ describe('ConnectionForm Component', function () {
5453
expect(screen.getByText('New Connection')).to.exist;
5554
});
5655

57-
it('should show the connect button', function () {
56+
it('should show no save or connect buttons by default', function () {
5857
renderForm();
59-
const button = screen.getByText('Connect').closest('button');
58+
expect(screen.queryByRole('button', { name: 'Save' })).to.be.null;
59+
expect(screen.queryByRole('button', { name: 'Connect' })).to.be.null;
60+
expect(screen.queryByRole('button', { name: 'Save & Connect' })).to.be.null;
61+
});
62+
63+
it('should show the save button if onSaveClicked is specified', function () {
64+
const onSaveClicked = Sinon.spy();
65+
renderForm({
66+
onSaveClicked: onSaveClicked,
67+
});
68+
const button = screen
69+
.getByRole('button', { name: 'Save' })
70+
.closest('button');
6071
expect(button?.getAttribute('aria-disabled')).to.not.equal('true');
72+
73+
button?.click();
74+
expect(onSaveClicked.callCount).to.equal(1);
75+
});
76+
77+
it('should show the connect button if onConnectClicked is specified', function () {
78+
const onConnectClicked = Sinon.spy();
79+
80+
renderForm({
81+
onConnectClicked,
82+
});
83+
const button = screen
84+
.getByRole('button', { name: 'Connect' })
85+
.closest('button');
86+
expect(button?.getAttribute('aria-disabled')).to.not.equal('true');
87+
88+
button?.click();
89+
expect(onConnectClicked.callCount).to.equal(1);
90+
});
91+
92+
it('should show the save & connect button if onSaveAndConnectClicked is specified', function () {
93+
const onSaveAndConnectClicked = Sinon.spy();
94+
95+
renderForm({
96+
onSaveAndConnectClicked,
97+
});
98+
const button = screen
99+
.getByRole('button', { name: 'Save & Connect' })
100+
.closest('button');
101+
expect(button?.getAttribute('aria-disabled')).to.not.equal('true');
102+
103+
button?.click();
104+
expect(onSaveAndConnectClicked.callCount).to.equal(1);
61105
});
62106

63107
it('should render the connection string textbox', function () {
@@ -103,6 +147,9 @@ describe('ConnectionForm Component', function () {
103147
screen.getByTestId('advanced-connection-options')
104148
).to.throw;
105149
expect(() => screen.getByRole('button', { name: 'Connect' })).to.throw;
150+
expect(() =>
151+
screen.getByRole('button', { name: 'Save & Connect' })
152+
).to.throw;
106153

107154
// pressing enter calls onSubmit which saves
108155
fireEvent.submit(screen.getByRole('form'));
@@ -137,6 +184,7 @@ describe('ConnectionForm Component', function () {
137184
expect(screen.getByTestId('toggle-edit-connection-string')).to.exist;
138185
expect(screen.getByTestId('advanced-connection-options')).to.exist;
139186
expect(screen.getByRole('button', { name: 'Connect' })).to.exist;
187+
expect(screen.getByRole('button', { name: 'Save & Connect' })).to.exist;
140188

141189
// pressing enter calls onSubmit which saves and connects (the default)
142190
fireEvent.submit(screen.getByRole('form'));

0 commit comments

Comments
 (0)