Skip to content

Kan endre fonttyper #1219

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

Merged
merged 18 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
79 changes: 20 additions & 59 deletions skribenten-web/frontend/cypress/utils/brevredigeringTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ import type {
SaksbehandlerValg,
} from "~/types/brev";
import type {
AnyBlock,
Content,
EditedLetter,
Item,
ItemList,
LiteralValue,
ParagraphBlock,
Sakspart,
Signatur,
TextContent,
Title1Block,
VariableValue,
} from "~/types/brevbakerTypes";
import {
type AnyBlock,
type EditedLetter,
type LiteralValue,
type Sakspart,
type Signatur,
} from "~/types/brevbakerTypes";
import type { Nullable } from "~/types/Nullable";

import { newLiteral, newVariable } from "../../src/Brevredigering/LetterEditor/actions/common";
import { SpraakKode } from "../../src/types/apiTypes";
import { Distribusjonstype } from "../../src/types/brev";
import { FontType } from "../../src/types/brevbakerTypes";

export const nyBrevResponse = ({
info = nyBrevInfo({}),
Expand Down Expand Up @@ -68,42 +68,15 @@ export const nyRedigertBrev = (args: {
parentId: null,
editable: true,
content: [
{
id: 1_507_865_607,
parentId: 272_720_182,
text: "We received your application for ",
editedText: null,
type: "LITERAL",
tags: [],
},
{
id: -726_051_414,
parentId: 272_720_182,
text: "alderspensjon",
type: "VARIABLE",
},
{
newLiteral({ id: 1_507_865_607, parentId: 272_720_182, text: "We received your application for " }),
newVariable({ id: -726_051_414, parentId: 272_720_182, text: "alderspensjon" }),
newLiteral({
id: -711_242_333,
parentId: 272_720_182,
text: " from the Norwegian National Insurance Scheme on ",
editedText: null,
type: "LITERAL",
tags: [],
},
{
id: -694_080_035,
parentId: 272_720_182,
text: "24 July 2024",
type: "VARIABLE",
},
{
id: 46,
parentId: 272_720_182,
text: ".",
editedText: null,
type: "LITERAL",
tags: [],
},
}),
newVariable({ id: -694_080_035, parentId: 272_720_182, text: "24 July 2024" }),
newLiteral({ id: -1_114_690_237, parentId: 272_720_182, text: "." }),
],
deletedContent: [],
type: "PARAGRAPH",
Expand All @@ -113,28 +86,13 @@ export const nyRedigertBrev = (args: {
parentId: null,
editable: true,
content: [
{
newLiteral({
id: -1_114_690_237,
parentId: 822_540_105,
text: "Our processing time for this type of application is usually ",
editedText: null,
type: "LITERAL",
tags: [],
},
{
id: 1_834_595_758,
parentId: 822_540_105,
text: "10",
type: "VARIABLE",
},
{
id: 1_838_606_639,
parentId: 822_540_105,
text: " weeks.",
editedText: null,
type: "LITERAL",
tags: [],
},
}),
newVariable({ id: 1_834_595_758, parentId: 822_540_105, text: "10" }),
newLiteral({ id: 1_838_606_639, parentId: 822_540_105, text: " weeks." }),
],
deletedContent: [],
type: "PARAGRAPH",
Expand Down Expand Up @@ -192,6 +150,8 @@ export const nyLiteral = (args: { id?: Nullable<number>; text?: string }): Liter
parentId: null,
text: args.text ?? "ny literal default text",
editedText: args.text ?? "ny literal default edited-text",
fontType: FontType.PLAIN,
editedFontType: null,
tags: [],
});

Expand All @@ -201,6 +161,7 @@ export const nyVariable = (args: { id?: Nullable<number>; name?: string; text?:
parentId: null,
name: args.name,
text: args.text ?? "ny variable default text",
fontType: FontType.PLAIN,
});

//TODO - kan heller bruke newItem fra common.ts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type { Draft } from "immer";

import { MergeTarget } from "~/Brevredigering/LetterEditor/actions/merge";
import { updateLiteralText } from "~/Brevredigering/LetterEditor/actions/updateContentText";
import { isFritekst, isLiteral } from "~/Brevredigering/LetterEditor/model/utils";
import type { BrevResponse } from "~/types/brev";
import type {
Content,
Expand All @@ -18,10 +15,14 @@ import type {
Title1Block,
TITLE2,
Title2Block,
VariableValue,
} from "~/types/brevbakerTypes";
import { ITEM_LIST, LITERAL, NEW_LINE, PARAGRAPH, VARIABLE } from "~/types/brevbakerTypes";
import type { Nullable } from "~/types/Nullable";

import { MergeTarget } from "../../../Brevredigering/LetterEditor/actions/merge";
import { updateLiteralText } from "../../../Brevredigering/LetterEditor/actions/updateContentText";
import { isFritekst, isLiteral } from "../../../Brevredigering/LetterEditor/model/utils";
import { FontType, ITEM_LIST, LITERAL, NEW_LINE, PARAGRAPH, VARIABLE } from "../../../types/brevbakerTypes";
import type { LetterEditorState } from "../model/state";

export function cleanseText(text: string): string {
Expand Down Expand Up @@ -199,13 +200,14 @@ export function newTitle(args: {

export function newParagraph(args: {
id?: Nullable<number>;
parentId?: Nullable<number>;
content: Content[];
deletedContent?: number[];
}): ParagraphBlock {
return {
type: PARAGRAPH,
id: args.id ?? null,
parentId: null,
parentId: args.parentId ?? null,
editable: true,
deletedContent: args.deletedContent ?? [],
content: args.content,
Expand All @@ -214,20 +216,40 @@ export function newParagraph(args: {

export function newLiteral(args: {
id?: Nullable<number>;
parentId?: Nullable<number>;
text: string;
editedText?: Nullable<string>;
fontType?: Nullable<FontType>;
editedFontType?: Nullable<FontType>;
tags?: ElementTags[];
}): LiteralValue {
return {
type: LITERAL,
id: args.id ?? null,
parentId: null,
parentId: args.parentId ?? null,
text: args.text,
editedText: args.editedText ?? null,
editedFontType: args.editedFontType ?? null,
fontType: FontType.PLAIN,
tags: args.tags ?? [],
};
}

export const newVariable = (args: {
id?: Nullable<number>;
text: string;
parentId?: Nullable<number>;
fontType?: FontType;
}): VariableValue => {
return {
type: VARIABLE,
id: args.id ?? null,
parentId: args.parentId ?? null,
text: args.text,
fontType: args.fontType ?? FontType.PLAIN,
};
};

export function newItem({ content }: { content: TextContent[] }): Item {
return {
id: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { paste } from "~/Brevredigering/LetterEditor/actions/paste";
import { create } from "./common";
import { merge } from "./merge";
import { split } from "./split";
import { switchFontType } from "./switchFontType";
import { switchTypography } from "./switchTypography";
import { toggleBulletList } from "./toggleBulletList";
import { updateContentText } from "./updateContentText";
Expand All @@ -19,5 +20,6 @@ const Actions = {
switchTypography,
updateContentText,
toggleBulletList,
switchFontType,
};
export default Actions;
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import type { Draft } from "immer";
import { produce } from "immer";

import type { AnyBlock, ItemList } from "~/types/brevbakerTypes";

import {
addElements,
getMergeIds,
newLiteral,
removeElements,
text,
} from "~/Brevredigering/LetterEditor/actions/common";
import type { AnyBlock, ItemList } from "~/types/brevbakerTypes";
import { NEW_LINE } from "~/types/brevbakerTypes";
import { ITEM_LIST, LITERAL, VARIABLE } from "~/types/brevbakerTypes";

} from "../../../Brevredigering/LetterEditor/actions/common";
import { ITEM_LIST, LITERAL, NEW_LINE, VARIABLE } from "../../../types/brevbakerTypes";
import type { Action } from "../lib/actions";
import type { Focus, LetterEditorState } from "../model/state";
import { isEmptyBlock, isEmptyContent, isEmptyItem, isTextContent } from "../model/utils";
Expand Down
Loading