"use strict";

var _react = _interopRequireDefault(require("react"));
var _text = _interopRequireDefault(require("../../components/atoms/text/text"));
var _reactNative = require("@testing-library/react-native");
var _themeContext = require("../src/theme-context");
var _box = _interopRequireDefault(require("../../components/atoms/box/box"));
var _button = _interopRequireDefault(require("../../components/molecules/button/button"));
var _useTheme = require("../../hooks/useTheme");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
jest.useFakeTimers();
const ThemeTestComponent = props => {
  const {
    colorMode,
    toggleColorMode,
    switchColorMode
  } = (0, _useTheme.useTheme)();
  return /*#__PURE__*/_react.default.createElement(_box.default, null, /*#__PURE__*/_react.default.createElement(_text.default, null, colorMode), ";", /*#__PURE__*/_react.default.createElement(_button.default, {
    onPress: toggleColorMode
  }, "Toggle mode"), /*#__PURE__*/_react.default.createElement(_button.default, {
    onPress: () => {
      if (props.targetColorMode) switchColorMode(props.targetColorMode);
    }
  }, "Switch mode"));
};
describe("Theme Context", () => {
  it("returns null if fonts haven't loaded", () => {
    const tree = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, {
      haveFontsLoaded: false
    }, /*#__PURE__*/_react.default.createElement(ThemeTestComponent, null))).toJSON();
    expect(tree).toBe(null);
  });
  it("initially loads the light theme", () => {
    const {
      getByText
    } = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(ThemeTestComponent, null)));
    expect(getByText("light")).toBeTruthy();
  });
  it("loads the dark theme when overriden", () => {
    const {
      getByText
    } = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, {
      initialColorMode: "dark"
    }, /*#__PURE__*/_react.default.createElement(ThemeTestComponent, null)));
    expect(getByText("dark")).toBeTruthy();
  });
  it("loads the theme automatically based on the system theme", () => {
    const {
      getByText
    } = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, {
      initialColorMode: "system"
    }, /*#__PURE__*/_react.default.createElement(ThemeTestComponent, null)));
    expect(getByText("light")).toBeTruthy();
  });
  it("toggles the theme (light -> dark) correctly", () => {
    const {
      getByText
    } = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, {
      initialColorMode: "light"
    }, /*#__PURE__*/_react.default.createElement(ThemeTestComponent, null)));
    expect(getByText("light")).toBeTruthy();
    const toggleButton = getByText(/toggle/i);
    _reactNative.fireEvent.press(toggleButton);
    expect(getByText("dark")).toBeTruthy();
  });
  it("toggles the theme (dark -> light) correctly", () => {
    const {
      getByText
    } = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, {
      initialColorMode: "dark"
    }, /*#__PURE__*/_react.default.createElement(ThemeTestComponent, null)));
    expect(getByText("dark")).toBeTruthy();
    const toggleButton = getByText(/toggle/i);
    _reactNative.fireEvent.press(toggleButton);
    expect(getByText("light")).toBeTruthy();
  });
  it("changes the theme from dark -> light correctly using switchColorMode", () => {
    const {
      getByText
    } = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, {
      initialColorMode: "dark"
    }, /*#__PURE__*/_react.default.createElement(ThemeTestComponent, {
      targetColorMode: "light"
    })));
    expect(getByText("dark")).toBeTruthy();
    const switchButton = getByText(/switch/i);
    _reactNative.fireEvent.press(switchButton);
    expect(getByText("light")).toBeTruthy();
  });
  it("changes the theme from light -> dark correctly using switchColorMode", () => {
    const {
      getByText
    } = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_themeContext.ThemeProvider, {
      initialColorMode: "light"
    }, /*#__PURE__*/_react.default.createElement(ThemeTestComponent, {
      targetColorMode: "dark"
    })));
    expect(getByText("light")).toBeTruthy();
    const switchButton = getByText(/switch/i);
    _reactNative.fireEvent.press(switchButton);
    expect(getByText("dark")).toBeTruthy();
  });
});
//# sourceMappingURL=theme-context.spec.js.map