Skip to content

Commit

Permalink
Correct tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathonherbert committed Jan 21, 2021
1 parent c27d71f commit 058fb33
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/ts/components/SidebarMatch.tsx
Expand Up @@ -12,7 +12,7 @@ import SidebarMatchContainer from "./SidebarMatchContainer";
import { createScrollToRangeHandler } from "../utils/component";
import Markdown from "./Markdown";
import { css, SerializedStyles } from "@emotion/react";
import { getSquiggleAsUri } from "./icons";
import { getSquiggleAsUri } from "../utils/squiggle";

interface IProps {
match: IMatch;
Expand Down
15 changes: 0 additions & 15 deletions src/ts/components/icons.tsx
@@ -1,18 +1,3 @@
const squiggleMap = {
VERTICAL: (colour: string) =>
`<svg width="4" height="20" fill="none" transform="scale(-1,1)" xmlns="http://www.w3.org/2000/svg"><path stroke="${colour}" stroke-width="2" d="m2.08695,-2.80434c1.33333,1.72222 1.33333,3.44444 0,5.16667c-1.33333,1.72222 -1.33333,3.44444 0,5.16663c1.33333,1.7223 1.33333,3.4445 0,5.1667c-1.33333,1.7222 -1.33333,3.4444 0,5.1667c1.33333,1.7222 1.33333,3.4444 0,5.1666c-1.33333,1.7223 -1.33333,3.4445 0,5.1667"/></svg>`,
HORIZONTAL: (colour: string) =>
`<svg width="16" height="4" fill="none" xmlns="http://www.w3.org/2000/svg"><path stroke="${colour}" stroke-width="2" d="m22.65517,2c-1.37161,1.33333 -2.74333,1.33333 -4.11494,0c-1.37161,-1.33333 -2.74333,-1.33333 -4.11494,0c-1.37161,1.33333 -2.74333,1.33333 -4.11494,0c-1.37161,-1.33333 -2.74333,-1.33333 -4.11494,0c-1.37164,1.33333 -2.7433,1.33333 -4.11494,0c-1.37164,-1.33333 -2.7433,-1.33333 -4.11494,0"/></svg>`
};

export const getSquiggleAsUri = (
colour: string,
orientation: "HORIZONTAL" | "VERTICAL" = "HORIZONTAL"
) => {
const svg = squiggleMap[orientation](colour);
return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
};

export const warningIcon = (colour: string) => (
<svg
width="20"
Expand Down
2 changes: 1 addition & 1 deletion src/ts/utils/decoration.ts
Expand Up @@ -2,7 +2,7 @@ import flatten from "lodash/flatten";
import { Node } from "prosemirror-model";
import { Decoration, DecorationSet } from "prosemirror-view";
import { IRange, IMatch } from "../interfaces/IMatch";
import { getSquiggleAsUri } from '../components/icons';
import { getSquiggleAsUri } from "./squiggle";

export enum MatchType {
HAS_REPLACEMENT = "HAS_REPLACEMENT",
Expand Down
14 changes: 14 additions & 0 deletions src/ts/utils/squiggle.ts
@@ -0,0 +1,14 @@
const squiggleMap = {
VERTICAL: (colour: string) =>
`<svg width="4" height="20" fill="none" transform="scale(-1,1)" xmlns="http://www.w3.org/2000/svg"><path stroke="${colour}" stroke-width="2" d="m2.08695,-2.80434c1.33333,1.72222 1.33333,3.44444 0,5.16667c-1.33333,1.72222 -1.33333,3.44444 0,5.16663c1.33333,1.7223 1.33333,3.4445 0,5.1667c-1.33333,1.7222 -1.33333,3.4444 0,5.1667c1.33333,1.7222 1.33333,3.4444 0,5.1666c-1.33333,1.7223 -1.33333,3.4445 0,5.1667"/></svg>`,
HORIZONTAL: (colour: string) =>
`<svg width="16" height="4" fill="none" xmlns="http://www.w3.org/2000/svg"><path stroke="${colour}" stroke-width="2" d="m22.65517,2c-1.37161,1.33333 -2.74333,1.33333 -4.11494,0c-1.37161,-1.33333 -2.74333,-1.33333 -4.11494,0c-1.37161,1.33333 -2.74333,1.33333 -4.11494,0c-1.37161,-1.33333 -2.74333,-1.33333 -4.11494,0c-1.37164,1.33333 -2.7433,1.33333 -4.11494,0c-1.37164,-1.33333 -2.7433,-1.33333 -4.11494,0"/></svg>`
};

export const getSquiggleAsUri = (
colour: string,
orientation: "HORIZONTAL" | "VERTICAL" = "HORIZONTAL"
) => {
const svg = squiggleMap[orientation](colour);
return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
};
11 changes: 4 additions & 7 deletions src/ts/utils/test/decoration.spec.ts
@@ -1,6 +1,5 @@
import {
createDecorationsForMatch,
defaultMatchColours,
getMatchType,
MatchType
} from "../decoration";
Expand All @@ -20,9 +19,8 @@ describe("Decoration utils", () => {
to: 5,
type: {
attrs: {
class: "MatchDecoration",
"data-match-id": "0-from:0-to:5--match-0",
style: `background-color: ${defaultMatchColours.default}07; border-bottom: 2px solid ${defaultMatchColours.default}${defaultMatchColours.defaultOpacity}`
class: "MatchDecoration MatchDecoration--default",
"data-match-id": "0-from:0-to:5--match-0"
},
spec: {
categoryId: "1",
Expand All @@ -43,9 +41,8 @@ describe("Decoration utils", () => {
to: 5,
type: {
attrs: {
class: "MatchDecoration",
"data-match-id": "0-from:0-to:5--match-0",
style: `background-color: ${defaultMatchColours.correct}07; border-bottom: 2px solid ${defaultMatchColours.correct}${defaultMatchColours.correctOpacity}`
class: "MatchDecoration MatchDecoration--is-correct",
"data-match-id": "0-from:0-to:5--match-0"
},
spec: {
categoryId: "1",
Expand Down

0 comments on commit 058fb33

Please sign in to comment.