Add type and id info to xml#1112
Conversation
core/xml.js
Outdated
| container.setAttribute('name', field.name); | ||
| if (field instanceof Blockly.FieldVariable) { | ||
| var variable = block.workspace.getVariable(field.getValue()); | ||
| variable = block.workspace.createVariable(field.getValue()); |
There was a problem hiding this comment.
Why are you trying to create a variable right after getting it?
There was a problem hiding this comment.
Meant to remove that. Fixing test and will push that change.
RoboErikG
left a comment
There was a problem hiding this comment.
Could you also add a description to the change since you're doing more than just adding type/id to xml in this PR?
tests/jsunit/xml_test.js
Outdated
| * @param {!string} id The expected id of the variable. | ||
| * @param {!string} id The expected text of the variable. | ||
| */ | ||
| function xmlTest_checkFieldDomValues(fieldDom, name, type, id, text) { |
There was a problem hiding this comment.
checkVariable or checkFieldVariable -> checkVariableDomValues since this is specific to variable fields and can't be used for other fields.
There was a problem hiding this comment.
That is a good point. Thanks!
Done.
tests/jsunit/xml_test.js
Outdated
| xmlTest_setUpWithMockBlocks() | ||
| var block = new Blockly.Block(workspace, 'field_angle_test_block'); | ||
| var resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0]; | ||
| xmlTest_checkFieldDomValues(resultFieldDom, 'VAR', null, null, '90') |
There was a problem hiding this comment.
This feels kind of hacky. The id and type are specific to variables but you're passing in null because it's not a variable. You probably want a separate method for checking non-variable fields.
There was a problem hiding this comment.
You are right, I updated it so it should be more clear.
tests/jsunit/xml_test.js
Outdated
| var block = new Blockly.Block(workspace, 'field_variable_test_block'); | ||
| block.inputList[0].fieldRow[0].setValue('name1'); | ||
| var resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0]; | ||
| xmlTest_checkFieldDomValues(resultFieldDom, 'VAR', 'type1', 'id1', 'name1') |
There was a problem hiding this comment.
Also add a test for the default case where type and id weren't specified (so type = '' and id is any string)
There was a problem hiding this comment.
I think you mean when createVariable doesn't specify a type or id. If not, let me know.
Done.
7944e8c to
c9fcfdf
Compare
|
I added a description and I rebased to get rid of the other commit so the description of this PR should be accurate now. |
|
Review status: 0 of 3 files reviewed at latest revision, all discussions resolved. Comments from Reviewable |
|
Reviewed 1 of 3 files at r1. core/flyout.js, line 256 at r1 (raw file):
This is solving a different problem from the rest of this code, yes? If so, you can submit with this code and then make the fix I'm suggesting in a separate PR. You're reaching into private variables twice in one line. I'd rather you call a function like tests/jsunit/xml_test.js, line 87 at r1 (raw file):
"Check the values of the variable field DOM." tests/jsunit/xml_test.js, line 199 at r1 (raw file):
Move this to just above xmlTests_checkVariableDomValues Comments from Reviewable |
|
Review status: 1 of 3 files reviewed at latest revision, 3 unresolved discussions. Comments from Reviewable |
|
Review status: 1 of 3 files reviewed at latest revision, 3 unresolved discussions. core/flyout.js, line 256 at r1 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
Offline we decided to overwrite the function this.workspace_.getVariable() and this.workspace_.getVariableById() to refer to targetWorkspace_.variableMap_. Done on a separate CL. tests/jsunit/xml_test.js, line 87 at r1 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
Done. tests/jsunit/xml_test.js, line 199 at r1 (raw file): Previously, rachel-fenichel (Rachel Fenichel) wrote…
Done. Comments from Reviewable |
Add xml tests for fieldToDom. Update workspace tests to pass with new changes.
c9fcfdf to
1cd8e1f
Compare
Add type and id info to generated xml.
Changed flyout's variable map to point to target workspace's variable map.
Wrote tests for FieldToDom() change in xml_tests.js
This change is