-
Notifications
You must be signed in to change notification settings - Fork 9
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
Conversation
Determining the subtree change at the reconciliation time lets us perform minimal changes to the underlying views. It also introduces formatting testInstances as JSX
I think we should also squash |
|
This commit also includes some changes in the algorithm to ignore empty updates.
They are included inside new/old instance
Instances are now memoized by the library
There was a problem hiding this 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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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" />] |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
Flat now contains only one element
|
test printer minor fixes
fix output diffing, improve indentation
@rauanmayemir After refactoring the tests to the new DSL we should remove |
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 replacedPrependElement
means that an element should be prependedTodos:
UpdateLog
step by step. It's important since we can determine that the minimal amount of steps is indeed in theUpdateLog
.TestapplyUpdateLog
. The tree fromapplyUpdateLog
should be the same as newly returned element.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 withUpdateLog
. TheRenderUpdateLog
however will only be a part of tests. Also, in order to test it properly we need to introduce mutations to theTestRenderer
because currently thehostView
is immutable.prependElement
Remember to includeTestupdateInstance
in the tests`ContentChanged