Conditional rendering testing value of object of forward/backward link#201
Conditional rendering testing value of object of forward/backward link#201jg10-mastodon-social wants to merge 37 commits into
Conversation
9c895fd to
243847e
Compare
| `); | ||
| }); | ||
|
|
||
| it('does not render templates when compareValue indicates that some-value-(lt|lte|gt|gte) is not met (numeric)', async () => { |
There was a problem hiding this comment.
I suspect we might need more tests here, but I'm not sure how to design them.
I designed these as TDD tests - they all fail if the numbers are treated as strings.
There was a problem hiding this comment.
I've now grouped tests, and split out tests specifically of the test method.
I've tried to systematically go through possible combinations of inputs and data, using the it.each approach.
The code is still missing systematic tests of:
- evaluating values of property and rev with multiple relations
- evaluating values of property with multiple strings
- evaluating values of property with multiple numbers
There are ad-hoc tests for this functionality, so given the difficulty in parameterising these combinatorial tests, I suggest we open an issue documenting this gap and merge in the mean time.
Any suggestions are welcome for systematically testing all combinations in the presence of multiple values!
02ee964 to
25f0fef
Compare
25f0fef to
261f92d
Compare
80772f3 to
69f0119
Compare
| and this project adheres to | ||
| [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
|
||
| ## 0.30.0 |
There was a problem hiding this comment.
I think this is now 0.30.0, but I may have misunderstood what is in the previous release
There was a problem hiding this comment.
you are right, next version will be 31. I might have messed up the changelog on main, will check that
|
|
||
| The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
|
||
| ## 0.42.0 |
There was a problem hiding this comment.
@angelo-v Is this correct?
When rebasing on main, it looked like your previous fixes no longer applied given the release in the mean time?
There was a problem hiding this comment.
this looks correct, version in package json is "0.42.0-next.0" so 0.42.0 will be the next released version. If you rebase onto main and 0.42.0 was meanwhile released you will see the version increase to 0.43.0-next.0 and you then need to adjust the changelog accordingly
angelo-v
left a comment
There was a problem hiding this comment.
@jg10-mastodon-social Sorry, I just noticed I left some comments in "pending" state and you propbably did not see them. I am just submitting them now - yet I did not find the time to look at your latest changes, so I am not sure if they are still relevant. I am going to continue reviewing the current state later this week
| let state = null; | ||
| let values = null; | ||
|
|
||
| const compareValue = function (values: string[]): boolean { |
There was a problem hiding this comment.
issue: this function is very complex and should a) be refactored into smaller chunks and b) moved into its own file and heavily unit tested. Comparision logic be separated from element attributes.
There was a problem hiding this comment.
I hadn't seen this comment and have therefore not refactored. Any help in dividing it up would be great!
I did however create a separate test file for this function so (b) is partially addressed.
I'm not sure about separating out comparison logic from element attributes - the main purpose of the function is to apply all necessary combinations of element attributes - the comparison logic itself is arguably trivial once the effect of the element attributes is applied.
There was a problem hiding this comment.
my fault! I did not submit it properly and am very sorry. I added a refactoring commit that goes into the direction I tried to explain, but it is still a long way to go. I am sorry to say that but in the current state the complexity in pos-switch is unacceptable to me and propably still a source of many bugs.
Thank you very much for the extensive test suite you added. These tests are a necessary security net for refactoring. Yet the combinatory explosion of these tests and the fact that they are yet not able to cover every case are a big big smell.
pos-switch does effectifly three things:
- data gathering: find all the necessary data for comparision (observed relations, values etc)
- rules: gather semantics, operators and their respective values applied to pos-case (like "some-value-eg=..." etc.)
- apply the rules to the gathered data
I imagine that those 3 parts could be well separated and tested by themselves and this would reduce the testing combinatoric a lot
There was a problem hiding this comment.
I am thinking of something like that:
const data = {
literals: [],
relations: [],
reverseRelations: [],
types: []
};
const rule = {
type: "if-property",
value: "https://schema.org/name",
operator: "eq",
semantic: "some",
target: "Alice"
}
function ruleMatches(r: typeof rule, d: typeof data): boolean {
}- collect
datafrom resource - create rule(s) from dom attributes
- match rules with data
ruleMatches is a pure function with no dependency on dom or resource that could be easily testable. Also there can be multiple sub-functions for different rule types that can be tested and focus on that specific rule
There was a problem hiding this comment.
There is Element.getAttributeNames that might make it easier to get the attributes from dom compared to checking if each exists individually, but unfortunately stencil testbed does not implement it. This should not stop us from using it, if it helps us. If the pure function based on configured rules does the heavy logic we can easily mock getAttributeNames for the component testing. I am also currently migrating to vitest and this might make the stencil testing situation better.
There was a problem hiding this comment.
vitest is available on main branch now, so you can add a vitest spec by using *.vspec.tsx if that helps
| } | ||
| if (caseElement.getAttribute('if-property') !== null) { | ||
| state = this.relations.map(x => x.predicate).includes(caseElement.getAttribute('if-property')); | ||
| const matchingRelations = this.relations.filter(x => x.predicate == caseElement.getAttribute('if-property')); |
There was a problem hiding this comment.
issue: same as above. Try to collect the relevant data and condition from component first, then do the logic in a dedicated function that is independent from the component and well tested
9bbd066 to
4244141
Compare
Closes #184