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/FeedbackContainer.stories.tsx
import {
  userEvent,
  within,
  waitFor,
  expect,
  fn,
  screen
} from "@storybook/test";
import {
  getNovaDecorator,
  MockPayloadGenerator,
  getNovaEnvironmentForStory,
  EventingInterceptor
} from "@nova/react-test-utils/apollo";
import { FeedbackContainer } from "./FeedbackContainer.mjs";
import { cacheConfig } from "../../testing-utils/apolloCacheConfig.mjs";
import * as React from "react";
import { schema } from "../../testing-utils/schema.mjs";
import { defaultNodeResolver } from "../../testing-utils/resolvers.mjs";
var telemetryEventMock = fn();
var meta = {
  component: FeedbackContainer,
  decorators: [getNovaDecorator(schema, { cache: cacheConfig })],
  parameters: {
    novaEnvironment: {
      resolvers: {
        Feedback: () => ({
          id: "feedback:42"
        }),
        Node: defaultNodeResolver
      }
    }
  },
  render: () => /* @__PURE__ */ React.createElement(
    EventingInterceptor,
    {
      eventMap: {
        feedbackTelemetry: telemetryEventMock
      }
    },
    /* @__PURE__ */ React.createElement(FeedbackContainer, null)
  )
};
var FeedbackContainer_stories_default = meta;
var AutoGeneratedDataOnly = {
  play: (_0) => __async(void 0, [_0], function* ({ canvasElement }) {
    const canvas = within(canvasElement);
    const button = yield canvas.findByRole("button", { name: "Like" });
    yield expect(button).toBeInTheDocument();
  })
};
var Primary = {
  parameters: {
    novaEnvironment: {
      resolvers: {
        Feedback: () => sampleFeedback
      }
    }
  },
  play: (_0) => __async(void 0, [_0], function* ({ canvasElement }) {
    const canvas = within(canvasElement);
    const button = yield canvas.findByRole("button", { name: "Like" });
    yield expect(button).toBeInTheDocument();
  })
};
var Liked = {
  parameters: {
    novaEnvironment: {
      resolvers: {
        Feedback: () => __spreadProps(__spreadValues({}, sampleFeedback), {
          doesViewerLike: true
        })
      }
    }
  },
  play: (_0) => __async(void 0, [_0], function* ({ canvasElement }) {
    const canvas = within(canvasElement);
    const button = yield canvas.findByRole("button", { name: "Unlike" });
    yield expect(button).toBeInTheDocument();
  })
};
var Like = {
  parameters: {
    novaEnvironment: {
      resolvers: {
        Feedback: () => sampleFeedback,
        FeedbackLikeMutationResult: () => ({
          feedback: __spreadProps(__spreadValues({}, sampleFeedback), {
            doesViewerLike: true
          })
        })
      }
    }
  },
  play: (_0) => __async(void 0, [_0], function* ({ canvasElement }) {
    const container = within(canvasElement);
    const likeButton = yield container.findByRole("button", { name: "Like" });
    userEvent.click(likeButton);
    yield container.findByRole("button", { name: "Unlike" });
    let feedbackOperationEvents = [];
    yield waitFor(() => {
      feedbackOperationEvents = telemetryEventMock.mock.calls.filter(
        ([{ event }]) => {
          const operation = event.data().operation;
          return operation === "FeedbackLiked" || operation === "FeedbackUnliked";
        }
      );
      expect(feedbackOperationEvents).toHaveLength(1);
    });
    const call = feedbackOperationEvents[0];
    expect(call[0].event.data().operation).toBe("FeedbackLiked");
  })
};
var LikeFailure = {
  parameters: {
    novaEnvironment: {
      enableQueuedMockResolvers: false
    }
  },
  play: (context) => __async(void 0, null, function* () {
    const {
      graphql: { mock }
    } = getNovaEnvironmentForStory(context);
    const container = within(context.canvasElement);
    yield waitFor(() => __async(void 0, null, function* () {
      const operation = mock.getMostRecentOperation();
      yield expect(operation).toBeDefined();
    }));
    yield mock.resolveMostRecentOperation(
      (operation) => MockPayloadGenerator.generate(operation, {
        Feedback: () => sampleFeedback
      })
    );
    const likeButton = yield container.findByRole("button", { name: "Like" });
    userEvent.click(likeButton);
    yield waitFor(() => __async(void 0, null, function* () {
      const operation = mock.getMostRecentOperation();
      expect(operation).toBeDefined();
    }));
    mock.rejectMostRecentOperation(new Error("Like failed"));
    yield container.findByText("Something went wrong");
  })
};
var QueryFailure = {
  parameters: {
    novaEnvironment: {
      enableQueuedMockResolvers: false
    }
  },
  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 screen.findByText("Error: Query failed");
  })
};
var Loading = {
  parameters: {
    novaEnvironment: {
      enableQueuedMockResolvers: false
    }
  },
  play: (_0) => __async(void 0, [_0], function* ({ canvasElement }) {
    const canvas = within(canvasElement);
    const loadingElement = yield canvas.findByText("Loading...");
    yield expect(loadingElement).toBeInTheDocument();
  })
};
var sampleFeedback = {
  id: "feedback:42",
  message: {
    text: "Feedback title"
  },
  doesViewerLike: false
};
export {
  AutoGeneratedDataOnly,
  Like,
  LikeFailure,
  Liked,
  Loading,
  Primary,
  QueryFailure,
  FeedbackContainer_stories_default as default
};
