/**
 * Native-path reveal rule (DR-182).
 *
 * TRACES: UR-003, UR-004 | DR-182 | UT-184
 */

import { describe, it, expect } from "vitest";
import { nativeSignalRevealsVideo } from "./mediaReady";

describe("nativeSignalRevealsVideo", () => {
  it("reveals on the backend's playing state", () => {
    expect(nativeSignalRevealsVideo({ kind: "state", state: "playing" })).toBe(true);
  });

  it.each(["buffering", "paused", "stopped", "ended", "error", "idle", ""])(
    "leaves the poster up on state %s",
    (state) => {
      expect(nativeSignalRevealsVideo({ kind: "state", state })).toBe(false);
    }
  );

  it("reveals on a position tick that carries a duration", () => {
    expect(
      nativeSignalRevealsVideo({ kind: "position", position: 0, duration: 1440 })
    ).toBe(true);
  });

  it("reveals on a position tick that has advanced, even with no duration", () => {
    // Live streams report no duration; an advancing position is still proof
    // that the surface has content.
    expect(
      nativeSignalRevealsVideo({ kind: "position", position: 3.2, duration: 0 })
    ).toBe(true);
  });

  it("leaves the poster up on an empty position tick", () => {
    // A tick before anything is loaded proves nothing, and revealing here would
    // show a transparent hole through the app.
    expect(
      nativeSignalRevealsVideo({ kind: "position", position: 0, duration: 0 })
    ).toBe(false);
  });

  it("does not treat a negative position as progress", () => {
    expect(
      nativeSignalRevealsVideo({ kind: "position", position: -1, duration: 0 })
    ).toBe(false);
  });
});
