Skip to content

Commit ec60839

Browse files
use dialog's checkbox and fix tests
1 parent ffeb762 commit ec60839

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/__tests__/test-components/GitPanel.spec.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ describe('GitPanel', () => {
188188
it('should commit when commit message is provided', async () => {
189189
configSpy.mockResolvedValue({ options: commitUser });
190190

191+
props.model.checkNotebooksForOutputs = jest.fn().mockResolvedValue([]);
192+
191193
await userEvent.type(screen.getAllByRole('textbox')[0], commitSummary);
192194
await userEvent.type(
193195
screen.getAllByRole('textbox')[1],
@@ -223,6 +225,7 @@ describe('GitPanel', () => {
223225

224226
it('should prompt for user identity if explicitly configured', async () => {
225227
configSpy.mockResolvedValue({ options: commitUser });
228+
props.model.checkNotebooksForOutputs = jest.fn().mockResolvedValue([]);
226229

227230
props.settings = MockSettings(false, true) as any;
228231
renderResult.rerender(<GitPanel {...props} />);
@@ -245,6 +248,8 @@ describe('GitPanel', () => {
245248
it('should prompt for user identity if user.name is not set', async () => {
246249
configSpy.mockImplementation(mockConfigImplementation('user.email'));
247250
mockUtils.showDialog.mockResolvedValue(dialogValue);
251+
props.model.checkNotebooksForOutputs = jest.fn().mockResolvedValue([]);
252+
248253

249254
await userEvent.type(screen.getAllByRole('textbox')[0], commitSummary);
250255
await userEvent.click(screen.getByRole('button', { name: 'Commit' }));
@@ -261,6 +266,7 @@ describe('GitPanel', () => {
261266
it('should prompt for user identity if user.email is not set', async () => {
262267
configSpy.mockImplementation(mockConfigImplementation('user.name'));
263268
mockUtils.showDialog.mockResolvedValue(dialogValue);
269+
props.model.checkNotebooksForOutputs = jest.fn().mockResolvedValue([]);
264270

265271
await userEvent.type(screen.getAllByRole('textbox')[0], commitSummary);
266272
await userEvent.click(screen.getByRole('button', { name: 'Commit' }));
@@ -280,6 +286,7 @@ describe('GitPanel', () => {
280286

281287
configSpy.mockImplementation(mockConfigImplementation('user.email'));
282288
mockUtils.showDialog.mockResolvedValue(dialogValue);
289+
props.model.checkNotebooksForOutputs = jest.fn().mockResolvedValue([]);
283290

284291
await userEvent.type(screen.getAllByRole('textbox')[0], commitSummary);
285292
await userEvent.click(screen.getByRole('button', { name: 'Commit' }));
@@ -298,6 +305,7 @@ describe('GitPanel', () => {
298305
renderResult.rerender(<GitPanel {...props} />);
299306
configSpy.mockImplementation(mockConfigImplementation('user.name'));
300307
mockUtils.showDialog.mockResolvedValue(dialogValue);
308+
props.model.checkNotebooksForOutputs = jest.fn().mockResolvedValue([]);
301309

302310
await userEvent.type(screen.getAllByRole('textbox')[0], commitSummary);
303311
await userEvent.click(screen.getByRole('button', { name: 'Commit' }));

src/components/GitPanel.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import { HistorySideBar } from './HistorySideBar';
3535
import { RebaseAction } from './RebaseAction';
3636
import { Toolbar } from './Toolbar';
3737
import { WarningBox } from './WarningBox';
38-
import { Widget } from '@lumino/widgets';
3938

4039
/**
4140
* Interface describing component properties.
@@ -817,19 +816,12 @@ export class GitPanel extends React.Component<IGitPanelProps, IGitPanelState> {
817816
notebooksWithOutputs.length > 0 &&
818817
(clearSetting === null || clearSetting === undefined)
819818
) {
820-
const bodyWidget = new Widget();
821-
bodyWidget.node.innerHTML = `
822-
<div>
823-
<p>Clear all outputs before committing?</p>
824-
<label>
825-
<input type="checkbox" id="dontAskAgain" /> Save my preference
826-
</label>
827-
</div>
828-
`;
829-
830819
const dialog = new Dialog({
831820
title: this.props.trans.__('Notebook outputs detected'),
832-
body: bodyWidget,
821+
checkbox: {
822+
label: this.props.trans.__('Clear all outputs before committing?'),
823+
checked: false
824+
},
833825
buttons: [
834826
Dialog.cancelButton({
835827
label: this.props.trans.__('Keep Outputs & Commit')
@@ -847,11 +839,9 @@ export class GitPanel extends React.Component<IGitPanelProps, IGitPanelState> {
847839
}
848840
const accepted =
849841
result.button.label === this.props.trans.__('Clean & Commit');
850-
const checkbox =
851-
bodyWidget.node.querySelector<HTMLInputElement>('#dontAskAgain');
852842

853843
// Remember the user’s choice if checkbox is checked
854-
if (checkbox?.checked) {
844+
if (result?.isChecked) {
855845
this.props.settings.set('clearOutputsBeforeCommit', accepted);
856846
}
857847
if (accepted) {

0 commit comments

Comments
 (0)