Changed utils.fields -> fieldRegistry. Also removed useless tooltip requires.

This commit is contained in:
Beka Westberg
2019-08-08 19:42:16 -07:00
parent 84937a0ff6
commit 0872d022e1
15 changed files with 53 additions and 57 deletions

View File

@@ -19,12 +19,12 @@
*/
/**
* @fileoverview Tests for Blockly.utils.fields
* @author bekawestberg@gmail.com (Beka WEstberg)
* @fileoverview Tests for Blockly.fieldRegistry
* @author bekawestberg@gmail.com (Beka Westberg)
*/
'use strict';
suite('Field Utils', function() {
suite('Field Registry', function() {
function CustomFieldType(value) {
CustomFieldType.superClass_.constructor.call(this, value);
}
@@ -34,45 +34,45 @@ suite('Field Utils', function() {
};
teardown(function() {
if (Blockly.utils.fields.typeMap_['field_custom_test']) {
delete Blockly.utils.fields.typeMap_['field_custom_test'];
if (Blockly.fieldRegistry.typeMap_['field_custom_test']) {
delete Blockly.fieldRegistry.typeMap_['field_custom_test'];
}
});
suite('Registration', function() {
test('Simple', function() {
Blockly.utils.fields.register('field_custom_test', CustomFieldType);
Blockly.fieldRegistry.register('field_custom_test', CustomFieldType);
});
test('Empty String Key', function() {
chai.assert.throws(function() {
Blockly.utils.fields.register('', CustomFieldType);
Blockly.fieldRegistry.register('', CustomFieldType);
}.bind(this), 'Invalid field type');
});
test('Class as Key', function() {
chai.assert.throws(function() {
Blockly.utils.fields.register(CustomFieldType, '');
Blockly.fieldRegistry.register(CustomFieldType, '');
}.bind(this), 'Invalid field type');
});
test('fromJson as Key', function() {
chai.assert.throws(function() {
Blockly.utils.fields.register(CustomFieldType.fromJson, '');
Blockly.fieldRegistry.register(CustomFieldType.fromJson, '');
}.bind(this), 'Invalid field type');
});
// TODO (#2788): What do you want it to do if you overwrite a key?
test('Overwrite a Key', function() {
Blockly.utils.fields.register('field_custom_test', CustomFieldType);
Blockly.fieldRegistry.register('field_custom_test', CustomFieldType);
Blockly.utils.fields.register('field_custom_test', CustomFieldType);
Blockly.fieldRegistry.register('field_custom_test', CustomFieldType);
});
test('Null Value', function() {
chai.assert.throws(function() {
Blockly.utils.fields.register('field_custom_test', null);
Blockly.fieldRegistry.register('field_custom_test', null);
}.bind(this), 'fromJson function');
});
test('No fromJson', function() {
var fromJson = CustomFieldType.fromJson;
delete CustomFieldType.fromJson;
chai.assert.throws(function() {
Blockly.utils.fields.register('field_custom_test', CustomFieldType);
Blockly.fieldRegistry.register('field_custom_test', CustomFieldType);
}.bind(this), 'fromJson function');
CustomFieldType.fromJson = fromJson;
});
@@ -80,21 +80,21 @@ suite('Field Utils', function() {
var fromJson = CustomFieldType.fromJson;
CustomFieldType.fromJson = true;
chai.assert.throws(function() {
Blockly.utils.fields.register('field_custom_test', CustomFieldType);
Blockly.fieldRegistry.register('field_custom_test', CustomFieldType);
}.bind(this), 'fromJson function');
CustomFieldType.fromJson = fromJson;
});
});
suite('Retrieval', function() {
test('Simple', function() {
Blockly.utils.fields.register('field_custom_test', CustomFieldType);
Blockly.fieldRegistry.register('field_custom_test', CustomFieldType);
var json = {
type: 'field_custom_test',
value: 'ok'
};
var field = Blockly.utils.fields.fromJson(json);
var field = Blockly.fieldRegistry.fromJson(json);
chai.assert.isNotNull(field);
chai.assert.equal('ok', field.getValue());
});
@@ -105,21 +105,21 @@ suite('Field Utils', function() {
};
var spy = sinon.stub(console, 'warn');
var field = Blockly.utils.fields.fromJson(json);
var field = Blockly.fieldRegistry.fromJson(json);
chai.assert.isNull(field);
chai.assert.isTrue(spy.called);
spy.restore();
});
// TODO: Is this supposed to be case sensitive?
test.skip('Case Different', function() {
Blockly.utils.fields.register('field_custom_test', CustomFieldType);
Blockly.fieldRegistry.register('field_custom_test', CustomFieldType);
var json = {
type: 'FIELD_CUSTOM_TEST',
value: 'ok'
};
var field = Blockly.utils.fields.fromJson(json);
var field = Blockly.fieldRegistry.fromJson(json);
chai.assert.isNotNull(field);
chai.assert.equal('ok', field.getValue());
});

View File

@@ -48,7 +48,7 @@
<script src="procedures_test.js"></script>
<script src="trashcan_test.js"></script>
<script src="utils_test.js"></script>
<script src="utils_field_test.js"></script>
<script src="field_registry_test.js"></script>
<script src="xml_test.js"></script>
<div id="blocklyDiv"></div>