mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-19 05:55:34 +09:00
chore(workspace): tighten quality gates (#2230)
This commit is contained in:
1 parent
e6e4c6f7b5
commit
5c2dca1c51
123 files changed
+4925
-5640
No files matched your search
@@ -1,167 +0,0 @@
|
||||
// @vitest-environment happy-dom
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {installVoiceMenuTestBootstrap} from '@app/features/ui/action_menu/items/__fixtures__/VoiceMenuTestBootstrap';
|
||||
import type {VoiceParticipantMenuSource} from '@app/features/ui/action_menu/items/VoiceParticipantMenuTypes';
|
||||
import type {User} from '@app/features/user/models/User';
|
||||
import {act, createElement} from 'react';
|
||||
import {createRoot, type Root} from 'react-dom/client';
|
||||
import {afterEach, expect, test, vi} from 'vitest';
|
||||
|
||||
vi.mock('@lingui/core/macro', () => {
|
||||
const descriptor = (value: unknown): unknown => (typeof value === 'string' ? {message: value} : value);
|
||||
return {msg: descriptor, t: descriptor, plural: () => '', select: () => '', selectOrdinal: () => ''};
|
||||
});
|
||||
vi.mock('@lingui/react/macro', () => ({
|
||||
Trans: () => null,
|
||||
useLingui: () => ({i18n: {_: (descriptor: {message?: string}) => descriptor.message ?? '', locale: 'en'}}),
|
||||
}));
|
||||
|
||||
installVoiceMenuTestBootstrap();
|
||||
|
||||
const {useVoiceParticipantMenuData} = await import('@app/features/ui/action_menu/items/VoiceParticipantMenuData');
|
||||
const {default: EntranceSoundListenerPrefs} = await import('@app/features/voice/state/EntranceSoundListenerPrefs');
|
||||
const {default: MediaEngine} = await import('@app/features/voice/engine/MediaEngineFacade');
|
||||
const {observer} = await import('mobx-react-lite');
|
||||
|
||||
(globalThis as {IS_REACT_ACT_ENVIRONMENT?: boolean}).IS_REACT_ACT_ENVIRONMENT = true;
|
||||
|
||||
const TARGET_USER = {id: '111', username: 'target'} as unknown as User;
|
||||
const PARTICIPANT_SOURCE: VoiceParticipantMenuSource = {kind: 'participant'};
|
||||
const CAMERA_SOURCE: VoiceParticipantMenuSource = {kind: 'camera'};
|
||||
const noop = (): void => undefined;
|
||||
|
||||
interface MenuLeaf {
|
||||
label?: string;
|
||||
checked?: boolean;
|
||||
value?: number;
|
||||
items?: Array<MenuLeaf>;
|
||||
}
|
||||
|
||||
interface MenuGroup {
|
||||
items: Array<MenuLeaf>;
|
||||
}
|
||||
|
||||
const shadowedMediaEngineKeys: Array<string> = [];
|
||||
let root: Root | null = null;
|
||||
let container: HTMLDivElement | null = null;
|
||||
|
||||
function shadowMediaEngine(key: string, value: unknown): void {
|
||||
Object.defineProperty(MediaEngine, key, {value, configurable: true, writable: true});
|
||||
shadowedMediaEngineKeys.push(key);
|
||||
}
|
||||
|
||||
function findLeaf(groups: Array<MenuGroup>, label: string): MenuLeaf | null {
|
||||
for (const group of groups) {
|
||||
for (const item of group.items) {
|
||||
if (item.label === label) return item;
|
||||
for (const child of item.items ?? []) {
|
||||
if (child.label === label) return child;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function renderMenu(
|
||||
options: Parameters<typeof useVoiceParticipantMenuData>[0],
|
||||
): Promise<{groups: () => Array<MenuGroup>}> {
|
||||
const latest: {groups: Array<MenuGroup>} = {groups: []};
|
||||
const Probe = observer(function Probe() {
|
||||
latest.groups = useVoiceParticipantMenuData(options).groups as unknown as Array<MenuGroup>;
|
||||
return null;
|
||||
});
|
||||
container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
root = createRoot(container);
|
||||
await act(async () => {
|
||||
root?.render(createElement(Probe));
|
||||
});
|
||||
return {groups: () => latest.groups};
|
||||
}
|
||||
|
||||
afterEach(async () => {
|
||||
await act(async () => {
|
||||
root?.unmount();
|
||||
});
|
||||
root = null;
|
||||
container?.remove();
|
||||
container = null;
|
||||
for (const key of shadowedMediaEngineKeys.splice(0)) {
|
||||
delete (MediaEngine as unknown as Record<string, unknown>)[key];
|
||||
}
|
||||
EntranceSoundListenerPrefs.reset(TARGET_USER.id);
|
||||
});
|
||||
|
||||
test('entrance-sound checkbox tracks the pref while the menu stays open', async () => {
|
||||
const menu = await renderMenu({
|
||||
user: TARGET_USER,
|
||||
surface: 'call-tile',
|
||||
source: PARTICIPANT_SOURCE,
|
||||
onClose: noop,
|
||||
});
|
||||
expect(findLeaf(menu.groups(), 'Mute entrance sound')?.checked).toBe(false);
|
||||
await act(async () => {
|
||||
EntranceSoundListenerPrefs.setMuted(TARGET_USER.id, true);
|
||||
});
|
||||
expect(findLeaf(menu.groups(), 'Mute entrance sound')?.checked).toBe(true);
|
||||
await act(async () => {
|
||||
EntranceSoundListenerPrefs.setVolume(TARGET_USER.id, 42);
|
||||
});
|
||||
expect(findLeaf(menu.groups(), 'Entrance sound volume')?.value).toBe(42);
|
||||
});
|
||||
|
||||
test('disable video locally is offered for another user camera tile in the local room', async () => {
|
||||
shadowMediaEngine('connected', true);
|
||||
shadowMediaEngine('connectionId', 'self-connection');
|
||||
shadowMediaEngine('channelId', 'channel-1');
|
||||
shadowMediaEngine('getVoiceStateByConnectionId', (connectionId: string) =>
|
||||
connectionId === 'target-connection' ? {channel_id: 'channel-1', user_id: TARGET_USER.id} : null,
|
||||
);
|
||||
const menu = await renderMenu({
|
||||
user: TARGET_USER,
|
||||
connectionId: 'target-connection',
|
||||
surface: 'call-tile',
|
||||
source: CAMERA_SOURCE,
|
||||
onClose: noop,
|
||||
});
|
||||
expect(findLeaf(menu.groups(), 'Disable video locally')).not.toBeNull();
|
||||
});
|
||||
|
||||
test('offers a single inline user-volume slider and no nested secondary submenu wrapper', async () => {
|
||||
const REMOVED_SUBMENU_LABELS = [
|
||||
'Media controls',
|
||||
'Device controls',
|
||||
'Display options',
|
||||
'User actions',
|
||||
'Relationship',
|
||||
'Relationship actions',
|
||||
'Moderation',
|
||||
'Moderation actions',
|
||||
'Advanced',
|
||||
'Advanced actions',
|
||||
];
|
||||
shadowMediaEngine('connected', true);
|
||||
shadowMediaEngine('connectionId', 'self-connection');
|
||||
shadowMediaEngine('channelId', 'channel-1');
|
||||
shadowMediaEngine('getVoiceStateByConnectionId', (connectionId: string) =>
|
||||
connectionId === 'target-connection' ? {channel_id: 'channel-1', user_id: TARGET_USER.id} : null,
|
||||
);
|
||||
const menu = await renderMenu({
|
||||
user: TARGET_USER,
|
||||
connectionId: 'target-connection',
|
||||
surface: 'participant-list',
|
||||
source: PARTICIPANT_SOURCE,
|
||||
onClose: noop,
|
||||
});
|
||||
const groups = menu.groups();
|
||||
const topLevelItems = groups.flatMap((group) => group.items);
|
||||
const topLevelSliders = topLevelItems.filter((item) => typeof item.value === 'number');
|
||||
expect(topLevelSliders).toHaveLength(1);
|
||||
expect(topLevelSliders[0]?.label).toBe('User volume');
|
||||
const submenuLabels = topLevelItems.filter((item) => Array.isArray(item.items)).map((item) => item.label);
|
||||
expect(submenuLabels.every((label) => label === 'Entrance sound')).toBe(true);
|
||||
for (const label of REMOVED_SUBMENU_LABELS) {
|
||||
expect(findLeaf(groups, label)).toBeNull();
|
||||
}
|
||||
});
|
||||
-116
@@ -1,116 +0,0 @@
|
||||
// @vitest-environment happy-dom
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {installVoiceMenuTestBootstrap} from '@app/features/ui/action_menu/items/__fixtures__/VoiceMenuTestBootstrap';
|
||||
import type {VoiceParticipantMenuScreenShareSource} from '@app/features/ui/action_menu/items/VoiceParticipantMenuTypes';
|
||||
import type {I18n} from '@lingui/core';
|
||||
import {expect, test, vi} from 'vitest';
|
||||
|
||||
vi.mock('@lingui/core/macro', () => {
|
||||
const descriptor = (value: unknown): unknown => (typeof value === 'string' ? {message: value} : value);
|
||||
return {msg: descriptor, t: descriptor, plural: () => '', select: () => '', selectOrdinal: () => ''};
|
||||
});
|
||||
vi.mock('@lingui/react/macro', () => ({
|
||||
Trans: () => null,
|
||||
useLingui: () => ({i18n: {_: (descriptor: {message?: string}) => descriptor.message ?? '', locale: 'en'}}),
|
||||
}));
|
||||
vi.mock('@app/features/voice/components/ActiveScreenShareMenu', () => ({
|
||||
changeActiveScreenShare: vi.fn(async () => undefined),
|
||||
stopActiveScreenShare: vi.fn(async () => undefined),
|
||||
}));
|
||||
vi.mock('@app/features/voice/components/modals/ScreenSharePickerModal', () => ({
|
||||
openScreenSharePreviewPrivacyModal: vi.fn(),
|
||||
}));
|
||||
vi.mock('@app/features/voice/engine/MediaEngineFacade', () => ({
|
||||
default: {
|
||||
applyLocalAudioPreferencesForUser: vi.fn(),
|
||||
getVoiceStateByConnectionId: () => null,
|
||||
connectionId: null,
|
||||
},
|
||||
}));
|
||||
vi.mock('@app/features/voice/state/PopoutWindowManager', () => ({
|
||||
default: {openTilePopout: vi.fn()},
|
||||
isVoicePopoutSupported: () => false,
|
||||
}));
|
||||
vi.mock('@app/features/voice/state/StreamAudioPrefs', () => ({
|
||||
default: {setMuted: vi.fn(), setVolume: vi.fn()},
|
||||
}));
|
||||
vi.mock('@app/features/voice/state/VoiceSettings', () => ({
|
||||
default: {showMyOwnScreenShare: false, pauseOwnScreenSharePreviewOnUnfocus: false},
|
||||
}));
|
||||
vi.mock('@app/features/voice/commands/VoiceSettingsCommands', () => ({
|
||||
update: vi.fn(),
|
||||
}));
|
||||
|
||||
installVoiceMenuTestBootstrap();
|
||||
|
||||
const {buildVoiceParticipantStreamMenu} = await import(
|
||||
'@app/features/ui/action_menu/items/VoiceParticipantStreamMenuBuilder'
|
||||
);
|
||||
|
||||
const i18n = {
|
||||
locale: 'en',
|
||||
_: (descriptor: {message?: string}) => descriptor.message ?? '',
|
||||
} as unknown as I18n;
|
||||
|
||||
interface MenuLeaf {
|
||||
label?: string;
|
||||
items?: Array<MenuLeaf>;
|
||||
}
|
||||
|
||||
function streamMenu(source: VoiceParticipantMenuScreenShareSource): Array<{items: Array<MenuLeaf>}> {
|
||||
return buildVoiceParticipantStreamMenu({
|
||||
i18n,
|
||||
userId: '111',
|
||||
channelId: null,
|
||||
participantIdentity: 'user_111_conn',
|
||||
displayName: 'Alice',
|
||||
isCurrentUserConnectedToVoice: false,
|
||||
source,
|
||||
streamVolume: 100,
|
||||
isStreamMuted: false,
|
||||
showMyOwnScreenShare: false,
|
||||
pauseOwnScreenSharePreviewOnUnfocus: false,
|
||||
onClose: () => undefined,
|
||||
}) as unknown as Array<{items: Array<MenuLeaf>}>;
|
||||
}
|
||||
|
||||
function findLeaf(groups: Array<{items: Array<MenuLeaf>}>, label: string): MenuLeaf | null {
|
||||
for (const group of groups) {
|
||||
for (const item of group.items) {
|
||||
if (item.label === label) return item;
|
||||
for (const child of item.items ?? []) {
|
||||
if (child.label === label) return child;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
const OWN_STREAM_SOURCE: VoiceParticipantMenuScreenShareSource = {
|
||||
kind: 'screen-share',
|
||||
streamKey: 'stream-key',
|
||||
state: {kind: 'own'},
|
||||
};
|
||||
|
||||
const WATCHED_REMOTE_STREAM_SOURCE: VoiceParticipantMenuScreenShareSource = {
|
||||
kind: 'screen-share',
|
||||
streamKey: 'stream-key',
|
||||
state: {kind: 'remote-watched', hasAudio: true, onStopWatching: () => undefined},
|
||||
};
|
||||
|
||||
test('own stream keeps a More options submenu with the screen-share preferences', () => {
|
||||
const groups = streamMenu(OWN_STREAM_SOURCE);
|
||||
const moreOptions = findLeaf(groups, 'More options');
|
||||
expect(moreOptions).not.toBeNull();
|
||||
expect(findLeaf(groups, 'Show My Screen Share')).not.toBeNull();
|
||||
expect(findLeaf(groups, 'Report Problem')).toBeNull();
|
||||
});
|
||||
|
||||
test('remote watched stream omits the now-empty More options submenu and keeps audio controls', () => {
|
||||
const groups = streamMenu(WATCHED_REMOTE_STREAM_SOURCE);
|
||||
expect(findLeaf(groups, 'More options')).toBeNull();
|
||||
expect(findLeaf(groups, 'Mute')).not.toBeNull();
|
||||
expect(findLeaf(groups, 'Stream volume')).not.toBeNull();
|
||||
expect(findLeaf(groups, 'Report Problem')).toBeNull();
|
||||
});
|
||||
@@ -1,71 +0,0 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
const HARNESS_ENDPOINT = 'https://primary.test/api';
|
||||
|
||||
export function installVoiceMenuTestBootstrap(): void {
|
||||
const host = globalThis as unknown as {window?: Record<string, unknown>};
|
||||
if (typeof host.window === 'undefined') {
|
||||
host.window = host as unknown as Record<string, unknown>;
|
||||
}
|
||||
host.window.__FLUXER_BOOTSTRAP__ = {
|
||||
config: {
|
||||
releaseChannel: 'stable',
|
||||
bootstrapApiEndpoint: HARNESS_ENDPOINT,
|
||||
bootstrapApiPublicEndpoint: HARNESS_ENDPOINT,
|
||||
},
|
||||
instance: {
|
||||
api_code_version: Number.MAX_SAFE_INTEGER,
|
||||
endpoints: {
|
||||
api: HARNESS_ENDPOINT,
|
||||
api_client: HARNESS_ENDPOINT,
|
||||
api_public: HARNESS_ENDPOINT,
|
||||
gateway: 'wss://gateway.primary.test',
|
||||
media: 'https://media.primary.test',
|
||||
static_cdn: 'https://cdn.primary.test',
|
||||
marketing: 'https://primary.test',
|
||||
admin: 'https://admin.primary.test',
|
||||
invite: 'https://primary.test/invite',
|
||||
gift: 'https://primary.test/gift',
|
||||
webapp: 'https://app.primary.test',
|
||||
upload_relay: 'https://upload.primary.test',
|
||||
},
|
||||
captcha: {provider: 'none', hcaptcha_site_key: null, turnstile_site_key: null},
|
||||
features: {
|
||||
voice_enabled: false,
|
||||
stripe_enabled: false,
|
||||
self_hosted: false,
|
||||
presigned_attachment_uploads: false,
|
||||
emails_enabled: false,
|
||||
},
|
||||
gif: {provider: 'klipy', display_name: 'Klipy', attribution_required: false},
|
||||
sso: {enabled: false, enforced: false, display_name: null, redirect_uri: ''},
|
||||
registration: {mode: 'open', admin_registration_urls_enabled: true},
|
||||
community: {single_community: false, single_community_guild_id: null, direct_messages_disabled: false},
|
||||
services: {gif_enabled: true, youtube_enabled: false, bluesky_enabled: false},
|
||||
limits: undefined,
|
||||
push: {public_vapid_key: null},
|
||||
app_public: {
|
||||
branding: {
|
||||
product_name: 'Fluxer',
|
||||
icon_url: null,
|
||||
symbol_url: null,
|
||||
logo_url: null,
|
||||
wordmark_url: null,
|
||||
favicon_url: null,
|
||||
theme_color: null,
|
||||
},
|
||||
setup: {configured: true, admin_url: null},
|
||||
legal: {terms_url: null, privacy_url: null},
|
||||
registration: {collect_date_of_birth: true},
|
||||
},
|
||||
},
|
||||
geoip: {
|
||||
countryCode: null,
|
||||
regionCode: null,
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
ageRestrictedGeos: [],
|
||||
ageBlockedGeos: [],
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -6,9 +6,11 @@ import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
|
||||
|
||||
async function loadTick() {
|
||||
vi.resetModules();
|
||||
const {Logger} = await import('@app/features/platform/utils/AppLogger');
|
||||
const debug = vi.spyOn(Logger.prototype, 'debug').mockImplementation(() => undefined);
|
||||
const {default: Window} = await import('@app/features/window/state/Window');
|
||||
const {default: Tick} = await import('@app/features/ui/state/Tick');
|
||||
return {Tick, Window};
|
||||
return {debug, Tick, Window};
|
||||
}
|
||||
|
||||
describe('Tick', () => {
|
||||
@@ -17,14 +19,16 @@ describe('Tick', () => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('keeps counting while the window is visible but not focused', async () => {
|
||||
const {Tick, Window} = await loadTick();
|
||||
const {debug, Tick, Window} = await loadTick();
|
||||
const dispose = autorun(() => Tick.nowSecond);
|
||||
const started = Tick.nowSecond;
|
||||
Window.setFocused(false);
|
||||
expect(debug).toHaveBeenCalledExactlyOnceWith('Window focus changed: false');
|
||||
vi.advanceTimersByTime(3000);
|
||||
expect(Window.visible).toBe(true);
|
||||
expect(Tick.nowSecond).toBe(started + 3);
|
||||
@@ -32,9 +36,10 @@ describe('Tick', () => {
|
||||
});
|
||||
|
||||
it('stops counting while the window is hidden', async () => {
|
||||
const {Tick, Window} = await loadTick();
|
||||
const {debug, Tick, Window} = await loadTick();
|
||||
const dispose = autorun(() => Tick.nowSecond);
|
||||
Window.setVisible(false);
|
||||
expect(debug).toHaveBeenCalledExactlyOnceWith('Window visibility changed: false');
|
||||
const stopped = Tick.nowSecond;
|
||||
vi.advanceTimersByTime(5000);
|
||||
expect(Tick.nowSecond).toBe(stopped);
|
||||
@@ -42,24 +47,28 @@ describe('Tick', () => {
|
||||
});
|
||||
|
||||
it('resynchronises to wall clock as soon as the window becomes visible again', async () => {
|
||||
const {Tick, Window} = await loadTick();
|
||||
const {debug, Tick, Window} = await loadTick();
|
||||
const dispose = autorun(() => Tick.nowSecond);
|
||||
Window.setVisible(false);
|
||||
const stopped = Tick.nowSecond;
|
||||
vi.advanceTimersByTime(60_000);
|
||||
expect(Tick.nowSecond).toBe(stopped);
|
||||
Window.setVisible(true);
|
||||
expect(debug).toHaveBeenNthCalledWith(1, 'Window visibility changed: false');
|
||||
expect(debug).toHaveBeenNthCalledWith(2, 'Window visibility changed: true');
|
||||
expect(debug).toHaveBeenCalledTimes(2);
|
||||
expect(Tick.nowSecond).toBe(stopped + 60);
|
||||
dispose();
|
||||
});
|
||||
|
||||
it('does not run an interval while nothing observes the clock', async () => {
|
||||
const {Tick} = await loadTick();
|
||||
const {debug, Tick} = await loadTick();
|
||||
const idle = Tick.nowSecond;
|
||||
vi.advanceTimersByTime(5000);
|
||||
expect(Tick.nowSecond).toBe(idle);
|
||||
const dispose = autorun(() => Tick.nowSecond);
|
||||
expect(Tick.nowSecond).toBe(idle + 5);
|
||||
expect(debug).not.toHaveBeenCalled();
|
||||
dispose();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user