mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Convert variable model tests to mocha. (#3829)
* Convert variable model tests to mocha. * Delete old jsunit test. * Updating to use chai syntax.
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
|
||||
<script src="generator_test.js"></script>
|
||||
<script src="variable_map_test.js"></script>
|
||||
<script src="variable_model_test.js"></script>
|
||||
<script src="widget_div_test.js"></script>
|
||||
<!-- Disable workspace comment tests until we include them in our build. -->
|
||||
<!-- <script src="workspace_comment_test.js"></script> -->
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Tests for variable model.
|
||||
* @author marisaleung@google.com (Marisa Leung)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var variable;
|
||||
var workspace;
|
||||
|
||||
function variableModelTest_setUp() {
|
||||
workspace = new Blockly.Workspace();
|
||||
}
|
||||
|
||||
function variableModelTest_tearDown() {
|
||||
workspace.dispose();
|
||||
variable = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* These tests check the constructor of the variable model.
|
||||
*/
|
||||
function testInit_Trivial() {
|
||||
variableModelTest_setUp();
|
||||
variable = new Blockly.VariableModel(workspace, 'test', 'test_type',
|
||||
'test_id');
|
||||
assertEquals('test', variable.name);
|
||||
assertEquals('test_type', variable.type);
|
||||
assertEquals('test_id', variable.id_);
|
||||
variableModelTest_tearDown();
|
||||
}
|
||||
|
||||
function testInit_NullType() {
|
||||
variableModelTest_setUp();
|
||||
variable = new Blockly.VariableModel(workspace, 'test', null, 'test_id');
|
||||
assertEquals('', variable.type);
|
||||
variableModelTest_tearDown();
|
||||
}
|
||||
|
||||
function testInit_UndefinedType() {
|
||||
variableModelTest_setUp();
|
||||
variable = new Blockly.VariableModel(workspace, 'test', undefined, 'test_id');
|
||||
assertEquals('', variable.type);
|
||||
variableModelTest_tearDown();
|
||||
}
|
||||
|
||||
function testInit_NullId() {
|
||||
variableModelTest_setUp();
|
||||
variable = new Blockly.VariableModel(workspace, 'test', 'test_type', null);
|
||||
assertEquals('test', variable.name);
|
||||
assertEquals('test_type', variable.type);
|
||||
assertNotNull(variable.id_);
|
||||
variableModelTest_tearDown();
|
||||
}
|
||||
|
||||
function testInit_UndefinedId() {
|
||||
variableModelTest_setUp();
|
||||
variable = new Blockly.VariableModel(workspace, 'test', 'test_type', undefined);
|
||||
assertEquals('test', variable.name);
|
||||
assertEquals('test_type', variable.type);
|
||||
assertNotNull(variable.id_);
|
||||
variableModelTest_tearDown();
|
||||
}
|
||||
|
||||
function testInit_OnlyNameProvided() {
|
||||
variableModelTest_setUp();
|
||||
variable = new Blockly.VariableModel(workspace, 'test');
|
||||
assertEquals('test', variable.name);
|
||||
assertEquals('', variable.type);
|
||||
assertNotNull(variable.id_);
|
||||
variableModelTest_tearDown();
|
||||
}
|
||||
@@ -60,6 +60,7 @@
|
||||
<script src="trashcan_test.js"></script>
|
||||
<script src="utils_test.js"></script>
|
||||
<script src="variables_test.js"></script>
|
||||
<script src="variable_model_test.js"></script>
|
||||
<script src="xml_procedures_test.js"></script>
|
||||
<script src="xml_test.js"></script>
|
||||
|
||||
|
||||
58
tests/mocha/variable_model_test.js
Normal file
58
tests/mocha/variable_model_test.js
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
suite('Variable Model', function() {
|
||||
setup(function() {
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
this.workspace.dispose();
|
||||
});
|
||||
|
||||
test('Trivial', function() {
|
||||
var variable = new Blockly.VariableModel(
|
||||
this.workspace, 'test', 'test_type', 'test_id');
|
||||
chai.assert.equal(variable.name, 'test');
|
||||
chai.assert.equal(variable.type, 'test_type');
|
||||
chai.assert.equal(variable.id_, 'test_id');
|
||||
});
|
||||
|
||||
test('Null type', function() {
|
||||
var variable = new Blockly.VariableModel(
|
||||
this.workspace, 'test', null, 'test_id');
|
||||
chai.assert.equal(variable.type, '');
|
||||
});
|
||||
|
||||
test('Undefined type', function() {
|
||||
var variable = new Blockly.VariableModel(
|
||||
this.workspace, 'test', undefined, 'test_id');
|
||||
chai.assert.equal(variable.type, '');
|
||||
});
|
||||
|
||||
test('Null id', function() {
|
||||
var variable = new Blockly.VariableModel(
|
||||
this.workspace, 'test', 'test_type', null);
|
||||
chai.assert.equal(variable.name, 'test');
|
||||
chai.assert.equal(variable.type, 'test_type');
|
||||
chai.assert.exists(variable.id_);
|
||||
});
|
||||
|
||||
test('Undefined id', function() {
|
||||
var variable = new Blockly.VariableModel(
|
||||
this.workspace, 'test', 'test_type', undefined);
|
||||
chai.assert.equal(variable.name, 'test');
|
||||
chai.assert.equal(variable.type, 'test_type');
|
||||
chai.assert.exists(variable.id_);
|
||||
});
|
||||
|
||||
test('Only name provided', function() {
|
||||
var variable = new Blockly.VariableModel(this.workspace, 'test');
|
||||
chai.assert.equal(variable.name, 'test');
|
||||
chai.assert.equal(variable.type, '');
|
||||
chai.assert.exists(variable.id_);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user