revert: "feat: allow the dialog methods to take in extra parameters (#8084)" (#8085)

This reverts commit 278006b5f8.
This commit is contained in:
Beka Westberg
2024-05-10 18:12:15 +00:00
committed by GitHub
parent 278006b5f8
commit c704d5a887
5 changed files with 75 additions and 104 deletions

View File

@@ -322,10 +322,10 @@ suite('Context Menu Items', function () {
});
test('Deletes all blocks after confirming', function () {
// Mocks the confirmation dialog and calls the callback with 'true'
// simulating ok.
const confirmStub = sinon.stub().callsArgWith(1, true);
Blockly.dialog.setConfirm(confirmStub);
// Mocks the confirmation dialog and calls the callback with 'true' simulating ok.
const confirmStub = sinon
.stub(Blockly.dialog.TEST_ONLY, 'confirmInternal')
.callsArgWith(1, true);
this.workspace.newBlock('text');
this.workspace.newBlock('text');
@@ -337,8 +337,9 @@ suite('Context Menu Items', function () {
test('Does not delete blocks if not confirmed', function () {
// Mocks the confirmation dialog and calls the callback with 'false' simulating cancel.
const confirmStub = sinon.stub().callsArgWith(1, false);
Blockly.dialog.setConfirm(confirmStub);
const confirmStub = sinon
.stub(Blockly.dialog.TEST_ONLY, 'confirmInternal')
.callsArgWith(1, false);
this.workspace.newBlock('text');
this.workspace.newBlock('text');
@@ -349,9 +350,10 @@ suite('Context Menu Items', function () {
});
test('No dialog for single block', function () {
const confirmStub = sinon.stub();
Blockly.dialog.setConfirm(confirmStub);
const confirmStub = sinon.stub(
Blockly.dialog.TEST_ONLY,
'confirmInternal',
);
this.workspace.newBlock('text');
this.deleteOption.callback(this.scope);
this.clock.runAll();

View File

@@ -1,58 +0,0 @@
/**
* @license
* Copyright 2024 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
suite.only('Dialog', function () {
teardown(function () {
sinon.restore();
});
suite('Prompt', function () {
test('setPrompt can take in a function with additional parameters', function () {
const spy = sinon.spy();
Blockly.dialog.setPrompt(spy);
const callback = () => {};
Blockly.dialog.prompt(
'message',
'defaultVal',
callback,
'extra parameter',
);
chai.assert.isTrue(
spy.calledWith('message', 'defaultVal', callback, 'extra parameter'),
);
});
});
suite('Confirm', function () {
test('setConfirm can take in a function with additional parameters', function () {
const spy = sinon.spy();
Blockly.dialog.setConfirm(spy);
const callback = () => {};
Blockly.dialog.confirm('message', callback, 'extra parameter');
chai.assert.isTrue(
spy.calledWith('message', callback, 'extra parameter'),
);
});
});
suite('Alert', function () {
test('setAlert can take in a function with additional parameters', function () {
const spy = sinon.spy();
Blockly.dialog.setAlert(spy);
const callback = () => {};
Blockly.dialog.alert('message', callback, 'extra parameter');
chai.assert.isTrue(
spy.calledWith('message', callback, 'extra parameter'),
);
});
});
});

View File

@@ -52,7 +52,6 @@
import './contextmenu_items_test.js';
import './contextmenu_test.js';
import './cursor_test.js';
import './dialog_test.js';
import './dropdowndiv_test.js';
import './event_test.js';
import './event_block_change_test.js';

View File

@@ -99,8 +99,9 @@ export function testAWorkspace() {
test('deleteVariableById(id2) one usage', function () {
// Deleting variable one usage should not trigger confirm dialog.
const stub = sinon.stub().callsArgWith(1, true);
Blockly.dialog.setConfirm(stub);
const stub = sinon
.stub(Blockly.dialog.TEST_ONLY, 'confirmInternal')
.callsArgWith(1, true);
this.workspace.deleteVariableById('id2');
sinon.assert.notCalled(stub);
@@ -112,8 +113,9 @@ export function testAWorkspace() {
test('deleteVariableById(id1) multiple usages confirm', function () {
// Deleting variable with multiple usages triggers confirm dialog.
const stub = sinon.stub().callsArgWith(1, true);
Blockly.dialog.setConfirm(stub);
const stub = sinon
.stub(Blockly.dialog.TEST_ONLY, 'confirmInternal')
.callsArgWith(1, true);
this.workspace.deleteVariableById('id1');
sinon.assert.calledOnce(stub);
@@ -125,8 +127,9 @@ export function testAWorkspace() {
test('deleteVariableById(id1) multiple usages cancel', function () {
// Deleting variable with multiple usages triggers confirm dialog.
const stub = sinon.stub().callsArgWith(1, false);
Blockly.dialog.setConfirm(stub);
const stub = sinon
.stub(Blockly.dialog.TEST_ONLY, 'confirmInternal')
.callsArgWith(1, false);
this.workspace.deleteVariableById('id1');
sinon.assert.calledOnce(stub);