-
Notifications
You must be signed in to change notification settings - Fork 3
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 Visual Tests stories to more closely control selected story #124
Refactor Visual Tests stories to more closely control selected story #124
Conversation
AP-3703 Auto switch to latest if story is on latest build, but not on selected build
Currently, if a user is on a story that exists on the last build on the branch, but not on the locally selected build, it will still display "new story ui". To refresh it, they need to change out of the story and back. Instead, if the story is on the latest selected build, we should automatically change to the latest build. |
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.
Sorry for delayed review. This story makes sense to me. I'm not sure about changing every story to have a function but if the change could be handled in the withBuilds method then it makes sense.
Now that I understand them a bit better, I think a high level mock is useful. For edge cases and interactions presentational stories might work well but I think this issue for instance might have been hard to test without a graphql mock that mimics our api even if it required changing.
The story looks good to me. I can comment on the other questions mentioned tomorrow after a night's rest.
I prefer the "integration test" style of stories over the pure presentational level, because it showcases what Storybook can do rather than copping out, while also providing us with better coverage. So I think the approach taken here is desirable. "some other type of testing" would likely mean E2E which I'd like to avoid if possible. |
Ok, so it sounds like the consensus here is to apply this approach to the other stories in the |
0030d1e
to
88957c9
Compare
I had forgotten we need to also switch build id when changing story.
…ch-to-latest-if-story-is-on-latest-build-but-not-on
// NOTE: this does not current work, the story is auto-selected | ||
// play: async ({ canvasElement, args, argsByTarget }) => { | ||
// // We have to wait a moment for the story to render | ||
// const canvas = within(canvasElement); | ||
// await canvas.findAllByText("Latest"); | ||
|
||
// // Ensure we don't switch to the new build, the user has to opt-in | ||
// mock(args.setSelectedBuildInfo!).mock.calls.forEach(([updater]) => { | ||
// const result = typeof updater === "function" ? updater(args.selectedBuildInfo) : updater; | ||
// expect(result).toEqual(args.selectedBuildInfo); // Unchanged | ||
// }); | ||
|
||
// // Now opt in | ||
// const viewLatestSnapshot = (await canvas.findAllByText("View latest snapshot"))[0]; | ||
// await userEvent.click(viewLatestSnapshot); | ||
|
||
// const graphqlArgs = argsByTarget.graphql?.$graphql as typeof args.$graphql; // We need to type argsByTarget | ||
// await waitFor(() => { | ||
// expect(args.setSelectedBuildInfo).toHaveBeenCalledWith({ | ||
// buildId: graphqlArgs?.AddonVisualTestsBuild?.lastBuildOnBranch?.id, | ||
// storyId: meta.args.storyId, | ||
// }); | ||
// }); | ||
// }, |
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.
As noted this play function is disabled here (and in 2 other tests) but fixed in #130
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, I like this approach 👍
This PR does 2 main things:
Refactor
VisualTests
so theselectedBuildId
is a prop. This allows us to continue to write stories that vary theselectedBuild
+lastBuildOnBranch
without having weird stuff happen with theselectedBuildId
. It also allows us to clearly assert on when the component should change theselectedBuildId
in play functions[1].Refactor the stories to use an args based approach and be very careful about the builds we pass. I'm pretty happy with how the stories end up reading but open to feedback.
[1] This also exposed a bug in how we are doing it right now that I'll fix in a follow up PR (#130)
Old text:
So the behaviour was actually right here, but the story didn't show it.
Let me explain because I think we might want to consider tightening up our testing strategy here.
lastBuildOnBranch
andselectedBuild
.VisualTests
component changes theselectedBuildId
variable based on various criteria.selectedBuild
was hard-coded.For the older story
Empty Branch Local Build Captured Current Story
we fudge around this, because we set theselectedBuild
to thelastBuildOnBranch
when there is noselectedBuild
:addon-visual-tests/src/screens/VisualTests/VisualTests.tsx
Lines 158 to 163 in 0030d1e
However, that doesn't help us for the newer, similar story
Story Added In Last Build On Branch Not In Selected
because the selected build does exist, it just doesn't have this story.So the fix here is to make the GraphQL mock actually respond to the change in
selectedBuildId
. My question for y'all is: Should we, to be correct, make that change to all these stories? Or is this whole approach of testing theVisualTests
component wrong and we should just write stories at the presentational level and do some other type of testing of "what happens when theselectedStoryId
changes?" or "what happens when there's a newlastBuildOnBranch
?"Possibly we drop the quoted lines above too as it's sort of confusing there are two ways the
selectedBuild
ends up being equal to thelastBuildOnBranch
. (Firstly by the short cut above, secondly by settingselectedBuildId
, requerying, and re-rendering). Then again the shortcut saves the user waiting for a second query.Another option would be to extend the logic to make
selectedBuild = lastBuildOnBranch
if the current story isn't in the actual selected build. Confusing?📦 Published PR as canary version:
0.0.106--canary.124.6cd88ba.0
✨ Test out this PR locally via: