"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __async = (__this, __arguments, generator) => {
  return new Promise((resolve, reject) => {
    var fulfilled = (value) => {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    };
    var rejected = (value) => {
      try {
        step(generator.throw(value));
      } catch (e) {
        reject(e);
      }
    };
    var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
    step((generator = generator.apply(__this, __arguments)).next());
  });
};
var import_vitest = require("vitest");
var import_react = require("@storybook/react");
var stories = __toESM(require("./Feedback.stories"), 1);
var import_vitest_browser_react = require("vitest-browser-react");
var React = __toESM(require("react"), 1);
var import_context = require("@vitest/browser/context");
const { Primary } = (0, import_react.composeStories)(stories);
const bubbleMock = import_vitest.vi.fn();
const generateEventMock = import_vitest.vi.fn();
import_vitest.vi.mock("@nova/react", () => __async(void 0, null, function* () {
  const actual = yield import_vitest.vi.importActual("@nova/react");
  return __spreadProps(__spreadValues({}, actual), {
    useNovaEventing: () => ({
      bubble: bubbleMock,
      generateEvent: generateEventMock
    })
  });
}));
(0, import_vitest.beforeEach)(() => {
  import_vitest.vi.clearAllMocks();
});
(0, import_vitest.describe)("Feedback", () => {
  (0, import_vitest.it)("rerenders without unmounting", () => __async(void 0, null, function* () {
    const { rerender } = (0, import_vitest_browser_react.render)(/* @__PURE__ */ React.createElement(Primary, null));
    let likeButton = import_context.page.getByRole("button", { name: "Like" });
    yield import_vitest.expect.element(likeButton).toBeInTheDocument();
    let telemetryEvents = generateEventMock.mock.calls.filter(
      ([{ event }]) => event.type === "feedbackTelemetry"
    );
    (0, import_vitest.expect)(telemetryEvents).toHaveLength(1);
    rerender(/* @__PURE__ */ React.createElement(Primary, null));
    likeButton = import_context.page.getByRole("button", { name: "Like" });
    yield import_vitest.expect.element(likeButton).toBeInTheDocument();
    telemetryEvents = generateEventMock.mock.calls.filter(
      ([{ event }]) => event.type === "feedbackTelemetry"
    );
    (0, import_vitest.expect)(telemetryEvents).toHaveLength(1);
  }));
});
