-
Notifications
You must be signed in to change notification settings - Fork 22
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
#4994: Make links in Field descriptions clickable #4993
Conversation
<span | ||
dangerouslySetInnerHTML={{ | ||
__html: linkifyUrls(children, { |
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.
Hopefully in the future:
dangerouslySetInnerHTML={{ | ||
__html: linkifyUrls(children, { | ||
attributes: { | ||
target: "_blank", |
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.
No rel
needed, see pixiebrix/eslint-config-pixiebrix#37
Codecov Report
@@ Coverage Diff @@
## main #4993 +/- ##
=======================================
Coverage 59.16% 59.16%
=======================================
Files 964 965 +1
Lines 29077 29084 +7
Branches 5568 5569 +1
=======================================
+ Hits 17202 17209 +7
Misses 11875 11875
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
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.
Nice!
<LinkifiedString>https://example.com and more</LinkifiedString> | ||
); | ||
|
||
expect(rendered.asFragment()).toMatchInlineSnapshot(` |
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.
Let's sue regular snapshots:
- that's consistent
- the tests are easier to grasp
- when you need to update the snapshots, you don't need to make the changes manually
- you can always explore the snapshot file to see what is the expected output
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.
when you need to update the snapshots, you don't need to make the changes manually
The point of snapshots is that they're automated, use jest --updateSnapshot
the tests are easier to grasp
you can always explore the snapshot file to see what is the expected output
Are you talking about .toMatchSnapshot
?
The actual test file is indeed easier to scan, but then to see the result you have to find it in the external file. This is fine when there's a single test but it becomes hard to find which is which when there are multiple snapshots.
With inline snapshots the results is right here, it's like manual "expect x to exist" tests, except they're fully automated.
that's consistent
We're already using inline snapshots in many other tests, especially for smaller components.
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.
when you need to update the snapshots
Pls disregard, I thought auto-update doesn't work for inline snapshots.
Are you talking about .toMatchSnapshot?
Yes.
We're already using inline snapshots in many other tests, especially for smaller components.
Personally, I prefer to have tests in one file and results in another file, always, regardless of the component size, so everyone on the team has the same knowledge, understanding, and expectations for reading and authoring the snapshot tests.
Let's not get into a long discussion though, the PR has been approved, leaving the final decision to you as the PR author.
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.
My two cents: I would prefer to use file-based snapshots for React components
Also, I've had problems with Jest failing to update the inline snapshots in files that use import {type Foo} from "foo"
syntax
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've had problems with Jest failing to update the inline snapshots in files that use import {type Foo} from "foo" syntax
That's a temporary issue that has or will be fixed. I do agree however that sometimes they cause annoyances.
File-based snapshots are good to ensure large components don't change, but they make tests unreadable. There's no way for me to see what the expectations are by just looking at this file:
https://github.com/pixiebrix/pixiebrix-extension/blob/main/src/components/LinkifiedString.test.tsx
everyone on the team has the same knowledge, understanding, and expectations for reading and authoring the snapshot tests.
I don’t think inline snapshots are difficult to understand and are definitely easier to author than manually copy-pasting the results like in this case:
pixiebrix-extension/src/blocks/transformers/parseDate.test.ts
Lines 68 to 82 in 251b6d5
expect(result).toEqual({ | |
utc: { | |
iso8601: "2021-12-10T03:00:00.000Z", | |
date: "12/10/2021", | |
time: "3:00:00 AM", | |
humanReadable: "Fri, 10 Dec 2021 03:00:00 GMT", | |
epochMillis: 1_639_105_200_000, | |
}, | |
local: { | |
iso8601: "2021-12-09T22:00:00.000-05:00", | |
date: "12/9/2021", | |
time: "10:00:00 PM", | |
humanReadable: "12/9/2021, 10:00:00 PM", | |
}, | |
}); |
👆 this one was a prime example of when to use (automated) inline snapshots.
No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack. Do not edit this comment manually. |
Discussion
This is the lowest-level place I found. If you know of other parts that would benefit from linkification, let me know.
This change also applies to the page editor. Here it ignores any pre-existing links/dom:
An alternative solution with a broader impact would be to use a barebones "markdown" parser so we don't have to create JSX for this kind of content:
pixiebrix-extension/src/pageEditor/tabs/quickBar/QuickBarConfiguration.tsx
Lines 58 to 68 in 9dfc712
However this requires further discussion and research so I skipped it for now. We just need support for
code
anda
, not the wholemarked
module.Team Coordination
Checklist