-
Notifications
You must be signed in to change notification settings - Fork 77
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
refactor: prepare tests for migration #10509
Conversation
// initialize page with calcite-color-picker to make it available in the evaluate callback below | ||
const page = await newE2EPage({ | ||
html: "<calcite-color-picker></calcite-color-picker>", | ||
html: "", | ||
}); | ||
await page.setContent(""); |
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 seems wrong.
The html
option of newE2EPage just calls setContent
behind the scenes.
Each time setContent
is called, the page is re-created from scratch - there is no information carried over in between.
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.
TL;DR: it seems this workaround is no longer needed and we can simplify newProgrammaticE2EPage
.
It looks like Stencil fixed an issue where creating an empty page and then adding a component via createElement
would not load properly (i.e., the html
content required a component). This was our workaround (basis for newProgrammaticE2EPage
).
|
||
await page.evaluate(async (color) => { | ||
const picker = document.createElement("calcite-color-picker"); | ||
picker.value = color; | ||
document.body.append(picker); | ||
|
||
await new Promise<void>((resolve) => requestAnimationFrame(() => resolve())); | ||
await picker.componentOnReady(); |
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.
componentOnReady is more suited for this
@@ -104,7 +104,6 @@ export class Loader implements LocalizedComponent { | |||
[CSS.loaderPart]: true, | |||
[CSS.loaderPartId(index)]: true, | |||
}} | |||
key={index} |
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.
key={index}
seems useless?
Lumina has a warning about using index as a key (it suggests not using the key at all in those cases)
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.
On closer inspection, I think key
isn't needed here since the indices won't vary between renders.
@@ -22,7 +22,7 @@ describe("calcite-navigation-user", () => { | |||
}, | |||
{ | |||
propertyName: "textDisabled", | |||
value: "", | |||
value: true, |
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.
In Stencil, casting is done both to property and attribute (thus setting boolean property to ""
will cast to true
). In Lit, casting is only done when converting attribute to property or property to attribute.
@@ -15,7 +15,7 @@ describe("calcite-navigation", () => { | |||
reflects("calcite-navigation", [ | |||
{ | |||
propertyName: "navigationAction", | |||
value: "", | |||
value: true, |
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.
same
@@ -9,7 +9,7 @@ describe("calcite-pick-list-item", () => { | |||
}); | |||
|
|||
describe("honors hidden attribute", () => { | |||
hidden("calcite-list-item"); | |||
hidden("calcite-pick-list-item"); |
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.
typo
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.
Good catch!
@@ -399,7 +399,7 @@ describe("calcite-rating", () => { | |||
expect(labels[4]).not.toHaveClass("partial"); | |||
}); | |||
|
|||
it("should update the ui of the rating when a hover event triggers on a rating label", async () => { | |||
it("should update the UI of the rating when a hover event triggers on a rating label", async () => { |
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.
consistency with usages in previous test titles
@@ -118,7 +118,7 @@ describe("calcite-shell-panel", () => { | |||
"calcite-shell-panel", | |||
(panel: HTMLCalciteShellPanelElement, containerClass: string, contentClass: string) => { | |||
const container = panel.shadowRoot.querySelector(containerClass); | |||
return container.firstElementChild.className == contentClass; | |||
return container.firstElementChild.classList.contains(contentClass); |
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.
In Lumina, when class={}
prop is an object, the attribute is set to not just "value"
but to " value "
(notice the spaces.
Adjusting this to use classList.contains to have the code work both pre and post migration
@@ -290,7 +290,7 @@ function invalidHandler(event: Event) { | |||
formComponent.status = "idle"; | |||
} | |||
|
|||
if ("validationIcon" in formComponent && !formComponent.validationIcon) { | |||
if ("validationIcon" in formComponent) { |
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.
Unless I am wrong, it seems like this condition should not have been here and it worked in Stencil accidentally:
- Since validationIcon prop is of mixed type (string | boolean), setting it to empty string does not automatically cast to
true
- You set validationIcon prop to true here on form validation error:
icon: true,
- SInce this prop is reflected, stencil reflects it to empty string attribute:
- Reflection of the attribute triggers attributeChangedCallback. Stencil sees that the attribute value
""
does not match the property valuetrue
, and sets the property to""
. - When it comes to clear the validation message, this place does the
&& !formComponent.validationIcon
check. That worked because""
is falsy.- However, this condition does not work in Lit because Lit ignores attributeChangedCallback when it does the reflection of a property to an attribute
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 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.
IIRC, this logic preserves user-set validation icons between invalid form submissions.
Yeah this is correct. I definitely abused some insane javascript quirks here so that's my bad lol. If you need help refactoring this so it will work in Lit I can take another look.
If so, could you look at updating formAssociated to cover this case?
Yeah definitely.
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.
Thanks for the fix, @benelan!
fed772f
to
cda7494
Compare
@@ -1214,7 +1214,7 @@ describe("calcite-time-picker", () => { | |||
await page.mouse.click(buttonUpLocationX, buttonUpLocationY); | |||
await page.waitForChanges(); | |||
const fractionalSecondEl = await page.find(`calcite-time-picker >>> .input.fractionalSecond`); | |||
expect(fractionalSecondEl.innerHTML).toEqual("0"); | |||
expect(fractionalSecondEl.textContent).toEqual("0"); |
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.
Lit inserts comments in the rendered content to help it deal with cases when nodes are inserted before/after lit-rendered nodes by third-party code.
To avoid those comments from appearing in this test, use textContent instead of innerHTML
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.
Good tip. We should probably add a warning against innerHTML
usage.
This PR has been automatically marked as stale because it has not had recent activity. Please close your PR if it is no longer relevant. Thank you for your contributions. |
Ping. |
**Related Issue:** #10482 ## Summary Resolve the `validationIcon` issue brought up in #10509 (comment) The only properties affected by the change in how boolean properties are reflected are `icon`, `validationIcon`, and `download`. This PR fixes the utils that caused issues with `icon` and `validationIcon`. The `download` property seems to already be correct, for example: https://github.com/Esri/calcite-design-system/blob/25319998739c3af17a5438d285c5931ea656285d/packages/calcite-components/src/components/link/link.tsx#L178
cda7494
to
d65c81b
Compare
@benelan thanks for the fix! With #10662 merged, #10509 (comment) is resolved, and this PR is unblocked. |
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.
Awesome! Thanks, @maxpatiiuk!
Make minor adjustments to Calcite code to have post-migration tests pass.
Changes that need to be done post-migration are encoded in the following codemod files in the arcgis-web-components repository:
At this point, I am finishing up the failing tests in the S components and will be pretty much done with all A-S component (with exception of #10394 and #10495)