Skip to content

Commit e5370b7

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

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

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

Lines changed: 7 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,7 @@ 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([]);
248252

249253
await userEvent.type(screen.getAllByRole('textbox')[0], commitSummary);
250254
await userEvent.click(screen.getByRole('button', { name: 'Commit' }));
@@ -261,6 +265,7 @@ describe('GitPanel', () => {
261265
it('should prompt for user identity if user.email is not set', async () => {
262266
configSpy.mockImplementation(mockConfigImplementation('user.name'));
263267
mockUtils.showDialog.mockResolvedValue(dialogValue);
268+
props.model.checkNotebooksForOutputs = jest.fn().mockResolvedValue([]);
264269

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

281286
configSpy.mockImplementation(mockConfigImplementation('user.email'));
282287
mockUtils.showDialog.mockResolvedValue(dialogValue);
288+
props.model.checkNotebooksForOutputs = jest.fn().mockResolvedValue([]);
283289

284290
await userEvent.type(screen.getAllByRole('textbox')[0], commitSummary);
285291
await userEvent.click(screen.getByRole('button', { name: 'Commit' }));
@@ -298,6 +304,7 @@ describe('GitPanel', () => {
298304
renderResult.rerender(<GitPanel {...props} />);
299305
configSpy.mockImplementation(mockConfigImplementation('user.name'));
300306
mockUtils.showDialog.mockResolvedValue(dialogValue);
307+
props.model.checkNotebooksForOutputs = jest.fn().mockResolvedValue([]);
301308

302309
await userEvent.type(screen.getAllByRole('textbox')[0], commitSummary);
303310
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)