Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add tests for the insertion marker manager #6596

Merged
merged 6 commits into from
Nov 3, 2022

Conversation

rachel-fenichel
Copy link
Collaborator

@rachel-fenichel rachel-fenichel commented Nov 1, 2022

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide
  • I ran npm run format and npm run lint

The details

Resolves

Just improving test coverage.

Proposed Changes

Add tests.

Test Coverage

There are four test suites.

The first one checks that the constructor works when given various blocks and block stacks, and that the appropriate number of markers is created (i.e. one marker for the first block, and sometimes another for the last block in the stack).

The second suite checks logic controlling whether a block is deleted when the drag ends. I stubbed the capability manager and drag target to force it down various paths. wouldDeleteBlock is one of the few public methods available to get information out of the insertion marker manager.

The third and fourth suites check that the insertion marker manager can find an appropriate connection in the middle of a drag. I faked dragging the block above, below, left, and right from the stationary block, and then checked the connections on the marker to make sure it was connected in the correct place.

Documentation

No documentation needed.

Additional Information

These tests will hopefully catch any bugs in an upcoming cleanup of the insertion marker manager.

Live footage of me working on this PR:
penguin-angry

Copy link
Collaborator

@BeksOmega BeksOmega left a comment

Choose a reason for hiding this comment

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

Generally looks really good! Unit tests make me so happy haha.

One high-level thing: How would you feel about renaming some stuff? I really like this convention, because I think it makes it very clear what each suite/test is doing:

  • suites: This tests '___' E.g.
    suite('Creating markers', function() { })
    
  • tests: This tests that '___' E.g.
    test('a single stack block results in a single marker block', function() { });
    

[Edit: one other high-level thing, it looks like the indentation is using 4 spaces for this file]

};
const manager = createBlocksAndManager(this.workspace, state);
const markers = manager.getInsertionMarkers();
chai.assert.equal(markers.length, 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not a comment about the contents of the test (that looks great!), but why is this the intended behavior?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

6ad23110-bfe4-4972-9ce2-d61833d19ba4

If you have multiple row blocks in a row, we don't offer to connect to the end of the row.

I don't know why, though. Some things that come to mind:

  • Value inputs/outputs often have type checks, so often it's not allowed anyway
  • Distance from mouse pointer gets large fast (when compared to stacks)

chai.assert.equal(markers.length, 1);
});

test('Two stack blocks', function() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How does this handle stacks where the top block in the stack has an ouput instead of a previous connection?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

aed92412-a07b-41e3-bd44-2345cadeeeaf

Two markers! I'll have to add a different test block for that.

And if the output + next block is the only block in the stack, it's one marker (I think).
3528aee7-1b85-4aa5-8ee2-5f90ebdffbde

tests/mocha/insertion_marker_manager_test.js Outdated Show resolved Hide resolved
tests/mocha/insertion_marker_manager_test.js Outdated Show resolved Hide resolved
this.manager.update(new Blockly.utils.Coordinate(200, 190), null);
chai.assert.isTrue(this.manager.wouldConnectBlock());
const markers = this.manager.getInsertionMarkers();
chai.assert.equal(markers.length, 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What are these assertions checking? These look like dupes of the 'Create markers' assertions, can they be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Checking that it's safe to call markers[0].nextConnection.isConnected. But I can remove the assertions on markers.length and assume that if I'm wrong the test will still fail on the next access. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good to me!

tests/mocha/insertion_marker_manager_test.js Outdated Show resolved Hide resolved
tests/mocha/insertion_marker_manager_test.js Outdated Show resolved Hide resolved
Copy link
Collaborator Author

@rachel-fenichel rachel-fenichel left a comment

Choose a reason for hiding this comment

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

Re: naming convention: I'm not a huge fan, because it leads to really verbose names of the tests, especially when they're doing similar things. I'm mostly resigned to using the name of the test as a hint, but needing to read it to really understand what it's testing.

};
const manager = createBlocksAndManager(this.workspace, state);
const markers = manager.getInsertionMarkers();
chai.assert.equal(markers.length, 1);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

6ad23110-bfe4-4972-9ce2-d61833d19ba4

If you have multiple row blocks in a row, we don't offer to connect to the end of the row.

I don't know why, though. Some things that come to mind:

  • Value inputs/outputs often have type checks, so often it's not allowed anyway
  • Distance from mouse pointer gets large fast (when compared to stacks)

tests/mocha/insertion_marker_manager_test.js Outdated Show resolved Hide resolved
tests/mocha/insertion_marker_manager_test.js Outdated Show resolved Hide resolved
this.manager.update(new Blockly.utils.Coordinate(200, 190), null);
chai.assert.isTrue(this.manager.wouldConnectBlock());
const markers = this.manager.getInsertionMarkers();
chai.assert.equal(markers.length, 1);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Checking that it's safe to call markers[0].nextConnection.isConnected. But I can remove the assertions on markers.length and assume that if I'm wrong the test will still fail on the next access. What do you think?

tests/mocha/insertion_marker_manager_test.js Outdated Show resolved Hide resolved
chai.assert.equal(markers.length, 1);
});

test('Two stack blocks', function() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

aed92412-a07b-41e3-bd44-2345cadeeeaf

Two markers! I'll have to add a different test block for that.

And if the output + next block is the only block in the stack, it's one marker (I think).
3528aee7-1b85-4aa5-8ee2-5f90ebdffbde

Copy link
Collaborator

@BeksOmega BeksOmega left a comment

Choose a reason for hiding this comment

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

Re: naming convention: I'm not a huge fan, because it leads to really verbose names of the tests, especially when they're doing similar things. I'm mostly resigned to using the name of the test as a hint, but needing to read it to really understand what it's testing.

I'm gonna push back against this one more time, (this time with evidence!) but also approving so you can go ahead and merge if you really disagree =)

@rachel-fenichel
Copy link
Collaborator Author

Okay I updated test names and also added tests for the row to stack block.

Copy link
Collaborator

@BeksOmega BeksOmega left a comment

Choose a reason for hiding this comment

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

LGTM

@rachel-fenichel rachel-fenichel merged commit 82dc966 into google:develop Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants