From 4f9b4a707a00631be4ba3d4e36f9696aeb1b578c Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Fri, 3 Apr 2020 14:50:33 -0700 Subject: [PATCH] Add field set source block tests (#3796) * Set the source block on fields in mocha tests. --- tests/mocha/.eslintrc.json | 4 ++-- tests/mocha/field_angle_test.js | 5 +++++ tests/mocha/field_checkbox_test.js | 5 +++++ tests/mocha/field_colour_test.js | 5 +++++ tests/mocha/field_dropdown_test.js | 5 +++++ tests/mocha/field_label_serializable_test.js | 5 +++++ tests/mocha/field_label_test.js | 5 +++++ tests/mocha/field_number_test.js | 5 +++++ tests/mocha/field_textinput_test.js | 5 +++++ tests/mocha/test_helpers.js | 12 +++++++++++- 10 files changed, 53 insertions(+), 3 deletions(-) diff --git a/tests/mocha/.eslintrc.json b/tests/mocha/.eslintrc.json index b4bb40fec..8e3fd2a25 100644 --- a/tests/mocha/.eslintrc.json +++ b/tests/mocha/.eslintrc.json @@ -16,8 +16,8 @@ "assertNotUndefined": true, "defineStackBlock": true, "defineRowBlock": true, - "defineStatementBlock": true - + "defineStatementBlock": true, + "createTestBlock": true }, "extends": "../../.eslintrc.json" } diff --git a/tests/mocha/field_angle_test.js b/tests/mocha/field_angle_test.js index 6bbc838a4..3c59bf627 100644 --- a/tests/mocha/field_angle_test.js +++ b/tests/mocha/field_angle_test.js @@ -133,6 +133,11 @@ suite('Angle Fields', function() { this.angleField.setValue('-Infinity'); assertValueDefault(this.angleField); }); + test('With source block', function() { + this.angleField.setSourceBlock(createTestBlock()); + this.angleField.setValue(2.5); + assertValue(this.angleField, 2.5); + }); }); suite('Value -> New Value', function() { setup(function() { diff --git a/tests/mocha/field_checkbox_test.js b/tests/mocha/field_checkbox_test.js index edfdebee2..9348bbb4f 100644 --- a/tests/mocha/field_checkbox_test.js +++ b/tests/mocha/field_checkbox_test.js @@ -87,6 +87,11 @@ suite('Checkbox Fields', function() { this.checkboxField.setValue('FALSE'); assertValue(this.checkboxField, 'FALSE', 'false'); }); + test('With source block', function() { + this.checkboxField.setSourceBlock(createTestBlock()); + this.checkboxField.setValue('FALSE'); + assertValue(this.checkboxField, 'FALSE', 'false'); + }); }); suite('False -> New Value', function() { setup(function() { diff --git a/tests/mocha/field_colour_test.js b/tests/mocha/field_colour_test.js index 16878c47e..d2987a691 100644 --- a/tests/mocha/field_colour_test.js +++ b/tests/mocha/field_colour_test.js @@ -168,6 +168,11 @@ suite('Colour Fields', function() { this.colourField.setValue('red'); assertValue(this.colourField, '#ff0000', '#f00'); }); + test('With source block', function() { + this.colourField.setSourceBlock(createTestBlock()); + this.colourField.setValue('#bcbcbc'); + assertValue(this.colourField, '#bcbcbc', '#bcbcbc'); + }); }); suite('Value -> New Value', function() { setup(function() { diff --git a/tests/mocha/field_dropdown_test.js b/tests/mocha/field_dropdown_test.js index 0bbc36724..0d6e26c30 100644 --- a/tests/mocha/field_dropdown_test.js +++ b/tests/mocha/field_dropdown_test.js @@ -148,6 +148,11 @@ suite('Dropdown Fields', function() { this.dropdownField.setValue('B'); assertValue(this.dropdownField, 'B', 'b'); }); + test('With source block', function() { + this.dropdownField.setSourceBlock(createTestBlock()); + this.dropdownField.setValue('B'); + assertValue(this.dropdownField, 'B', 'b'); + }); }); suite('Validators', function() { setup(function() { diff --git a/tests/mocha/field_label_serializable_test.js b/tests/mocha/field_label_serializable_test.js index fb490a6ee..676e14fe3 100644 --- a/tests/mocha/field_label_serializable_test.js +++ b/tests/mocha/field_label_serializable_test.js @@ -136,6 +136,11 @@ suite('Label Serializable Fields', function() { this.labelField.setValue(false); assertValue(this.labelField, 'false'); }); + test('With source block', function() { + this.labelField.setSourceBlock(createTestBlock()); + this.labelField.setValue('newValue'); + assertValue(this.labelField, 'newValue'); + }); }); suite('Value -> New Value', function() { setup(function() { diff --git a/tests/mocha/field_label_test.js b/tests/mocha/field_label_test.js index b2cf8be95..fba48723c 100644 --- a/tests/mocha/field_label_test.js +++ b/tests/mocha/field_label_test.js @@ -125,6 +125,11 @@ suite('Label Fields', function() { this.labelField.setValue(false); assertValue(this.labelField, 'false'); }); + test('With source block', function() { + this.labelField.setSourceBlock(createTestBlock()); + this.labelField.setValue('newValue'); + assertValue(this.labelField, 'newValue'); + }); }); suite('Value -> New Value', function() { setup(function() { diff --git a/tests/mocha/field_number_test.js b/tests/mocha/field_number_test.js index 91edca652..c6564fad7 100644 --- a/tests/mocha/field_number_test.js +++ b/tests/mocha/field_number_test.js @@ -158,6 +158,11 @@ suite('Number Fields', function() { this.numberField.setValue('-Infinity'); assertValue(this.numberField, -Infinity); }); + test('With source block', function() { + this.numberField.setSourceBlock(createTestBlock()); + this.numberField.setValue(2.5); + assertValue(this.numberField, 2.5); + }); }); suite('Value -> New Value', function() { setup(function() { diff --git a/tests/mocha/field_textinput_test.js b/tests/mocha/field_textinput_test.js index a3acdec61..9fcbc16c4 100644 --- a/tests/mocha/field_textinput_test.js +++ b/tests/mocha/field_textinput_test.js @@ -109,6 +109,11 @@ suite('Text Input Fields', function() { this.textInputField.setValue(false); assertValue(this.textInputField, 'false'); }); + test('With source block', function() { + this.textInputField.setSourceBlock(createTestBlock()); + this.textInputField.setValue('newValue'); + assertValue(this.textInputField, 'newValue'); + }); }); suite('Value -> New Value', function() { setup(function() { diff --git a/tests/mocha/test_helpers.js b/tests/mocha/test_helpers.js index 6ff98c327..15ddc3f88 100644 --- a/tests/mocha/test_helpers.js +++ b/tests/mocha/test_helpers.js @@ -7,7 +7,7 @@ /* exported assertEquals, assertNotEquals, assertArrayEquals, assertTrue, assertFalse, assertNull, assertNotNull, assertNotNullNorUndefined, assert, isEqualArrays, assertUndefined, assertNotUndefined, - defineRowBlock, defineStackBlock, defineStatementBlock */ + defineRowBlock, defineStackBlock, defineStatementBlock, createTestBlock */ function _argumentsIncludeComments(expectedNumberOfNonCommentArgs, args) { return args.length == expectedNumberOfNonCommentArgs + 1; } @@ -181,3 +181,13 @@ function defineStatementBlock() { "helpUrl": "" }]); } + +function createTestBlock() { + return { + id: 'test', + rendered: false, + workspace: { + rendered: false + } + }; +}