Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions frontend/src/utils/avatarUtils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getAvatarColor } from './avatarUtils';

describe('getAvatarColor', () => {
test('returns specific color for known id', () => {
expect(getAvatarColor('red')).toBe('#e53935');
});

test('falls back to default color for unknown id', () => {
expect(getAvatarColor('unknown')).toBe('primary.main');
});
});
38 changes: 38 additions & 0 deletions frontend/src/utils/refreshUtils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { setRefreshFlag, checkAndRefresh } from './refreshUtils';

describe('refreshUtils', () => {
beforeEach(() => {
jest.useFakeTimers();
sessionStorage.clear();
Object.defineProperty(window, 'location', {
configurable: true,
value: { ...window.location, reload: jest.fn() },
});
});

afterEach(() => {
jest.useRealTimers();
// Reset the location object
delete window.location;
window.location = new URL('http://localhost');
});

test('setRefreshFlag stores value in sessionStorage', () => {
setRefreshFlag('flag', 2);
expect(sessionStorage.getItem('flag')).toBe('2');
});

test('checkAndRefresh triggers reload and clears flag when count is 1', () => {
setRefreshFlag('flag', 1);
checkAndRefresh('flag');
jest.runAllTimers();
expect(window.location.reload).toHaveBeenCalled();
expect(sessionStorage.getItem('flag')).toBeNull();
});

test('checkAndRefresh decrements count when greater than 1', () => {
setRefreshFlag('flag', 3);
checkAndRefresh('flag');
expect(sessionStorage.getItem('flag')).toBe('2');
});
});
17 changes: 17 additions & 0 deletions frontend/src/utils/styleUtils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { forceReflow, applyBodyClass } from './styleUtils';

describe('styleUtils', () => {
test('forceReflow reads offsetHeight', () => {
const el = document.createElement('div');
const spy = jest.spyOn(el, 'offsetHeight', 'get').mockReturnValue(0);
forceReflow(el);
expect(spy).toHaveBeenCalled();
});

test('applyBodyClass adds and removes class on body', () => {
const cleanup = applyBodyClass('test-class');
expect(document.body.classList.contains('test-class')).toBe(true);
cleanup();
expect(document.body.classList.contains('test-class')).toBe(false);
});
});