-
Notifications
You must be signed in to change notification settings - Fork 25
DEVPROD-4608 Add stepback to the metadata of tasks #2299
DEVPROD-4608 Add stepback to the metadata of tasks #2299
Conversation
5 flaky tests on run #16261 ↗︎
Details:
Review all test suite changes for PR #2299 ↗︎ |
Could anyone on UI help me with the hooks tests? I defined the mocks and I'm using the Here's a quick view of it but it's available in the Test usage part:
The mock I'm providing:
The query I'm expecting the mock to fill (but it prints undefined)
taskId properly puts out |
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.
test structure lgtm 😎 feel free to add the rest! and great reorganization with the hooks!
@@ -0,0 +1,180 @@ | |||
import { ProviderWrapper } from "components/HistoryTable/hooks/test-utils"; |
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 ProviderWrapper
is specifically for the HistoryTable
component. You probably want to define your own ProviderWrapper
in this file instead!
|
||
expect(result.current.task).toBeDefined(); |
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 think you should be able to get this to pass if you wrap it in await waitFor(() => { // expect here })
You may also want to add an assertion like expect(result.current.task.id).toBe("breaking_commit");
after this one
|
||
expect(result.current.task).toBeDefined(); | ||
}); | ||
}); |
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.
(optional) another test case you may want to test is the error case — would require creating an additional GraphQL mock that returns an error. in this test, you can assert that the error toast is dispatched as expected
* It should only be used in favor of RenderFakeToastContext when the component | ||
* requires children to be rendered. | ||
*/ | ||
const MockToastContext = () => { |
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.
From what I can tell, I think you can achieve the same effect in your tests with the existing function RenderFakeToastContext
:
const { dispatchToast } = RenderFakeToastContext();
const { result } = renderHook(() => useBreakingTask("t1"), {
wrapper: ({ children }) => ProviderWrapper({ children }),
});
(see example hook test with toast mocks in Toast.test.tsx
)
then you can make assertions in your test that dispatchToast
is or is not called :)
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 added this for the ones that dispatch a toast notification but excluded it for those that don't!
src/pages/task/metadata/Stepback.tsx
Outdated
// nextStepbackTaskId is set when the next task in stepback in known, in the beginning | ||
// of stepback, it is known right away. In the rest of stepback, it is not. |
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.
nit. there might be a few typos in this comment e.g. in stepback in known
. in the beginning of...
seems like it should be its own sentence as well
src/pages/task/metadata/Stepback.tsx
Outdated
<Tooltip | ||
align="top" | ||
justify="middle" | ||
trigger={ | ||
<IconContainer> | ||
<Icon glyph="InfoWithCircle" size="small" /> | ||
</IconContainer> | ||
} | ||
triggerEvent="hover" | ||
> | ||
<Body> | ||
When Stepback is completed you can access the breaking commit via the | ||
relevant commits dropdown. | ||
</Body> | ||
</Tooltip>{" "} |
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.
You might be able to replace this block with the InfoSprinkle
component
src/pages/task/metadata/Stepback.tsx
Outdated
relevant commits dropdown. | ||
</Body> | ||
</Tooltip>{" "} | ||
{loading && <Badge variant="lightgray">Loading</Badge>} |
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.
Having Loading
in a badge makes it seem like it's a state of stepback, rather than an indication that we're still querying for a response. Perhaps a Skeleton Loader or Spinner could be a good replacement? (a skeleton loader is good for longer-term loading operations > 300ms, a spinner is good for shorter-term loading operations < 300ms)
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.
It's hard to guage how fast this might take. I based it on relevant commits since it uses the same queries, and guessed on average it would be a longer operation so I did the skeleton loader for the badge!
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.
added tests look great!
); | ||
|
||
describe("useBreakingTask", () => { | ||
it("no breaking task is found when task is not found", 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.
nit. You can remove async
since this test doesn't await
anything (applies to other test files as well)
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 catch! I wonder why the linter didn't catch it...
src/pages/task/metadata/Stepback.tsx
Outdated
* @param task The task to check if it is in stepback. | ||
* @returns Whether the task is in stepback. | ||
*/ | ||
export function inStepback(task: TaskQuery["task"]) { |
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.
nit. I'd maybe rename this function to something like isInStepback
to more clearly indicate that it returns a boolean
src/pages/task/metadata/Stepback.tsx
Outdated
const stepback = | ||
task?.stepbackInfo?.lastFailingStepbackTaskId !== undefined && | ||
task?.stepbackInfo?.lastFailingStepbackTaskId !== ""; |
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 would suggest a more boolean-y name, and I think you can simplify it to something like this:
const stepback = | |
task?.stepbackInfo?.lastFailingStepbackTaskId !== undefined && | |
task?.stepbackInfo?.lastFailingStepbackTaskId !== ""; | |
const hasLastStepback = task?.stepbackInfo?.lastFailingStepbackTaskId?.length > 0; |
src/pages/task/metadata/Stepback.tsx
Outdated
const beginningStepback = | ||
task?.stepbackInfo?.nextStepbackTaskId !== undefined && | ||
task?.stepbackInfo?.nextStepbackTaskId !== ""; |
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 comment!
const beginningStepback = | |
task?.stepbackInfo?.nextStepbackTaskId !== undefined && | |
task?.stepbackInfo?.nextStepbackTaskId !== ""; | |
const isBeginningStepback = task?.stepbackInfo?.nextStepbackTaskId?.length > 0; |
src/pages/task/metadata/Stepback.tsx
Outdated
// The last stepback task has an undefined last passing task (it is passing itself). | ||
const isLastStepbackTask = lastPassingTask === undefined; | ||
|
||
// The stepback is finished if there is a breaking task or we are on the last stepback task. | ||
const finished = breakingTask !== undefined || isLastStepbackTask; |
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.
Is it necessary to check lastPassingTask
? I feel like we always expect there to be a breaking task as long as stepback is finished — if breaking task was not defined then users wouldn't be able to access it via the Relevant Commits dropdown as the tooltip instructs
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.
If you are on the breaking task, stepback should still be counted as finished- the breaking task is when lastPassingTask === undefined
is true. I'll redo the comment!
src/pages/task/metadata/Stepback.tsx
Outdated
<StepbackWrapper> | ||
Stepback: | ||
<InfoSprinkle baseFontSize={BaseFontSize.Body1}> | ||
When Stepback is completed you can access the breaking commit via the | ||
relevant commits dropdown. | ||
</InfoSprinkle> | ||
{loading && <Skeleton size="small" />} | ||
{!loading && !finished && <Badge variant="lightgray">In progress</Badge>} | ||
{!loading && finished && <Badge variant="green">Complete</Badge>} | ||
</StepbackWrapper> |
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 only reservation about this is that now this doesn't have the correct font styles from MetadataItem
(if you look closely the font size is wrong). Perhaps we can change the underlying HTML of MetadataItem
into a <div>
and then rewrite it as the following:
<StepbackWrapper> | |
Stepback: | |
<InfoSprinkle baseFontSize={BaseFontSize.Body1}> | |
When Stepback is completed you can access the breaking commit via the | |
relevant commits dropdown. | |
</InfoSprinkle> | |
{loading && <Skeleton size="small" />} | |
{!loading && !finished && <Badge variant="lightgray">In progress</Badge>} | |
{!loading && finished && <Badge variant="green">Complete</Badge>} | |
</StepbackWrapper> | |
<MetadataItem> | |
<StepbackWrapper> | |
// content goes here | |
</StepbackWrapper> | |
</MetadataItem> |
versionMetadata, | ||
} = taskData?.task ?? {}; | ||
const { order: skipOrderNumber } = versionMetadata?.baseVersion ?? {}; | ||
const { baseTask, versionMetadata } = taskData?.task ?? {}; |
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 just realized that there doesn't seem to be a reason to perform the BaseVersionAndTaskQuery
at all; it looks like the parent component of this component (ActionButtons.tsx
) can pass these values down as props 🤔
src/pages/task/ActionButtons.tsx
Outdated
@@ -254,7 +254,7 @@ export const ActionButtons: React.FC<Props> = ({ | |||
<PageButtonRow> | |||
{!isExecutionTask && ( | |||
<> | |||
<RelevantCommits taskId={taskId} /> | |||
<RelevantCommits taskId={taskId} task={task} /> |
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.
You can remove the taskId
prop if it can be accessed from the task
!
children, | ||
"data-cy": dataCy, | ||
}) => <Item data-cy={dataCy}>{children}</Item>; | ||
}) => ( | ||
<Item data-cy={dataCy} as={as}> |
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 is cool! The only issue with this is that the margin from :not(:last-of-type)
selector doesn't quite work as intended anymore due to the mix of <p>
and <div>
tags.
Maybe we can change :not(:last-of-type)
-> :not(:last-child)
src/pages/task/metadata/Stepback.tsx
Outdated
}; | ||
|
||
const StepbackWrapper = styled.div` | ||
margin-top: ${size.xxs}; |
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.
you can remove this margin-top
style if you get the margin from the style change mentioned in the previous comment
src/pages/task/metadata/Stepback.tsx
Outdated
const isBeginningStepback = | ||
task?.stepbackInfo?.nextStepbackTaskId !== undefined && | ||
task?.stepbackInfo?.nextStepbackTaskId !== ""; |
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.
Can this be rewritten with length as well, or did you run into a problem? 👀
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.
Nope! Just got confused but I updated it to use the length trick too
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.
great work!
src/pages/task/metadata/index.tsx
Outdated
data-cy="t | ||
task: patchTaskWithSuccessfulBaseTask, | ||
ask-metrics-link" |
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.
looks like this was an unintentional change
When Stepback is completed you can access the breaking commit via the | ||
relevant commits dropdown. | ||
</InfoSprinkle> | ||
{loading && <Skeleton size="small" />} |
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.
DEVPROD-4608
Description
This adds the metadata item for stepback to show "In progress" or "completed" and an info icon accompanying it. I implemented according to the design except I added a "loading" state while the graphql query completes.
This also isolates and extracts the different relevant commit queries in to each their own hook: 'useParentTask', 'useLastPassingTask', 'useBreakingCommit', and 'useLastExecutedTask'. The first three are re-used (within each other, in the relevant commits dropdown, and the metadata card) while the last one is only used in the relevant commits dropdown- but it figured it would be better to extract and test that logic separately to be consistent (it removes bloat from the relevant commits dropdown component).
I separated my commits to be distinct so anyone who reviews can look over the commits for an easier time!
Screenshots
In progress
Completed
Hovering dropdown
Testing
I tested the buttons on multiple different tasks on staging- before and after this change. All the buttons respond the exact same- and as for the metadata item I also tested on staging making sure it shows the correct state.
I plan to add similar testing for all the new hooks if the reviewer thinks the tests for the hook I added is good! Please let me know- it shouldn't be too long to add them!