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

UpdateLog tests #1

Merged
merged 39 commits into from
May 18, 2018
Merged

UpdateLog tests #1

merged 39 commits into from
May 18, 2018

Conversation

rauanmayemir
Copy link
Member

@rauanmayemir rauanmayemir commented Apr 12, 2018

This introduces UpdateLog tests. UpdateLog is a data structure which contains a description of mutations to the instance tree in order to get to the desired state.

The most important part is subTreeChange which highlights the type of subtree change.

  • Nested means that the underlying subtree did change but it was an element deep down the tree.
  • NoChange means that the tree has not changed.
  • ReplaceElements means that a subtree should be replaced
  • PrependElement means that an element should be prepended

Todos:

  • Improve formatting in tests. I want to handle this first since poor readability affects productivity a lot
  • Determine why the existing test is failing :)
  • Implement tests which verify the UpdateLog step by step. It's important since we can determine that the minimal amount of steps is indeed in the UpdateLog.
  • Test applyUpdateLog. The tree from applyUpdateLog should be the same as newly returned element.
  • Introduce side effects in applyUpdateLog
  • applyUpdateLog should perform mutations to the tree and invoke render-cycle lifecycle functions. In order to test that we should build a list of all mutations and lifecycle function invocations and assert if they happen. Similar to what we do with UpdateLog. The RenderUpdateLog however will only be a part of tests. Also, in order to test it properly we need to introduce mutations to the TestRenderer because currently the hostView is immutable.
  • add tests for prependElement
  • Remember to include updateInstance in the tests Test `ContentChanged

Determining the subtree change at the reconciliation time lets us
perform minimal changes to the underlying views.

It also introduces formatting testInstances as JSX
@wokalski
Copy link
Member

I think we should also squash [294ab97... f17cd5e] Into Add SwitchComponent to UpdateLog and introduce topLevelUpdate.

@wokalski
Copy link
Member

ec8e2bd -> ReactCore refactor?

Copy link
Member

@wokalski wokalski left a comment

Choose a reason for hiding this comment

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

There's one conclusion from this: we've got bugs. There's also another conclusion, there are parts I don't understand. I believe these are not very simple fixes but they are necessary.

test/Test.re Outdated
],
Some(
TestRenderer.{
subtreeChange: `Nested,
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't make sense. If this caused `Nested, what triggers ReplaceElements for the top level update?

Copy link
Member Author

Choose a reason for hiding this comment

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

If I'm understanding this correctly, ReplaceElements is triggered only when we're replacing children element with a list of new elements (or inserting a list of new elements into the empty subtree).

I suggest we do a complete overhaul of UpdateLog types and outline all possible scenarios how updates could happen. (we could reuse our existing test suites establishing the correct expected output and work towards making the actual output match)

Copy link
Member

Choose a reason for hiding this comment

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

I applaud this suggestion.

test/Test.re Outdated
ref([
UpdateInstance({
stateChanged: true,
subTreeChanged: `NoChange,
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't make sense - the subtree didn't change but the content has changed. It'll probably require something like shouldUpdateContent on the nativeElement... (Although it'd be awesome to avoid that.)

test/Test.re Outdated
elem
),
(
"Test Lists With Dynamic Keys",
Copy link
Member

Choose a reason for hiding this comment

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

What are dynamic keys?

test/Test.re Outdated
subTreeChanged:
`ReplaceElements((
[<Box id=2 state="Hello" />],
[<Box id=3 state="World" />, <Box id=4 state="Hello" />]
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be PrependElement? If not, why? Actually, it shouldn't be, but why not? We need to document this.

test/Test.re Outdated
}
),
(
"Deep Move Box With Dynamic Keys",
Copy link
Member

Choose a reason for hiding this comment

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

Interesting... but how it happens?

test/Test.re Outdated
TestRenderer.update(
rendered3,
<ButtonWrapperWrapper wrappedText="updatedTextmodified" />
/* TODO Compare rendered0 and rendered1 */
Copy link
Member

Choose a reason for hiding this comment

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

It seems like an unfinished test.

test/Test.re Outdated
ref([
UpdateInstance({
stateChanged: true,
subTreeChanged: `NoChange,
Copy link
Member

Choose a reason for hiding this comment

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

Again, this should yield that the context has changed.

test/Test.re Outdated
],
Some(
TestRenderer.{
subtreeChange: `Nested,
Copy link
Member

Choose a reason for hiding this comment

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

What we've done in this test is reversing the order of boxes. It's not reflected in the subtreeChange... It'd cause lack of rerender/relayout which in turn would cause a visual bug. How will we solve this?

test/Test.re Outdated
TestRenderer.convertElement(rendered)
|> check(renderedElement, "Initial", result(~state="0", ~text="0"));
RemoteAction.act(rAction, ~action=Click);
let (rendered, _) = RenderedElement.flushPendingUpdates(rendered);
Copy link
Member

Choose a reason for hiding this comment

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

we're not checking the updateLog here.

@wokalski
Copy link
Member

  • I just added a test for swapping elements. It's currently failing. The fix is fairly easy but requires changes to almost all tests (because now Nested and NoChange must also carry information if there's been some reordering (like Nested(true)).
  • I think we should remove useDynamicKey. I don't understand its usefulness
  • After fixing the reordering situation this PR should be feature wise good to go.

@wokalski
Copy link
Member

@rauanmayemir After refactoring the tests to the new DSL we should remove Assert module or rather merge it with the Run module.

@wokalski wokalski merged commit 5d57787 into master May 18, 2018
@wokalski wokalski deleted the tests branch May 18, 2018 18:49
@rauanmayemir rauanmayemir changed the title [WIP] UpdateLog tests UpdateLog tests May 23, 2018
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.

2 participants