Fix mock test env check outside of browser
This commit is contained in:
parent
dbff1ab4d1
commit
3f074a7737
11 changed files with 47 additions and 22 deletions
|
@ -142,21 +142,20 @@ export function FromSomeoneToGroup(): JSX.Element {
|
|||
}
|
||||
|
||||
export function LongSearchResult(): JSX.Element {
|
||||
const snippets = [
|
||||
'This is a really <<left>>detail<<right>>ed long line which will wrap and only be cut off after it gets to three lines. So maybe this will make it in as well?',
|
||||
"Okay, here are the <<left>>detail<<right>>s:\n\n1355 Ridge Way\nCode: 234\n\nI'm excited!",
|
||||
];
|
||||
|
||||
const props1 = useProps({
|
||||
from: someone,
|
||||
to: me,
|
||||
snippet: snippets[0],
|
||||
snippet:
|
||||
'This is a really <<left>>detail<<right>>ed long line which will wrap and only be cut off after it gets to three lines. So maybe this will make it in as well?',
|
||||
body: 'This is a really detailed long line which will wrap and only be cut off after it gets to three lines. So maybe this will make it in as well?',
|
||||
});
|
||||
|
||||
const props2 = useProps({
|
||||
from: someone,
|
||||
to: me,
|
||||
snippet: snippets[1],
|
||||
snippet:
|
||||
"Okay, here are the <<left>>detail<<right>>s:\n\n1355 Ridge Way\nCode: 234\n\nI'm excited!",
|
||||
body: "Okay, here are the details:\n\n1355 Ridge Way\nCode: 234\n\nI'm excited!",
|
||||
});
|
||||
|
||||
return (
|
||||
|
|
|
@ -4,16 +4,15 @@
|
|||
import { config } from './config';
|
||||
import {
|
||||
getEnvironment,
|
||||
isTestEnvironment,
|
||||
parseEnvironment,
|
||||
setEnvironment,
|
||||
} from '../environment';
|
||||
|
||||
setEnvironment(parseEnvironment(config.environment));
|
||||
setEnvironment(
|
||||
parseEnvironment(config.environment),
|
||||
config.isMockTestEnvironment
|
||||
);
|
||||
|
||||
const environment = getEnvironment();
|
||||
|
||||
const isTestOrMockEnvironment =
|
||||
isTestEnvironment(environment) || Boolean(process.env.MOCK_TEST);
|
||||
|
||||
export { environment, isTestOrMockEnvironment };
|
||||
export { environment };
|
||||
|
|
|
@ -12,6 +12,7 @@ export enum Environment {
|
|||
}
|
||||
|
||||
let environment: undefined | Environment;
|
||||
let isMockTestEnvironment: undefined | boolean;
|
||||
|
||||
export function getEnvironment(): Environment {
|
||||
if (environment === undefined) {
|
||||
|
@ -26,12 +27,16 @@ export function getEnvironment(): Environment {
|
|||
/**
|
||||
* Sets the current environment. Should be called early in a process's life, and can only
|
||||
* be called once.
|
||||
*
|
||||
* isMockTestEnv is used when running tests that require a non-"test" environment but
|
||||
* need to mock certain behaviors.
|
||||
*/
|
||||
export function setEnvironment(env: Environment): void {
|
||||
export function setEnvironment(env: Environment, isMockTestEnv: boolean): void {
|
||||
if (environment !== undefined) {
|
||||
throw new Error('Environment has already been set');
|
||||
}
|
||||
environment = env;
|
||||
isMockTestEnvironment = isMockTestEnv;
|
||||
}
|
||||
|
||||
export const parseEnvironment = makeEnumParser(
|
||||
|
@ -41,3 +46,10 @@ export const parseEnvironment = makeEnumParser(
|
|||
|
||||
export const isTestEnvironment = (env: Environment): boolean =>
|
||||
env === Environment.Test;
|
||||
|
||||
export const isTestOrMockEnvironment = (): boolean => {
|
||||
if (isMockTestEnvironment == null) {
|
||||
throw new Error('Mock test environment not set');
|
||||
}
|
||||
return isTestEnvironment(getEnvironment()) || isMockTestEnvironment;
|
||||
};
|
||||
|
|
|
@ -45,6 +45,7 @@ export const rendererConfigSchema = z.object({
|
|||
dnsFallback: DNSFallbackSchema,
|
||||
ciBackupPath: configOptionalStringSchema,
|
||||
environment: environmentSchema,
|
||||
isMockTestEnvironment: z.boolean(),
|
||||
homePath: configRequiredStringSchema,
|
||||
hostname: configRequiredStringSchema,
|
||||
installPath: configRequiredStringSchema,
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// Copyright 2024 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { isTestOrMockEnvironment } from '../environment';
|
||||
|
||||
/**
|
||||
* Left-to-Right Isolate
|
||||
* Sets direction to LTR and isolates the embedded content from the surrounding text
|
||||
|
@ -208,7 +210,7 @@ export function _bidiIsolate(text: string): string {
|
|||
* ```
|
||||
*/
|
||||
export function bidiIsolate(text: string): string {
|
||||
if (window.SignalContext.isTestOrMockEnvironment()) {
|
||||
if (isTestOrMockEnvironment()) {
|
||||
// Turn this off in tests to make it easier to compare strings
|
||||
return text;
|
||||
}
|
||||
|
|
|
@ -12,13 +12,14 @@ import { activeWindowService } from '../context/activeWindowService';
|
|||
import { config } from '../context/config';
|
||||
import { createNativeThemeListener } from '../context/createNativeThemeListener';
|
||||
import { createSetting } from '../util/preload';
|
||||
import { environment, isTestOrMockEnvironment } from '../context/environment';
|
||||
import { environment } from '../context/environment';
|
||||
import {
|
||||
localeDisplayNames,
|
||||
countryDisplayNames,
|
||||
localeMessages,
|
||||
} from '../context/localeMessages';
|
||||
import { waitForSettingsChange } from '../context/waitForSettingsChange';
|
||||
import { isTestOrMockEnvironment } from '../environment';
|
||||
|
||||
const emojiListCache = new Map<string, LocaleEmojiListType>();
|
||||
|
||||
|
@ -71,7 +72,7 @@ export const MinimalSignalContext: MinimalSignalContextType = {
|
|||
getHourCyclePreference: () => config.hourCyclePreference,
|
||||
getPreferredSystemLocales: () => config.preferredSystemLocales,
|
||||
getLocaleOverride: () => config.localeOverride,
|
||||
isTestOrMockEnvironment: () => isTestOrMockEnvironment,
|
||||
isTestOrMockEnvironment,
|
||||
nativeThemeListener: createNativeThemeListener(ipcRenderer, window),
|
||||
restartApp: () => ipcRenderer.send('restart'),
|
||||
OS: {
|
||||
|
|
|
@ -9,6 +9,7 @@ import { i18n } from '../sandboxedInit';
|
|||
import { Preferences } from '../../components/Preferences';
|
||||
import { startInteractionMode } from '../../services/InteractionMode';
|
||||
import { strictAssert } from '../../util/assert';
|
||||
import { parseEnvironment, setEnvironment } from '../../environment';
|
||||
|
||||
const { SettingsWindowProps } = window.Signal;
|
||||
|
||||
|
@ -16,6 +17,11 @@ strictAssert(SettingsWindowProps, 'window values not provided');
|
|||
|
||||
startInteractionMode();
|
||||
|
||||
setEnvironment(
|
||||
parseEnvironment(window.SignalContext.getEnvironment()),
|
||||
window.SignalContext.isTestOrMockEnvironment()
|
||||
);
|
||||
|
||||
SettingsWindowProps.onRender(
|
||||
({
|
||||
addCustomColor,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue