fix(frontend): fix motd e2e test

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-10-24 08:57:42 +02:00 committed by Erik Michelson
parent dd4e50103f
commit dfbd45301c
6 changed files with 31 additions and 9 deletions

View file

@ -8,9 +8,10 @@
import React, { useCallback, useMemo, useState } from 'react'
import { useMotdContextValue } from '../../motd/motd-context'
import { useLocalStorage } from 'react-use'
import { MOTD_LOCAL_STORAGE_KEY } from './fetch-motd'
import { MotdModal } from './motd-modal'
import { testId } from '../../../utils/test-id'
import { isTestMode } from '../../../utils/test-modes'
import { IGNORE_MOTD, MOTD_LOCAL_STORAGE_KEY } from './local-storage-keys'
/**
* Reads the motd from the context and shows it in a modal.
@ -19,13 +20,22 @@ import { testId } from '../../../utils/test-id'
*/
export const CachedMotdModal: React.FC = () => {
const contextValue = useMotdContextValue()
const [cachedLastModified, saveLocalStorage] = useLocalStorage<string>(MOTD_LOCAL_STORAGE_KEY, undefined)
const [cachedLastModified, saveLocalStorage] = useLocalStorage<string>(MOTD_LOCAL_STORAGE_KEY, undefined, {
raw: true
})
const [dismissed, setDismissed] = useState(false)
const show = useMemo(() => {
const lastModified = contextValue?.lastModified
return cachedLastModified !== lastModified && lastModified !== undefined && !dismissed
if (cachedLastModified === IGNORE_MOTD && isTestMode) {
return false
}
if (cachedLastModified === lastModified || lastModified === undefined) {
return false
}
return !dismissed
}, [cachedLastModified, contextValue?.lastModified, dismissed])
const doDismiss = useCallback(() => {

View file

@ -5,8 +5,6 @@
*/
import { defaultConfig } from '../../../api/common/default-config'
export const MOTD_LOCAL_STORAGE_KEY = 'motd.lastModified'
export interface MotdApiResponse {
motdText: string
lastModified: string

View file

@ -0,0 +1,8 @@
/*
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
export const MOTD_LOCAL_STORAGE_KEY: string = 'motd.lastModified'
export const IGNORE_MOTD: string = 'IGNORE_MOTD'