var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
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 __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());
  });
};

// src/apollo/Feedback/Feedback.stories.tsx
import { graphql } from "@nova/react";
import {
  EventingInterceptor,
  getNovaDecorator,
  getNovaEnvironmentForStory
} from "@nova/react-test-utils/apollo";
import { expect, fn, userEvent, waitFor, within } from "@storybook/test";
import { FeedbackComponent } from "./Feedback.mjs";
import * as React from "react";
import { cacheConfig } from "../../testing-utils/apolloCacheConfig.mjs";
import { schema } from "../../testing-utils/schema.mjs";
import { defaultNodeResolver } from "../../testing-utils/resolvers.mjs";
var meta = {
  component: FeedbackComponent,
  decorators: [getNovaDecorator(schema, { cache: cacheConfig })],
  parameters: {
    novaEnvironment: {
      query: graphql`
        query FeedbackStoryQuery($id: ID!) @relay_test_operation {
          feedback(id: $id) {
            ...Feedback_feedbackFragment
          }
        }
      `,
      variables: { id: "42" },
      referenceEntries: {
        feedback: (data) => data == null ? void 0 : data.feedback
      },
      resolvers: {
        Node: defaultNodeResolver
      }
    }
  }
};
var Feedback_stories_default = meta;
var AutoGeneratedDataOnly = {};
var Primary = {
  parameters: {
    novaEnvironment: {
      resolvers: {
        Feedback: () => sampleFeedback
      }
    }
  }
};
var Liked = {
  parameters: {
    novaEnvironment: {
      resolvers: {
        Feedback: () => __spreadProps(__spreadValues({}, sampleFeedback), {
          doesViewerLike: true
        })
      }
    }
  }
};
var Like = {
  parameters: {
    novaEnvironment: {
      resolvers: {
        Feedback: () => sampleFeedback,
        FeedbackLikeMutationResult: () => ({
          feedback: __spreadProps(__spreadValues({}, sampleFeedback), {
            doesViewerLike: true
          })
        })
      }
    }
  },
  play: (context) => __async(void 0, null, function* () {
    const container = within(context.canvasElement);
    const likeButton = yield container.findByRole("button", { name: "Like" });
    yield userEvent.click(likeButton);
    yield container.findByRole("button", { name: "Unlike" });
  })
};
var mockOnError = fn();
var ArtificialFailureToShowcaseDecoratorBehaviorInCaseOfADevCausedError = {
  parameters: {
    novaEnvironment: {
      enableQueuedMockResolvers: false
    },
    errorBoundary: {
      onError: mockOnError
    }
  },
  play: (context) => __async(void 0, null, function* () {
    const {
      graphql: { mock }
    } = getNovaEnvironmentForStory(context);
    yield waitFor(() => __async(void 0, null, function* () {
      const operation = mock.getMostRecentOperation();
      yield expect(operation).toBeDefined();
    }));
    yield mock.rejectMostRecentOperation(new Error("Query failed"));
    yield waitFor(() => {
      expect(mockOnError).toHaveBeenCalledTimes(1);
    });
    const call = mockOnError.mock.calls[0];
    expect(call[0].message).toBe("Query failed");
  })
};
var FeedbackWithDeleteDialog = (props) => {
  const [open, setOpen] = React.useState(false);
  const [text, setText] = React.useState("");
  return /* @__PURE__ */ React.createElement(
    EventingInterceptor,
    {
      eventMap: {
        onDeleteFeedback: (eventWrapper) => {
          setOpen(true);
          setText(eventWrapper.event.data().feedbackText);
          return Promise.resolve(void 0);
        },
        feedbackTelemetry: (eventWrapper) => {
          console.log("Telemetry event", eventWrapper.event.data());
          return Promise.resolve(eventWrapper);
        }
      }
    },
    /* @__PURE__ */ React.createElement(FeedbackComponent, __spreadValues({}, props)),
    /* @__PURE__ */ React.createElement("dialog", { open }, /* @__PURE__ */ React.createElement("button", { onClick: () => setOpen(false) }, "Cancel"), 'Are you sure you want to delete feedback "', text, '"')
  );
};
var WithDeleteDialog = __spreadProps(__spreadValues({}, Primary), {
  render: (args) => /* @__PURE__ */ React.createElement(FeedbackWithDeleteDialog, __spreadValues({}, args)),
  play: (context) => __async(void 0, null, function* () {
    const container = within(context.canvasElement);
    const deleteButton = yield container.findByRole("button", {
      name: "Delete feedback"
    });
    yield userEvent.click(deleteButton);
    const dialog = yield container.findByRole("dialog");
    yield expect(dialog).toBeInTheDocument();
  })
});
var sampleFeedback = {
  id: "feedback:42",
  message: {
    text: "Feedback title"
  },
  doesViewerLike: false
};
export {
  ArtificialFailureToShowcaseDecoratorBehaviorInCaseOfADevCausedError,
  AutoGeneratedDataOnly,
  Like,
  Liked,
  Primary,
  WithDeleteDialog,
  Feedback_stories_default as default
};
