From 1ed1d0ce799fb1042f7741d8a63dce2fb9988bf5 Mon Sep 17 00:00:00 2001 From: Salome Gene Date: Fri, 15 May 2026 11:57:30 -0500 Subject: [PATCH] test(frontend): add unit tests for favorites flow - Add LoveButton.test.jsx with 9 cases (render, disabled states, click, propagation, tooltip) - Add ContextMenus.test.jsx with 8 cases for AlbumContextMenu and ArtistContextMenu - Extend useToggleLove.test.js with error handling and loading state cases - Add useToggleLove.test.md documenting test cases and mocks - Add frontend-test service to docker-compose.dev.yml (profile: test) Co-Authored-By: Claude Sonnet 4.6 --- docker-compose.dev.yml | 10 +++ ui/src/common/ContextMenus.test.jsx | 99 +++++++++++++++++++++++++++ ui/src/common/LoveButton.test.jsx | 100 ++++++++++++++++++++++++++++ ui/src/common/useToggleLove.test.js | 58 +++++++++++++++- ui/src/common/useToggleLove.test.md | 27 ++++++++ 5 files changed, 291 insertions(+), 3 deletions(-) create mode 100644 ui/src/common/ContextMenus.test.jsx create mode 100644 ui/src/common/LoveButton.test.jsx create mode 100644 ui/src/common/useToggleLove.test.md diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 0d9713896..58737ab83 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -35,6 +35,16 @@ services: depends_on: - backend + frontend-test: + image: node:24 + working_dir: /app + volumes: + - ./ui:/app + - node-modules:/app/node_modules + command: sh -c "npm ci && npm test" + profiles: + - test + volumes: go-mod-cache: go-build-cache: diff --git a/ui/src/common/ContextMenus.test.jsx b/ui/src/common/ContextMenus.test.jsx new file mode 100644 index 000000000..787e30805 --- /dev/null +++ b/ui/src/common/ContextMenus.test.jsx @@ -0,0 +1,99 @@ +import React from 'react' +import { render, screen } from '@testing-library/react' +import { describe, it, expect, vi, beforeEach } from 'vitest' +import { AlbumContextMenu, ArtistContextMenu } from './ContextMenus' + +const capturedLoveButtonProps = {} + +vi.mock('./LoveButton', () => ({ + LoveButton: (props) => { + Object.assign(capturedLoveButtonProps, props) + return props.visible ?