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/relay/pure-relay/extensions/ViewDataOnly.stories.ts
import { schema } from "../../../testing-utils/schema.mjs";
import { graphql } from "react-relay";
import {
  getNovaDecorator
} from "@nova/react-test-utils/relay";
import { MockPayloadGenerator } from "relay-test-utils";
import { fn, within, expect, waitFor } from "@storybook/test";
import { ViewDataOnly } from "./ViewDataOnly.mjs";
var mockOnError = fn();
var originalConsoleWarn = console.warn;
var consoleWarnMock = fn((...args) => {
  originalConsoleWarn(...args);
});
console.warn = consoleWarnMock;
var novaDecorator = getNovaDecorator(schema, {
  generateFunction: (operation, mockResolvers) => {
    const result = MockPayloadGenerator.generate(
      operation,
      mockResolvers != null ? mockResolvers : null,
      {
        mockClientData: true
      }
    );
    return result;
  }
});
var meta = {
  component: ViewDataOnly,
  decorators: [novaDecorator],
  parameters: {
    novaEnvironment: {
      query: 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;
var ViewDataOnlyStory = {
  parameters: {
    errorBoundary: {
      onError: mockOnError
    }
  },
  play: (context) => __async(void 0, null, function* () {
    const canvas = within(context.canvasElement);
    yield canvas.findByText("Error in story!");
    yield waitFor(() => {
      expect(mockOnError).toHaveBeenCalledTimes(1);
    });
    const call = mockOnError.mock.calls[0];
    expect(call[0].message).toBe(
      "Cannot read properties of null (reading 'viewDataField')"
    );
    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."
    );
  })
};
var ViewDataOnlyWithServerFieldSelected = {
  parameters: {
    novaEnvironment: {
      query: 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 = within(context.canvasElement);
    yield canvas.findByText("This is a view data field");
  })
};
export {
  ViewDataOnlyStory,
  ViewDataOnlyWithServerFieldSelected,
  ViewDataOnly_stories_default as default
};
