"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), 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 ViewDataOnly_stories_exports = {};
__export(ViewDataOnly_stories_exports, {
  ViewDataOnlyStory: () => ViewDataOnlyStory,
  ViewDataOnlyWithServerFieldSelected: () => ViewDataOnlyWithServerFieldSelected,
  default: () => ViewDataOnly_stories_default
});
module.exports = __toCommonJS(ViewDataOnly_stories_exports);
var import_schema = require("../../../testing-utils/schema");
var import_react_relay = require("react-relay");
var import_relay = require("@nova/react-test-utils/relay");
var import_relay_test_utils = require("relay-test-utils");
var import_test = require("@storybook/test");
var import_ViewDataOnly = require("./ViewDataOnly");
const mockOnError = (0, import_test.fn)();
const originalConsoleWarn = console.warn;
const consoleWarnMock = (0, import_test.fn)((...args) => {
  originalConsoleWarn(...args);
});
console.warn = consoleWarnMock;
const novaDecorator = (0, import_relay.getNovaDecorator)(import_schema.schema, {
  generateFunction: (operation, mockResolvers) => {
    const result = import_relay_test_utils.MockPayloadGenerator.generate(
      operation,
      mockResolvers != null ? mockResolvers : null,
      {
        mockClientData: true
      }
    );
    return result;
  }
});
const meta = {
  component: import_ViewDataOnly.ViewDataOnly,
  decorators: [novaDecorator],
  parameters: {
    novaEnvironment: {
      query: import_react_relay.graphql`
        query ViewDataOnlyStoryRelayQuery @relay_test_operation {
          viewData {
            ...ViewDataOnly_viewDataFragment
          }
        }
      `,
      referenceEntries: {
        viewData: (data) => data == null ? void 0 : data.viewData
      },
      resolvers: {
        ViewData: () => ({
          viewDataField: "This is a view data field"
        })
      }
    }
  }
};
var ViewDataOnly_stories_default = meta;
const ViewDataOnlyStory = {
  parameters: {
    errorBoundary: {
      onError: mockOnError
    }
  },
  play: (context) => __async(void 0, null, function* () {
    const canvas = (0, import_test.within)(context.canvasElement);
    yield canvas.findByText("Error in story!");
    yield (0, import_test.waitFor)(() => {
      (0, import_test.expect)(mockOnError).toHaveBeenCalledTimes(1);
    });
    const call = mockOnError.mock.calls[0];
    (0, import_test.expect)(call[0].message).toBe(
      "Cannot read properties of null (reading 'viewDataField')"
    );
    (0, import_test.expect)(consoleWarnMock).toHaveBeenCalledWith(
      "The ViewDataOnlyStoryRelayQuery query is a client-only query, which means mock resolvers won't get called. Please select at least one server field in the query to ensure that mock resolvers are called."
    );
  })
};
const ViewDataOnlyWithServerFieldSelected = {
  parameters: {
    novaEnvironment: {
      query: import_react_relay.graphql`
        query ViewDataOnlyWithServerFieldSelectedStoryRelayQuery
        @relay_test_operation {
          viewData {
            ...ViewDataOnly_viewDataFragment
          }
          serverField
        }
      `,
      referenceEntries: {
        viewData: (data) => data == null ? void 0 : data.viewData
      }
    }
  },
  play: (context) => __async(void 0, null, function* () {
    const canvas = (0, import_test.within)(context.canvasElement);
    yield canvas.findByText("This is a view data field");
  })
};
