Skip to content
Open
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
2 changes: 1 addition & 1 deletion frontend/jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,6 @@ global.fetch = jest.fn().mockImplementation((url: string) => {
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve({}),
json: () => Promise.resolve({ success: true, data: [] }),
});
});
36 changes: 10 additions & 26 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/src/pages/AITagging/AITagging.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const AITagging = () => {
} else if (imagesError) {
dispatch(hideLoader());
} else if (imagesSuccess) {
const images = imagesData?.data as Image[];
const images = (imagesData?.data ?? []) as Image[];
dispatch(setImages(images));
dispatch(hideLoader());
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const Home = () => {

useEffect(() => {
if (!isSearchActive && isSuccess) {
const images = data?.data as Image[];
const images = (data?.data ?? []) as Image[];
dispatch(setImages(images));
}
}, [data, isSuccess, dispatch, isSearchActive]);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Home/MyFav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const MyFav = () => {
// Handle fetching lifecycle
useEffect(() => {
if (!isSearchActive && isSuccess) {
const images = data?.data as Image[];
const images = (data?.data ?? []) as Image[];
dispatch(setImages(images));
}
}, [data, isSuccess, dispatch, isSearchActive]);
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/pages/__tests__/PageSanity.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen } from '@/test-utils';
import { render, screen, act } from '@/test-utils';
import { Home } from '../Home/Home';
import Settings from '../SettingsPage/Settings';

Expand All @@ -15,8 +15,11 @@ describe('Page Sanity Tests', () => {
});

describe('Settings Page', () => {
test('renders settings page sections', () => {
test('renders settings page sections', async () => {
render(<Settings />);
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 0));
});

expect(screen.getByText('Folder Management')).toBeInTheDocument();
expect(screen.getByText('User Preferences')).toBeInTheDocument();
Expand All @@ -26,6 +29,6 @@ describe('Page Sanity Tests', () => {
screen.getByRole('button', { name: /Check for Updates/i }),
).toBeInTheDocument();
expect(screen.getByText('GPU Acceleration')).toBeInTheDocument();
}); // Settings is expected to render synchronously.
});
});
});
19 changes: 11 additions & 8 deletions frontend/src/pages/__tests__/SettingsPage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { render, screen } from '@/test-utils';
import { render, screen, act } from '@/test-utils';
import userEvent from '@testing-library/user-event';
import Settings from '../SettingsPage/Settings';

describe('Settings Page', () => {
// shared setup for all tests
const setupTest = () => {
const setupTest = async () => {
const user = userEvent.setup();
render(<Settings />);
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 0));
});
return { user };
};

describe('Interaction Sanity', () => {
describe('User Preferences Section', () => {
test('YOLO model dropdown opens and shows options', async () => {
const { user } = setupTest();
const { user } = await setupTest();

const dropdownTrigger = screen.getByRole('button', {
name: /nano|small|medium/i,
Expand All @@ -28,7 +31,7 @@ describe('Settings Page', () => {
});

test('GPU Acceleration toggle changes state on click', async () => {
const { user } = setupTest();
const { user } = await setupTest();

const gpuSwitch = screen.getByRole('switch');
expect(gpuSwitch).toHaveAttribute('aria-checked', 'false');
Expand All @@ -49,7 +52,7 @@ describe('Settings Page', () => {
test.each(buttonCases)(
'$label button does not crash when clicked',
async ({ name }) => {
const { user } = setupTest();
const { user } = await setupTest();

const button = screen.getByRole('button', { name });

Expand All @@ -71,7 +74,7 @@ describe('Settings Page', () => {
test.each(yoloSelectionCases)(
'selecting $expectedText updates dropdown display',
async ({ selectOption, expectedText }) => {
const { user } = setupTest();
const { user } = await setupTest();

const dropdownTrigger = screen.getByRole('button', { name: /nano/i });
expect(dropdownTrigger).toHaveTextContent('Nano');
Expand All @@ -88,7 +91,7 @@ describe('Settings Page', () => {
);

test('dropdown can be reopened after selection', async () => {
const { user } = setupTest();
const { user } = await setupTest();

const dropdownTrigger = screen.getByRole('button', { name: /nano/i });
await user.click(dropdownTrigger);
Expand All @@ -102,7 +105,7 @@ describe('Settings Page', () => {

describe('GPU Acceleration Toggle', () => {
test('toggle cycles through ON/OFF states', async () => {
const { user } = setupTest();
const { user } = await setupTest();

const gpuSwitch = screen.getByRole('switch');
expect(gpuSwitch).toHaveAttribute('aria-checked', 'false');
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/pages/__tests__/allPages.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render } from '@testing-library/react';
import { render, act } from '@testing-library/react';
import { AITagging } from '@/pages/AITagging/AITagging';
import Album from '../Album/Album';
import { Home } from '@/pages/Home/Home';
Expand All @@ -23,7 +23,7 @@ const pages = [

describe('Page rendering tests', () => {
pages.forEach(({ path, Component }) => {
test(`renders ${path} without crashing`, () => {
test(`renders ${path} without crashing`, async () => {
render(
<Provider store={store}>
<ThemeProvider>
Expand All @@ -35,6 +35,9 @@ describe('Page rendering tests', () => {
</ThemeProvider>
</Provider>,
);
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 0));
});
});
});
});
Loading