|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { audioFxSummary } from "./audioFxSummary"; |
| 3 | +import type { DomEditSelection } from "./domEditingTypes"; |
| 4 | + |
| 5 | +const el = (dataAttributes: Record<string, string>): DomEditSelection => |
| 6 | + ({ dataAttributes }) as unknown as DomEditSelection; |
| 7 | + |
| 8 | +const chain = (nodes: unknown[]) => JSON.stringify({ version: 1, nodes }); |
| 9 | + |
| 10 | +describe("audioFxSummary", () => { |
| 11 | + it("counts a carve as one module, not as the filters behind it", () => { |
| 12 | + // Six bands and a level stage reading "7 effects" is the misreading the |
| 13 | + // grouping exists to prevent. |
| 14 | + const summary = audioFxSummary( |
| 15 | + el({ |
| 16 | + "fx-chain": chain([ |
| 17 | + { type: "peaking", id: "n1", fromCarve: true, params: { frequency: 400 } }, |
| 18 | + { type: "peaking", id: "n2", fromCarve: true, params: { frequency: 1600 } }, |
| 19 | + { type: "gain", id: "n3", fromCarve: true, params: { gain: -6 } }, |
| 20 | + ]), |
| 21 | + "fx-carve": JSON.stringify({ source: "vo", strength: 0.25 }), |
| 22 | + }), |
| 23 | + ); |
| 24 | + expect(summary).toBe("carve"); |
| 25 | + }); |
| 26 | + |
| 27 | + it("counts hand-built effects alongside the module", () => { |
| 28 | + expect( |
| 29 | + audioFxSummary( |
| 30 | + el({ |
| 31 | + "fx-chain": chain([ |
| 32 | + { type: "peaking", id: "n1", fromCarve: true, params: { frequency: 400 } }, |
| 33 | + { type: "lowpass", id: "n2", params: { frequency: 8000 } }, |
| 34 | + { type: "delay", id: "n3", params: { time: 200 } }, |
| 35 | + ]), |
| 36 | + }), |
| 37 | + ), |
| 38 | + ).toBe("2 effects + carve"); |
| 39 | + }); |
| 40 | + |
| 41 | + it("says how many when there is no carve", () => { |
| 42 | + expect(audioFxSummary(el({ "fx-chain": chain([{ type: "lowpass", id: "n1" }]) }))).toBe( |
| 43 | + "1 effect", |
| 44 | + ); |
| 45 | + }); |
| 46 | + |
| 47 | + it("names a carve that is on but has not compiled to filters yet", () => { |
| 48 | + // Switching it on with no voice chosen leaves the control in this section with |
| 49 | + // nothing behind it; the summary should still say the section holds one. |
| 50 | + expect(audioFxSummary(el({ "fx-carve": JSON.stringify({ source: "", strength: 0.25 }) }))).toBe( |
| 51 | + "carve", |
| 52 | + ); |
| 53 | + }); |
| 54 | + |
| 55 | + it("ignores bypassed effects, as it always did", () => { |
| 56 | + expect( |
| 57 | + audioFxSummary( |
| 58 | + el({ |
| 59 | + "fx-chain": chain([ |
| 60 | + { type: "lowpass", id: "n1", enabled: false }, |
| 61 | + { type: "delay", id: "n2" }, |
| 62 | + ]), |
| 63 | + }), |
| 64 | + ), |
| 65 | + ).toBe("1 effect"); |
| 66 | + }); |
| 67 | + |
| 68 | + it("says none for a track with neither", () => { |
| 69 | + expect(audioFxSummary(el({}))).toBe("none"); |
| 70 | + }); |
| 71 | + |
| 72 | + it("says so when the chain cannot be read", () => { |
| 73 | + expect(audioFxSummary(el({ "fx-chain": "{not json" }))).toBe("unreadable"); |
| 74 | + }); |
| 75 | +}); |
0 commit comments