fix(dashboard): improve performance with OnPush change detection (#440)
* fix(dashboard): improve performance with OnPush change detection * fix(dashboard): refactor book card component for improved readability and performance * fix(tests): mock matchMedia for improved test compatibility * fix(tests): matchMedia mock for better CI compatibility and support * fix(dashboard): add clearAll method to BookBrowserScrollService and update tests * fix(dashboard): improve performance with content visibility and refactor styles * fix(dashboard): improve scroll performance with estimated total height and refactor layout * fix(tests): add mock for getCurrentUser in userService for improved test coverage * fix(dashboard): implement infinite scroll for book loading and scroll restoration * fix(tests): fix lint error * fix(tests): mock ResizeObserver and IntersectionObserver * fix(tests): mock ResizeObserver and IntersectionObserver (again) * fix(dashboard): improve accessibility and performance by updating aria attributes and optimizing animations * fix(dashboard): improve submenu accessibility and optimize virtual scroller performance * fix(dashboard): clean up imports and improve component structure * fix(dashboard): correct mobile check in author browser component * fix(dashboard): add OnDestroy lifecycle hook to BookBrowserComponent
This commit is contained in:
+29
-13
@@ -1,6 +1,5 @@
|
||||
import '@angular/compiler';
|
||||
import 'zone.js';
|
||||
import 'zone.js/testing';
|
||||
import {vi} from 'vitest';
|
||||
import '@testing-library/jest-dom/vitest';
|
||||
import 'vitest-canvas-mock';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
@@ -30,17 +29,34 @@ class MockIntersectionObserver {
|
||||
}
|
||||
}
|
||||
|
||||
if (!globalThis.matchMedia) {
|
||||
globalThis.matchMedia = (query: string): MediaQueryList => ({
|
||||
matches: false,
|
||||
media: query,
|
||||
onchange: null,
|
||||
addEventListener: () => undefined,
|
||||
removeEventListener: () => undefined,
|
||||
addListener: () => undefined,
|
||||
removeListener: () => undefined,
|
||||
dispatchEvent: () => false,
|
||||
});
|
||||
// Standard mock for matchMedia to support PrimeNG and other UI libraries in JSDOM
|
||||
const matchMediaMock = (query: string): MediaQueryList => ({
|
||||
matches: false,
|
||||
media: query,
|
||||
onchange: null,
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
addListener: vi.fn(), // Deprecated but still used by some libraries
|
||||
removeListener: vi.fn(), // Deprecated
|
||||
dispatchEvent: vi.fn(),
|
||||
});
|
||||
|
||||
Object.defineProperty(globalThis, 'matchMedia', {
|
||||
writable: true,
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
value: matchMediaMock,
|
||||
});
|
||||
|
||||
Object.defineProperty(window, 'matchMedia', {
|
||||
writable: true,
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
value: matchMediaMock,
|
||||
});
|
||||
|
||||
if (process.env['GITHUB_ACTIONS']) {
|
||||
console.log('Test setup: Applied robust window.matchMedia mock');
|
||||
}
|
||||
|
||||
if (!globalThis.ResizeObserver) {
|
||||
|
||||
Reference in New Issue
Block a user