Skip to content

Add type and id info to xml#1112

Merged
marisaleung merged 1 commit intoRaspberryPiFoundation:developfrom
marisaleung:Add_type_and_id_info_to_xml
May 19, 2017
Merged

Add type and id info to xml#1112
marisaleung merged 1 commit intoRaspberryPiFoundation:developfrom
marisaleung:Add_type_and_id_info_to_xml

Conversation

@marisaleung
Copy link
Copy Markdown
Contributor

@marisaleung marisaleung commented May 18, 2017

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 Reviewable

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());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you trying to create a variable right after getting it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meant to remove that. Fixing test and will push that change.

Copy link
Copy Markdown
Contributor

@RoboErikG RoboErikG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a description to the change since you're doing more than just adding type/id to xml in this PR?

* @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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkVariable or checkFieldVariable -> checkVariableDomValues since this is specific to variable fields and can't be used for other fields.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good point. Thanks!
Done.

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')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I updated it so it should be more clear.

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')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a test for the default case where type and id weren't specified (so type = '' and id is any string)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mean when createVariable doesn't specify a type or id. If not, let me know.
Done.

@marisaleung marisaleung force-pushed the Add_type_and_id_info_to_xml branch 2 times, most recently from 7944e8c to c9fcfdf Compare May 18, 2017 21:06
@marisaleung
Copy link
Copy Markdown
Contributor Author

I added a description and I rebased to get rid of the other commit so the description of this PR should be accurate now.

@RoboErikG
Copy link
Copy Markdown
Contributor

:lgtm:


Review status: 0 of 3 files reviewed at latest revision, all discussions resolved.


Comments from Reviewable

@rachel-fenichel
Copy link
Copy Markdown
Collaborator

Reviewed 1 of 3 files at r1.
Review status: 1 of 3 files reviewed at latest revision, 3 unresolved discussions.


core/flyout.js, line 256 at r1 (raw file):

  this.workspace_.getGesture =
      this.targetWorkspace_.getGesture.bind(this.targetWorkspace_);
  // A flyout connected to a workspace doesn't have the updated variable map.

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
this.workspace_.useVariableMapFrom(this.targetWorkspace_), which internally calls getVariableMap on the other workspace.


tests/jsunit/xml_test.js, line 87 at r1 (raw file):

/**
 * Check the values of the field dom.

"Check the values of the variable field DOM."


tests/jsunit/xml_test.js, line 199 at r1 (raw file):

function test_blockToDom_fieldToDom_defaultCase() {
  // Expect type is '' and id is '1' since we don't specify type and id.

Move this to just above xmlTests_checkVariableDomValues


Comments from Reviewable

@rachel-fenichel
Copy link
Copy Markdown
Collaborator

:lgtm:


Review status: 1 of 3 files reviewed at latest revision, 3 unresolved discussions.


Comments from Reviewable

@marisaleung
Copy link
Copy Markdown
Contributor Author

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…

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
this.workspace_.useVariableMapFrom(this.targetWorkspace_), which internally calls getVariableMap on the other workspace.

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…

"Check the values of the variable field DOM."

Done.


tests/jsunit/xml_test.js, line 199 at r1 (raw file):

Previously, rachel-fenichel (Rachel Fenichel) wrote…

Move this to just above xmlTests_checkVariableDomValues

Done.


Comments from Reviewable

Add xml tests for fieldToDom.
Update workspace tests to pass with new changes.
@marisaleung marisaleung force-pushed the Add_type_and_id_info_to_xml branch from c9fcfdf to 1cd8e1f Compare May 19, 2017 22:48
@marisaleung marisaleung merged commit 90eeaae into RaspberryPiFoundation:develop May 19, 2017
@marisaleung marisaleung deleted the Add_type_and_id_info_to_xml branch May 23, 2017 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants