From 8e57188ab55d239ed549365c2f777235931547f9 Mon Sep 17 00:00:00 2001 From: Philip Molares Date: Sun, 26 Mar 2023 12:30:16 +0200 Subject: [PATCH] refactor(common): extract frontmatter code into commons Signed-off-by: Philip Molares Signed-off-by: Tilman Vatteroth --- commons/src/utils/parse-url.spec.ts | 1 + .../src/components/editor-page/app-bar/app-bar.tsx | 2 +- .../editor-page/document-bar/share/share-modal.tsx | 2 +- .../editor-document-renderer.tsx | 2 +- frontend/src/redux/application-state.d.ts | 2 +- .../build-state-from-first-heading-update.spec.ts | 11 ++++++++--- ...build-state-from-set-note-data-from-server.spec.ts | 2 +- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/commons/src/utils/parse-url.spec.ts b/commons/src/utils/parse-url.spec.ts index 2884d60e6..4f412340a 100644 --- a/commons/src/utils/parse-url.spec.ts +++ b/commons/src/utils/parse-url.spec.ts @@ -5,6 +5,7 @@ */ import { MissingTrailingSlashError, WrongProtocolError } from './errors.js' import { parseUrl } from './parse-url.js' +import { describe, expect, it } from '@jest/globals' describe('validate url', () => { it("doesn't accept non-urls", () => { diff --git a/frontend/src/components/editor-page/app-bar/app-bar.tsx b/frontend/src/components/editor-page/app-bar/app-bar.tsx index b692a8be5..40d45073c 100644 --- a/frontend/src/components/editor-page/app-bar/app-bar.tsx +++ b/frontend/src/components/editor-page/app-bar/app-bar.tsx @@ -4,7 +4,6 @@ * SPDX-License-Identifier: AGPL-3.0-only */ import { useApplicationState } from '../../../hooks/common/use-application-state' -import { NoteType } from '../../../redux/note-details/types/note-details' import { NewNoteButton } from '../../common/new-note-button/new-note-button' import { ShowIf } from '../../common/show-if/show-if' import { SignInButton } from '../../landing-layout/navigation/sign-in-button' @@ -15,6 +14,7 @@ import { HelpButton } from './help-button/help-button' import { NavbarBranding } from './navbar-branding' import { ReadOnlyModeButton } from './read-only-mode-button' import { SlideModeButton } from './slide-mode-button' +import { NoteType } from '@hedgedoc/commons' import React from 'react' import { Nav, Navbar } from 'react-bootstrap' diff --git a/frontend/src/components/editor-page/document-bar/share/share-modal.tsx b/frontend/src/components/editor-page/document-bar/share/share-modal.tsx index 2c1ca1b7e..9117b5c41 100644 --- a/frontend/src/components/editor-page/document-bar/share/share-modal.tsx +++ b/frontend/src/components/editor-page/document-bar/share/share-modal.tsx @@ -5,11 +5,11 @@ */ import { useApplicationState } from '../../../../hooks/common/use-application-state' import { useBaseUrl } from '../../../../hooks/common/use-base-url' -import { NoteType } from '../../../../redux/note-details/types/note-details' import { CopyableField } from '../../../common/copyable/copyable-field/copyable-field' import type { ModalVisibilityProps } from '../../../common/modals/common-modal' import { CommonModal } from '../../../common/modals/common-modal' import { ShowIf } from '../../../common/show-if/show-if' +import { NoteType } from '@hedgedoc/commons' import React from 'react' import { Modal } from 'react-bootstrap' import { Trans, useTranslation } from 'react-i18next' diff --git a/frontend/src/components/editor-page/editor-document-renderer/editor-document-renderer.tsx b/frontend/src/components/editor-page/editor-document-renderer/editor-document-renderer.tsx index e3b9a1f54..b620a8475 100644 --- a/frontend/src/components/editor-page/editor-document-renderer/editor-document-renderer.tsx +++ b/frontend/src/components/editor-page/editor-document-renderer/editor-document-renderer.tsx @@ -5,13 +5,13 @@ */ import { useApplicationState } from '../../../hooks/common/use-application-state' import { useTrimmedNoteMarkdownContentWithoutFrontmatter } from '../../../hooks/common/use-trimmed-note-markdown-content-without-frontmatter' -import { NoteType } from '../../../redux/note-details/types/note-details' import { setRendererStatus } from '../../../redux/renderer-status/methods' import { RendererType } from '../../render-page/window-post-message-communicator/rendering-message' import type { RenderIframeProps } from '../renderer-pane/render-iframe' import { RenderIframe } from '../renderer-pane/render-iframe' import { useOnScrollWithLineOffset } from './hooks/use-on-scroll-with-line-offset' import { useScrollStateWithoutLineOffset } from './hooks/use-scroll-state-without-line-offset' +import { NoteType } from '@hedgedoc/commons' import React from 'react' export type EditorDocumentRendererProps = Omit< diff --git a/frontend/src/redux/application-state.d.ts b/frontend/src/redux/application-state.d.ts index c1fb28d67..3d20406ac 100644 --- a/frontend/src/redux/application-state.d.ts +++ b/frontend/src/redux/application-state.d.ts @@ -7,10 +7,10 @@ import type { Config } from '../api/config/types' import type { HistoryEntryWithOrigin } from '../api/history/types' import type { DarkModeConfig } from './dark-mode/types' import type { EditorConfig } from './editor/types' +import type { NoteDetails } from './note-details/types/note-details' import type { RealtimeStatus } from './realtime/types' import type { RendererStatus } from './renderer-status/types' import type { OptionalUserState } from './user/types' -import type { NoteDetails } from '@hedgedoc/commons' export interface ApplicationState { user: OptionalUserState diff --git a/frontend/src/redux/note-details/reducers/build-state-from-first-heading-update.spec.ts b/frontend/src/redux/note-details/reducers/build-state-from-first-heading-update.spec.ts index 8cbbafbc8..254d9bffa 100644 --- a/frontend/src/redux/note-details/reducers/build-state-from-first-heading-update.spec.ts +++ b/frontend/src/redux/note-details/reducers/build-state-from-first-heading-update.spec.ts @@ -7,9 +7,14 @@ import { initialState } from '../initial-state' import { buildStateFromFirstHeadingUpdate } from './build-state-from-first-heading-update' // noinspection JSUnusedGlobalSymbols -jest.mock('../generate-note-title', () => ({ - generateNoteTitle: () => 'generated title' -})) +jest.mock( + '@hedgedoc/commons', + () => + ({ + ...jest.requireActual('@hedgedoc/commons'), + generateNoteTitle: () => 'generated title' + } as Record) +) describe('build state from first heading update', () => { it('generates a new state with the given first heading', () => { diff --git a/frontend/src/redux/note-details/reducers/build-state-from-set-note-data-from-server.spec.ts b/frontend/src/redux/note-details/reducers/build-state-from-set-note-data-from-server.spec.ts index de8929118..9338fab1d 100644 --- a/frontend/src/redux/note-details/reducers/build-state-from-set-note-data-from-server.spec.ts +++ b/frontend/src/redux/note-details/reducers/build-state-from-set-note-data-from-server.spec.ts @@ -7,8 +7,8 @@ import type { Note } from '../../../api/notes/types' import * as buildStateFromUpdatedMarkdownContentModule from '../build-state-from-updated-markdown-content' import { initialSlideOptions } from '../initial-state' import type { NoteDetails } from '../types/note-details' -import { NoteTextDirection, NoteType } from '../types/note-details' import { buildStateFromServerDto } from './build-state-from-set-note-data-from-server' +import { NoteTextDirection, NoteType } from '@hedgedoc/commons' import { DateTime } from 'luxon' import { Mock } from 'ts-mockery'