Skip to content

Commit 7675c98

Browse files
authored
feat(aggregations): conditional confirmation modal COMPASS-6355 (#4079)
1 parent 08a3b6a commit 7675c98

34 files changed

+581
-835
lines changed

configs/mocha-config-compass/register/jsdom-global-register.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@ if (!globalThis.IntersectionObserver) {
5151
disconnect() {}
5252
};
5353
}
54+
55+
// jsdom doesn't override classes that already exist in global scope
56+
// https://github.com/jsdom/jsdom/issues/3331
57+
globalThis.EventTarget = window.EventTarget;

packages/compass-aggregations/src/components/pipeline-confirm-modal/pipeline-confirm-modal.spec.tsx

Lines changed: 0 additions & 62 deletions
This file was deleted.

packages/compass-aggregations/src/components/pipeline-confirm-modal/pipeline-confirm-modal.tsx

Lines changed: 0 additions & 58 deletions
This file was deleted.

packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-settings/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import PipelineName from './pipeline-name';
77
import PipelineExtraSettings from './pipeline-extra-settings';
88
import type { RootState } from '../../../modules';
99
import { getIsPipelineInvalidFromBuilderState } from '../../../modules/pipeline-builder/builder-helpers';
10-
import { toggleNewPipelineModal } from '../../../modules/is-new-pipeline-confirm';
10+
import { confirmNewPipeline } from '../../../modules/is-new-pipeline-confirm';
1111

1212
const containerStyles = css({
1313
display: 'grid',
@@ -95,6 +95,6 @@ export default connect(
9595
},
9696
{
9797
onExportToLanguage: exportToLanguage,
98-
onCreateNewPipeline: () => toggleNewPipelineModal(true),
98+
onCreateNewPipeline: confirmNewPipeline,
9999
}
100100
)(PipelineSettings);

packages/compass-aggregations/src/components/pipeline/pipeline.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Banner, WorkspaceContainer } from '@mongodb-js/compass-components';
44

55
import Settings from '../settings';
66
import SavingPipelineModal from '../saving-pipeline-modal';
7-
import PipelineConfirmModal from '../pipeline-confirm-modal/pipeline-confirm-modal';
87
import styles from './pipeline.module.less';
98

109
import PipelineToolbar from '../pipeline-toolbar';
@@ -141,7 +140,6 @@ class Pipeline extends PureComponent {
141140
)}
142141
<PipelineExplain />
143142
<FocusMode />
144-
<PipelineConfirmModal />
145143
{savingPipelineModal}
146144
</WorkspaceContainer>
147145
</div>

packages/compass-aggregations/src/components/saved-pipelines/saved-pipeline-confirmation-modals.tsx

Lines changed: 0 additions & 68 deletions
This file was deleted.

packages/compass-aggregations/src/components/saved-pipelines/saved-pipelines.spec.tsx

Lines changed: 26 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,24 @@ import Sinon from 'sinon';
66

77
import { SavedPipelines } from './saved-pipelines';
88

9+
const savedPipelines = [
10+
{
11+
name: 'test name 0',
12+
id: 'test id 0',
13+
},
14+
{
15+
name: 'test name 1',
16+
id: 'test id 1',
17+
},
18+
];
19+
920
const renderSavedPipelines = (
1021
props: Partial<ComponentProps<typeof SavedPipelines>> = {}
1122
) => {
1223
render(
1324
<SavedPipelines
1425
savedPipelines={[]}
1526
namespace="test.test123"
16-
editor_view_type="stage"
1727
onDeletePipeline={() => {}}
1828
onOpenPipeline={() => {}}
1929
{...props}
@@ -39,16 +49,6 @@ describe('SavedPipelines', function () {
3949
});
4050

4151
describe('renders saved pipeline cards', function () {
42-
const savedPipelines = [
43-
{
44-
name: 'test name 0',
45-
id: 'test id 0',
46-
},
47-
{
48-
name: 'test name 1',
49-
id: 'test id 1',
50-
},
51-
];
5252
let savedPipelineCards: HTMLElement[];
5353

5454
beforeEach(function () {
@@ -95,95 +95,34 @@ describe('SavedPipelines', function () {
9595
});
9696
});
9797

98-
describe('when pipeline is opened', function () {
99-
const openPipelineModalTestId = 'restore-pipeline-modal';
100-
let onOpenPipelineSpy: Sinon.SinonSpy;
101-
102-
beforeEach(function () {
103-
onOpenPipelineSpy = Sinon.spy();
98+
describe('calls card actions', function () {
99+
it('calls onOpenPipeline when open button is clicked', function () {
100+
const onOpenPipelineSpy = Sinon.spy();
104101
renderSavedPipelines({
105-
savedPipelines: [
106-
{
107-
name: 'test name 1',
108-
id: 'test id 1',
109-
},
110-
],
102+
savedPipelines,
111103
onOpenPipeline: onOpenPipelineSpy,
112104
});
113-
// Open the pipeline open modal
114-
userEvent.click(screen.getByTestId('saved-pipeline-card-open-action'));
115-
expect(screen.getByTestId(openPipelineModalTestId)).to.exist;
116-
});
117-
118-
it('closes when cancel is clicked', function () {
105+
const savedPipelineCard = screen.getAllByTestId('saved-pipeline-card')[0];
119106
userEvent.click(
120-
screen.getByRole('button', {
121-
name: /cancel/i,
122-
})
123-
);
124-
expect(onOpenPipelineSpy.calledOnce).to.be.false;
125-
expect(() => {
126-
screen.getByTestId(openPipelineModalTestId);
127-
}).to.throw;
128-
});
129-
130-
it('closes when open pipeline is clicked and calls onOpenPipeline', function () {
131-
expect(onOpenPipelineSpy.calledOnce).to.be.false;
132-
userEvent.click(
133-
screen.getByRole('button', {
134-
name: /open pipeline/i,
135-
})
107+
within(savedPipelineCard).getByTestId('saved-pipeline-card-open-action')
136108
);
137109
expect(onOpenPipelineSpy.calledOnce).to.be.true;
138-
expect(() => {
139-
screen.getByTestId(openPipelineModalTestId);
140-
}).to.throw;
110+
expect(onOpenPipelineSpy.calledWith(savedPipelines[0].id)).to.be.true;
141111
});
142-
});
143-
144-
describe('when pipeline is deleted', function () {
145-
const deletePipelineModalTestId = 'delete-pipeline-modal';
146-
let onDeletePipelineSpy: Sinon.SinonSpy;
147-
148-
beforeEach(function () {
149-
onDeletePipelineSpy = Sinon.spy();
112+
it('calls onDeletePipeline when delete button is clicked', function () {
113+
const onDeletePipelineSpy = Sinon.spy();
150114
renderSavedPipelines({
151-
savedPipelines: [
152-
{
153-
name: 'test name 1',
154-
id: 'test id 1',
155-
},
156-
],
115+
savedPipelines,
157116
onDeletePipeline: onDeletePipelineSpy,
158117
});
159-
// Open the pipeline delete modal
160-
userEvent.click(screen.getByTestId('saved-pipeline-card-delete-action'));
161-
expect(screen.getByTestId(deletePipelineModalTestId)).to.exist;
162-
});
163-
164-
it('closes when cancel is clicked', function () {
165-
userEvent.click(
166-
screen.getByRole('button', {
167-
name: /cancel/i,
168-
})
169-
);
170-
expect(onDeletePipelineSpy.calledOnce).to.be.false;
171-
expect(() => {
172-
screen.getByTestId(deletePipelineModalTestId);
173-
}).to.throw;
174-
});
175-
176-
it('closes when delete pipeline is clicked and calls onDeletePipeline', function () {
177-
expect(onDeletePipelineSpy.calledOnce).to.be.false;
118+
const savedPipelineCard = screen.getAllByTestId('saved-pipeline-card')[1];
178119
userEvent.click(
179-
screen.getByRole('button', {
180-
name: /delete pipeline/i,
181-
})
120+
within(savedPipelineCard).getByTestId(
121+
'saved-pipeline-card-delete-action'
122+
)
182123
);
183124
expect(onDeletePipelineSpy.calledOnce).to.be.true;
184-
expect(() => {
185-
screen.getByTestId(deletePipelineModalTestId);
186-
}).to.throw;
125+
expect(onDeletePipelineSpy.calledWith(savedPipelines[1].id)).to.be.true;
187126
});
188127
});
189128
});

0 commit comments

Comments
 (0)