From 9741cd25306d084c69a768a395bdaa3f782241db Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Mon, 5 Dec 2022 10:30:28 -0800 Subject: [PATCH] chore: add simple round tripping tests (#6668) --- .../event_procedure_change_return_test.js | 20 ++++++++++++++--- tests/mocha/event_procedure_create_test.js | 13 +++++++++++ tests/mocha/event_procedure_delete_test.js | 16 ++++++++++++-- tests/mocha/event_procedure_enable_test.js | 16 ++++++++++++-- .../event_procedure_parameter_create_test.js | 22 +++++++++++++++++-- .../event_procedure_parameter_delete_test.js | 18 +++++++++++++++ .../event_procedure_parameter_rename_test.js | 18 +++++++++++++++ tests/mocha/event_procedure_rename_test.js | 20 ++++++++++++++--- 8 files changed, 131 insertions(+), 12 deletions(-) diff --git a/tests/mocha/event_procedure_change_return_test.js b/tests/mocha/event_procedure_change_return_test.js index 0e11458d6..63b265cb1 100644 --- a/tests/mocha/event_procedure_change_return_test.js +++ b/tests/mocha/event_procedure_change_return_test.js @@ -11,6 +11,9 @@ import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown suite('Procedure Change Return Event', function() { + const DEFAULT_TYPES = null; + const NON_DEFAULT_TYPES = []; + setup(function() { sharedTestSetup.call(this); this.workspace = new Blockly.Workspace(); @@ -23,9 +26,6 @@ suite('Procedure Change Return Event', function() { }); suite('running', function() { - const DEFAULT_TYPES = null; - const NON_DEFAULT_TYPES = []; - setup(function() { this.createProcedureModel = (id) => { return new Blockly.procedures.ObservableProcedureModel( @@ -180,4 +180,18 @@ suite('Procedure Change Return Event', function() { }); }); }); + + suite.skip('serialization', function() { + test('events round-trip through JSON', function() { + const model = new Blockly.procedures.ObservableProcedureModel( + this.workspace, 'test name', 'test id'); + const origEvent = new Blockly.Events.ProcedureChangeReturn( + this.workspace, model, NON_DEFAULT_TYPES); + + const json = origEvent.toJson(); + const newEvent = new Blockly.Events.fromJson(json, this.workspace); + + chai.assert.deepEqual(newEvent, origEvent); + }); + }); }); diff --git a/tests/mocha/event_procedure_create_test.js b/tests/mocha/event_procedure_create_test.js index 1455d3afe..d74b56463 100644 --- a/tests/mocha/event_procedure_create_test.js +++ b/tests/mocha/event_procedure_create_test.js @@ -145,4 +145,17 @@ suite('Procedure Create Event', function() { }); }); }); + + suite.skip('serialization', function() { + test('events round-trip through JSON', function() { + const model = new Blockly.procedures.ObservableProcedureModel( + this.workspace, 'test name', 'test id'); + const origEvent = new Blockly.Events.ProcedureCreate(this.workspace, model); + + const json = origEvent.toJson(); + const newEvent = new Blockly.Events.fromJson(json, this.workspace); + + chai.assert.deepEqual(newEvent, origEvent); + }); + }); }); diff --git a/tests/mocha/event_procedure_delete_test.js b/tests/mocha/event_procedure_delete_test.js index 20f41a191..4db5d8ab6 100644 --- a/tests/mocha/event_procedure_delete_test.js +++ b/tests/mocha/event_procedure_delete_test.js @@ -30,8 +30,7 @@ suite('Procedure Delete Event', function() { }; this.createEventToState = (procedureModel) => { - return new Blockly.Events.ProcedureDelete( - this.workspace, procedureModel); + return new Blockly.Events.ProcedureDelete(this.workspace, procedureModel); }; }); @@ -146,4 +145,17 @@ suite('Procedure Delete Event', function() { }); }); }); + + suite.skip('serialization', function() { + test('events round-trip through JSON', function() { + const model = new Blockly.procedures.ObservableProcedureModel( + this.workspace, 'test name', 'test id'); + const origEvent = new Blockly.Events.ProcedureDelete(this.workspace, model); + + const json = origEvent.toJson(); + const newEvent = new Blockly.Events.fromJson(json, this.workspace); + + chai.assert.deepEqual(newEvent, origEvent); + }); + }); }); diff --git a/tests/mocha/event_procedure_enable_test.js b/tests/mocha/event_procedure_enable_test.js index 9617d4c7d..7f753fc1a 100644 --- a/tests/mocha/event_procedure_enable_test.js +++ b/tests/mocha/event_procedure_enable_test.js @@ -30,8 +30,7 @@ suite('Procedure Enable Event', function() { }; this.createEventToState = (procedureModel) => { - return new Blockly.Events.ProcedureEnable( - this.workspace, procedureModel); + return new Blockly.Events.ProcedureEnable(this.workspace, procedureModel); }; }); @@ -172,4 +171,17 @@ suite('Procedure Enable Event', function() { }); }); }); + + suite.skip('serialization', function() { + test('events round-trip through JSON', function() { + const model = new Blockly.procedures.ObservableProcedureModel( + this.workspace, 'test name', 'test id'); + const origEvent = new Blockly.Events.ProcedureEnable(this.workspace, model); + + const json = origEvent.toJson(); + const newEvent = new Blockly.Events.fromJson(json, this.workspace); + + chai.assert.deepEqual(newEvent, origEvent); + }); + }); }); diff --git a/tests/mocha/event_procedure_parameter_create_test.js b/tests/mocha/event_procedure_parameter_create_test.js index 88c214d24..4cfeb34ea 100644 --- a/tests/mocha/event_procedure_parameter_create_test.js +++ b/tests/mocha/event_procedure_parameter_create_test.js @@ -32,9 +32,9 @@ suite('Procedure Parameter Create Event', function() { this.createProcedureAndParameter = (procName, procId, paramName, paramId) => { const param = new Blockly.procedures.ObservableParameterModel( - this.workspace, procName, paramId); + this.workspace, paramName, paramId); const proc = new Blockly.procedures.ObservableProcedureModel( - this.workspace, paramName, procId) + this.workspace, procName, procId) .insertParameter(param, 0); return {param, proc}; }; @@ -196,4 +196,22 @@ suite('Procedure Parameter Create Event', function() { }); }); }); + + suite.skip('serialization', function() { + test('events round-trip through JSON', function() { + const param = new Blockly.procedures.ObservableParameterModel( + this.workspace, 'test param name', 'test param id'); + const model = + new Blockly.procedures.ObservableProcedureModel( + this.workspace, 'test name', 'test id') + .insertParameter(param, 0); + const origEvent = new Blockly.Events.ProcedureParameterCreate( + this.workspace, model); + + const json = origEvent.toJson(); + const newEvent = new Blockly.Events.fromJson(json, this.workspace); + + chai.assert.deepEqual(newEvent, origEvent); + }); + }); }); diff --git a/tests/mocha/event_procedure_parameter_delete_test.js b/tests/mocha/event_procedure_parameter_delete_test.js index 16cebd904..3de6226e1 100644 --- a/tests/mocha/event_procedure_parameter_delete_test.js +++ b/tests/mocha/event_procedure_parameter_delete_test.js @@ -196,4 +196,22 @@ suite('Procedure Parameter Delete Event', function() { }); }); }); + + suite.skip('serialization', function() { + test('events round-trip through JSON', function() { + const param = new Blockly.procedures.ObservableParameterModel( + this.workspace, 'test param name', 'test param id'); + const model = + new Blockly.procedures.ObservableProcedureModel( + this.workspace, 'test name', 'test id') + .insertParameter(param, 0); + const origEvent = new Blockly.Events.ProcedureParameterDelete( + this.workspace, model); + + const json = origEvent.toJson(); + const newEvent = new Blockly.Events.fromJson(json, this.workspace); + + chai.assert.deepEqual(newEvent, origEvent); + }); + }); }); diff --git a/tests/mocha/event_procedure_parameter_rename_test.js b/tests/mocha/event_procedure_parameter_rename_test.js index 7a7de0457..39f75662d 100644 --- a/tests/mocha/event_procedure_parameter_rename_test.js +++ b/tests/mocha/event_procedure_parameter_rename_test.js @@ -203,4 +203,22 @@ suite('Procedure Parameter Rename Event', function() { }); }); }); + + suite.skip('serialization', function() { + test('events round-trip through JSON', function() { + const param = new Blockly.procedures.ObservableParameterModel( + this.workspace, 'test param name', 'test param id'); + const model = + new Blockly.procedures.ObservableProcedureModel( + this.workspace, 'test name', 'test id') + .insertParameter(param, 0); + const origEvent = new Blockly.Events.ProcedureParameterDelete( + this.workspace, model); + + const json = origEvent.toJson(); + const newEvent = new Blockly.Events.fromJson(json, this.workspace); + + chai.assert.deepEqual(newEvent, origEvent); + }); + }); }); diff --git a/tests/mocha/event_procedure_rename_test.js b/tests/mocha/event_procedure_rename_test.js index 162e216eb..1ae69f529 100644 --- a/tests/mocha/event_procedure_rename_test.js +++ b/tests/mocha/event_procedure_rename_test.js @@ -11,6 +11,9 @@ import {sharedTestSetup, sharedTestTeardown} from './test_helpers/setup_teardown suite('Procedure Rename Event', function() { + const DEFAULT_NAME = 'default'; + const NON_DEFAULT_NAME = 'non-default'; + setup(function() { sharedTestSetup.call(this); this.workspace = new Blockly.Workspace(); @@ -23,9 +26,6 @@ suite('Procedure Rename Event', function() { }); suite('running', function() { - const DEFAULT_NAME = 'default'; - const NON_DEFAULT_NAME = 'non-default'; - setup(function() { this.createProcedureModel = (id) => { return new Blockly.procedures.ObservableProcedureModel( @@ -168,4 +168,18 @@ suite('Procedure Rename Event', function() { }); }); }); + + suite.skip('serialization', function() { + test('events round-trip through JSON', function() { + const model = new Blockly.procedures.ObservableProcedureModel( + this.workspace, 'test name', 'test id'); + const origEvent = new Blockly.Events.ProcedureRename( + this.workspace, model, NON_DEFAULT_NAME); + + const json = origEvent.toJson(); + const newEvent = new Blockly.Events.fromJson(json, this.workspace); + + chai.assert.deepEqual(newEvent, origEvent); + }); + }); });