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

refactor: prepare tests for migration #10509

Merged
merged 1 commit into from
Nov 1, 2024
Merged

refactor: prepare tests for migration #10509

merged 1 commit into from
Nov 1, 2024

Conversation

maxpatiiuk
Copy link
Member

@maxpatiiuk maxpatiiuk commented Oct 9, 2024

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:

  • /packages/support-packages/stencil-to-lit/src/code/fileSpecific.ts
  • /packages/support-packages/stencil-to-lit/src/component/fileSpecific.ts

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)

@maxpatiiuk maxpatiiuk requested a review from jcfranco October 9, 2024 04:13
@maxpatiiuk maxpatiiuk self-assigned this Oct 9, 2024
@github-actions github-actions bot added the refactor Issues tied to code that needs to be significantly reworked. label Oct 9, 2024
Comment on lines -915 to -919
// 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("");
Copy link
Member Author

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.

Copy link
Member

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();
Copy link
Member Author

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}
Copy link
Member Author

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)

Copy link
Member

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,
Copy link
Member Author

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.

See https://qawebgis.esri.com/arcgis-components/?path=/docs/references-lumina-transition-from-stencil--docs#attribute-to-property-casting

@@ -15,7 +15,7 @@ describe("calcite-navigation", () => {
reflects("calcite-navigation", [
{
propertyName: "navigationAction",
value: "",
value: true,
Copy link
Member Author

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");
Copy link
Member Author

Choose a reason for hiding this comment

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

typo

Copy link
Member

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 () => {
Copy link
Member Author

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);
Copy link
Member Author

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) {
Copy link
Member Author

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:

Copy link
Member

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. You can see the behavior in this pen.

@benelan could you confirm? If so, could you look at updating formAssociated to cover this case?

Copy link
Member

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.

Copy link
Member

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!

@@ -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");
Copy link
Member Author

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

Copy link
Member

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.

Copy link
Contributor

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.

@github-actions github-actions bot added the Stale Issues or pull requests that have not had recent activity. label Oct 28, 2024
@maxpatiiuk
Copy link
Member Author

Ping.
Looks like #10509 (comment) is the only remaining thing blocking this PR?

benelan added a commit that referenced this pull request Oct 31, 2024
**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
@maxpatiiuk
Copy link
Member Author

@benelan thanks for the fix!

With #10662 merged, #10509 (comment) is resolved, and this PR is unblocked.

@maxpatiiuk maxpatiiuk requested review from jcfranco and removed request for jcfranco November 1, 2024 01:56
@github-actions github-actions bot removed the Stale Issues or pull requests that have not had recent activity. label Nov 1, 2024
jcfranco

This comment was marked as duplicate.

Copy link
Member

@jcfranco jcfranco left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks, @maxpatiiuk!

@jcfranco jcfranco added the skip visual snapshots Pull requests that do not need visual regression testing. label Nov 1, 2024
@jcfranco jcfranco merged commit 30367fd into dev Nov 1, 2024
15 checks passed
@jcfranco jcfranco deleted the max/tests-migration branch November 1, 2024 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Issues tied to code that needs to be significantly reworked. skip visual snapshots Pull requests that do not need visual regression testing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants