-
Notifications
You must be signed in to change notification settings - Fork 0
feat(score): name Add a score when the list or viewer is empty #1019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
seonghobae
wants to merge
7
commits into
develop
Choose a base branch
from
feat/score-empty-add-next-action
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d315fbc
feat(score): name Add a score when the list or viewer is empty
seonghobae 3b96630
test(score): reject unavailable empty-state action
seonghobae 64c89a8
fix(score): route empty state through project authority
seonghobae 8283350
Merge remote-tracking branch 'origin/develop' into HEAD
seonghobae 278ba34
Merge remote-tracking branch 'origin/develop' into HEAD
seonghobae f078fbf
test(score): reproduce stale viewer across project changes
seonghobae 3a86b15
fix(score): scope viewer state to active project
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
apps/desktop/src/features/score/ScoreView.project-context.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { render, screen } from "@testing-library/react"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import type { RehearsalSong } from "@bandscope/shared-types"; | ||
| import { ScoreView } from "./ScoreView"; | ||
|
|
||
| vi.mock("@tauri-apps/api/core", () => ({ | ||
| invoke: vi.fn() | ||
| })); | ||
|
|
||
| vi.mock("./ScoreViewer", () => ({ | ||
| ScoreViewer: () => <div data-testid="score-viewer">score viewer</div> | ||
| })); | ||
|
|
||
| vi.mock("../../i18n", () => ({ | ||
| createTranslator: () => (key: string) => | ||
| ({ | ||
| scoreViewTitle: "Score", | ||
| scoreViewSubtitle: "Attach validated PDF scores to the current song.", | ||
| scoreListTitle: "Attached scores", | ||
| scoreListEmpty: "Add a score to read it during rehearsal.", | ||
| scoreAttach: "Add score", | ||
| scoreRequiresProject: | ||
| "Scores attach to the active analysis project. Analyze local audio or a YouTube import first." | ||
| })[key] ?? key, | ||
| detectPreferredLocale: () => "en" | ||
| })); | ||
|
|
||
| function makeSong(): RehearsalSong { | ||
| return { | ||
| id: "song-1", | ||
| title: "Late Night Set", | ||
| sections: [], | ||
| exportSummary: { format: "cue-sheet", headline: "", focusSections: [] } | ||
| } as RehearsalSong; | ||
| } | ||
|
|
||
| describe("ScoreView project authority", () => { | ||
| it("names analyze-first instead of unavailable score actions without a project", () => { | ||
| render(<ScoreView song={makeSong()} projectId={null} onSongUpdate={vi.fn()} />); | ||
|
|
||
| expect(screen.getByRole("status")).toHaveTextContent( | ||
| "Analyze local audio or a YouTube import first." | ||
| ); | ||
| expect(screen.queryByText("Add a score to read it during rehearsal.")).not.toBeInTheDocument(); | ||
| expect(screen.queryByTestId("score-viewer")).not.toBeInTheDocument(); | ||
| expect(screen.getByRole("button", { name: "Add score" })).toBeDisabled(); | ||
| }); | ||
| }); |
122 changes: 122 additions & 0 deletions
122
apps/desktop/src/features/score/ScoreView.project-scope.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| import { act, fireEvent, render, screen, waitFor } from "@testing-library/react"; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import type { RehearsalSong } from "@bandscope/shared-types"; | ||
| import { invoke } from "@tauri-apps/api/core"; | ||
| import { ScoreView } from "./ScoreView"; | ||
|
|
||
| vi.mock("@tauri-apps/api/core", () => ({ | ||
| invoke: vi.fn() | ||
| })); | ||
|
|
||
| vi.mock("./ScoreViewer", () => ({ | ||
| ScoreViewer: ({ data, fileName }: { data: Uint8Array | null; fileName?: string }) => ( | ||
| <div data-testid="score-viewer"> | ||
| {data ? `bytes:${data.length}` : "no-data"} | ||
| {fileName ? `:${fileName}` : ""} | ||
| </div> | ||
| ) | ||
| })); | ||
|
|
||
| vi.mock("../../i18n", () => ({ | ||
| createTranslator: () => (key: string) => | ||
| ({ | ||
| scoreViewTitle: "Score", | ||
| scoreViewSubtitle: "Attach validated PDF scores to the current song.", | ||
| scoreListTitle: "Attached scores", | ||
| scoreListEmpty: "Add a score to read it during rehearsal.", | ||
| scoreAttach: "Add score", | ||
| scoreAttaching: "Attaching...", | ||
| scoreRemove: "Remove", | ||
| scoreRemoveConfirm: "Remove {fileName} from this song?", | ||
| scoreOpen: "Open score", | ||
| scoreOpening: "Opening score PDF...", | ||
| scoreAttachFailed: "Could not attach the score PDF.", | ||
| scoreReadFailed: "Could not open the score PDF.", | ||
| scoreRemoveFailed: "Could not remove the score PDF.", | ||
| scoreRequiresProject: "Scores attach to the active analysis project." | ||
| })[key] ?? key, | ||
| detectPreferredLocale: () => "en" | ||
| })); | ||
|
|
||
| type TauriWindow = Window & { | ||
| __TAURI_INTERNALS__?: unknown; | ||
| __TAURI_INVOKE__?: (command: string, args?: Record<string, unknown>) => Promise<unknown>; | ||
| }; | ||
|
|
||
| const tauriWindow = window as TauriWindow; | ||
| const mockInvoke = vi.mocked(invoke); | ||
| const SCORE_ID = "3f2c8f0e-1a2b-4c3d-8e9f-001122334455"; | ||
|
|
||
| function makeSong(): RehearsalSong { | ||
| return { | ||
| id: "song-1", | ||
| title: "Late Night Set", | ||
| sections: [], | ||
| exportSummary: { format: "cue-sheet", headline: "", focusSections: [] }, | ||
| scoreAttachments: [{ id: SCORE_ID, fileName: "opener.pdf" }] | ||
| } as RehearsalSong; | ||
| } | ||
|
|
||
| describe("ScoreView project-scoped viewer state", () => { | ||
| beforeEach(() => { | ||
| mockInvoke.mockReset(); | ||
| tauriWindow.__TAURI_INTERNALS__ = { invoke: () => Promise.resolve(null) }; | ||
| delete tauriWindow.__TAURI_INVOKE__; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| delete tauriWindow.__TAURI_INTERNALS__; | ||
| delete tauriWindow.__TAURI_INVOKE__; | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it("does not reuse opened PDF bytes after the active project changes", async () => { | ||
| mockInvoke.mockResolvedValueOnce([1, 2, 3]); | ||
| const song = makeSong(); | ||
| const onSongUpdate = vi.fn(); | ||
| const { rerender } = render( | ||
| <ScoreView song={song} projectId="project-a" onSongUpdate={onSongUpdate} /> | ||
| ); | ||
|
|
||
| fireEvent.click(screen.getByRole("button", { name: "Open score: opener.pdf" })); | ||
| await waitFor(() => { | ||
| expect(screen.getByTestId("score-viewer")).toHaveTextContent("bytes:3:opener.pdf"); | ||
| }); | ||
|
|
||
| rerender(<ScoreView song={song} projectId={null} onSongUpdate={onSongUpdate} />); | ||
| expect(screen.queryByTestId("score-viewer")).not.toBeInTheDocument(); | ||
|
|
||
| rerender(<ScoreView song={song} projectId="project-b" onSongUpdate={onSongUpdate} />); | ||
| await waitFor(() => { | ||
| expect(screen.getByTestId("score-viewer")).toHaveTextContent("no-data"); | ||
| }); | ||
| expect(mockInvoke).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it("ignores a previous project's read completion after project authority is removed", async () => { | ||
| let resolveRead!: (value: unknown) => void; | ||
| mockInvoke.mockImplementationOnce( | ||
| () => new Promise((resolve) => { | ||
| resolveRead = resolve; | ||
| }) | ||
| ); | ||
| const song = makeSong(); | ||
| const onSongUpdate = vi.fn(); | ||
| const { rerender } = render( | ||
| <ScoreView song={song} projectId="project-a" onSongUpdate={onSongUpdate} /> | ||
| ); | ||
|
|
||
| fireEvent.click(screen.getByRole("button", { name: "Open score: opener.pdf" })); | ||
| expect(await screen.findByText("Opening score PDF...")).toBeInTheDocument(); | ||
|
|
||
| rerender(<ScoreView song={song} projectId={null} onSongUpdate={onSongUpdate} />); | ||
| await act(async () => { | ||
| resolveRead([9, 9]); | ||
| }); | ||
| rerender(<ScoreView song={song} projectId="project-b" onSongUpdate={onSongUpdate} />); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByTestId("score-viewer")).toHaveTextContent("no-data"); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.