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

186 open snapshot in editor #197

Merged
merged 3 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}