Skip to content

Commit

Permalink
implement view snapshot button
Browse files Browse the repository at this point in the history
This commit implements issue Raathigesh#186. I can't know if there is a snapshot
for each but I can add a button to the summary that opens the snapshot
for the file in the code editor. That's what this commit does. It adds
the button to the UI and a mutation to send to the server to open the
snapshot in the editor.
And it implements issue Raathigesh#191. There was already a button for generating
a snapshot, but it was only visible when there was a detected snapshot
error. This caused us to have to run known failing tests before we could
get the button to generate the snapshots. Now the button is there all
the time, so if you know your snapshots are out of date, then you can
generate them immediately and save time.
  • Loading branch information
Greg Veres committed May 15, 2020
1 parent 2296cf6 commit f77d47a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
13 changes: 13 additions & 0 deletions server/api/app/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as launch from "launch-editor";
import { App } from "./app";
import FileWatcher, { WatcherEvents } from "../../services/file-watcher";
import { pubsub } from "../../event-emitter";
import { dirname, basename } from "path";

@Resolver(App)
export default class AppResolver {
Expand Down Expand Up @@ -44,4 +45,16 @@ export default class AppResolver {

return "";
}

@Mutation(returns => String)
openSnapInEditor(@Arg("path") path: string) {
var dir = dirname(path)
var file = basename(path);

var snap = dir + '/__snapshots__/' + file + '.snap'
console.log("opening the snapshot:", snap);
this.openInEditor(snap);

return "";
}
}
9 changes: 0 additions & 9 deletions ui/test-file/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,6 @@ function TestFile({ selectedFilePath, isRunning, projectRoot, onStop }: Props) {
result => result.changeToResult
);

const haveSnapshotFailures = ((result && result.testResults) || []).some(
testResult => {
return (testResult.failureMessages || []).some(failureMessage =>
failureMessage.includes("toMatchSnapshot")
);
}
);

const roots = (fileItemResult.items || []).filter(
item => item.parent === null
);
Expand All @@ -116,7 +108,6 @@ function TestFile({ selectedFilePath, isRunning, projectRoot, onStop }: Props) {
path={selectedFilePath}
isRunning={isRunning}
isLoadingResult={loading}
haveSnapshotFailures={haveSnapshotFailures}
onRun={() => {
runFile();
}}
Expand Down
24 changes: 19 additions & 5 deletions ui/test-file/summary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import {
CheckCircle,
Frown,
ZapOff,
Circle
Circle,
Eye
} from "react-feather";
import Button from "../../components/button";
import OPEN_IN_EDITOR from "./open-in-editor.gql";
import OPEN_SNAP_IN_EDITOR from "./open-snap-in-editor.gql";
import { Tooltip } from "react-tippy";
import { useMutation } from "react-apollo-hooks";

Expand Down Expand Up @@ -127,7 +129,6 @@ export default function FileSummary({
onRun,
onStop,
onSnapshotUpdate,
haveSnapshotFailures
}: Props) {
const Icon = isRunning ? StopCircle : Play;

Expand All @@ -137,6 +138,12 @@ export default function FileSummary({
}
});

const openSnapshotInEditor = useMutation(OPEN_SNAP_IN_EDITOR, {
variables: {
path
}
});

return (
<Container p={4} bg="slightDark">
{(isRunning || isLoadingResult) && <ContainerBG />}
Expand Down Expand Up @@ -188,9 +195,8 @@ export default function FileSummary({
}}
/>
</Tooltip>
{haveSnapshotFailures && (
<Tooltip
title="Update all snapshots of the file"
title="Update all snapshots for this file"
position="bottom"
size="small"
>
Expand All @@ -204,7 +210,15 @@ export default function FileSummary({
Update Snapshot
</Button>
</Tooltip>
)}
<Tooltip title="Open snapshot in editor" size="small" position="bottom">
<Button
icon={<Eye size={14} />}
minimal
onClick={() => {
openSnapshotInEditor();
}}
/>
</Tooltip>
</ActionPanel>
</Container>
);
Expand Down
3 changes: 3 additions & 0 deletions ui/test-file/summary/open-snap-in-editor.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mutation OpenSnapInEditor($path: String!) {
openSnapInEditor(path: $path)
}

0 comments on commit f77d47a

Please sign in to comment.