"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importStar(require("react"));
const react_2 = require("@testing-library/react");
const useBaseDatePicker_1 = __importDefault(require("./useBaseDatePicker"));
const index_util_1 = require("./index.util");
const user_event_1 = __importDefault(require("@testing-library/user-event"));
const types_1 = require("../../../../types");
describe('useBaseDatePicker 는 표시년월에 대한 dateList 를 제공합니다.', () => {
    const TempComponent = () => {
        const [displayDate, setDisplayDate] = (0, react_1.useState)(new types_1.PurpleDate([2019, 9, 1]));
        const result = (0, useBaseDatePicker_1.default)({
            displayDate,
            onUpdateDisplayDate: setDisplayDate,
        });
        return (react_1.default.createElement("div", null,
            react_1.default.createElement("div", null,
                "\uB144:",
                result.displayYear),
            react_1.default.createElement("div", null,
                "\uC6D4:",
                result.displayMonth)));
    };
    it('displayDate 출력 확인', () => {
        (0, react_2.render)(react_1.default.createElement(TempComponent, null));
        expect(react_2.screen.getByText('년:2019')).toBeInTheDocument();
        expect(react_2.screen.getByText('월:9')).toBeInTheDocument();
    });
    it('getDateListByWeek: 특정달에 존재하는 일자들을 주별 리스트로 반환합니다 - (1)', () => {
        const formatter = (d) => {
            if (d === types_1.EMPTY_DATE) {
                return types_1.EMPTY_DATE;
            }
            else {
                return d.toDateString('YYYY.MM.DD');
            }
        };
        const dateList = (0, index_util_1.getDateList)({
            displayYear: 2023,
            displayMonth: 8,
        });
        expect(JSON.stringify(dateList.map(formatter))).toBe(JSON.stringify([
            null,
            null,
            '2023.08.01',
            '2023.08.02',
            '2023.08.03',
            '2023.08.04',
            '2023.08.05',
            '2023.08.06',
            '2023.08.07',
            '2023.08.08',
            '2023.08.09',
            '2023.08.10',
            '2023.08.11',
            '2023.08.12',
            '2023.08.13',
            '2023.08.14',
            '2023.08.15',
            '2023.08.16',
            '2023.08.17',
            '2023.08.18',
            '2023.08.19',
            '2023.08.20',
            '2023.08.21',
            '2023.08.22',
            '2023.08.23',
            '2023.08.24',
            '2023.08.25',
            '2023.08.26',
            '2023.08.27',
            '2023.08.28',
            '2023.08.29',
            '2023.08.30',
            '2023.08.31',
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
        ]));
    });
    it('getDateListByWeek: 특정달에 존재하는 일자들을 주별 리스트로 반환합니다 - (2)', () => {
        const formatter = (d) => {
            if (d === types_1.EMPTY_DATE) {
                return types_1.EMPTY_DATE;
            }
            else {
                return d.toDateString('YYYY.MM.DD');
            }
        };
        const dateList = (0, index_util_1.getDateList)({
            displayYear: 2023,
            displayMonth: 2,
        });
        expect(JSON.stringify(dateList.map(formatter))).toBe(JSON.stringify([
            null,
            null,
            null,
            '2023.02.01',
            '2023.02.02',
            '2023.02.03',
            '2023.02.04',
            '2023.02.05',
            '2023.02.06',
            '2023.02.07',
            '2023.02.08',
            '2023.02.09',
            '2023.02.10',
            '2023.02.11',
            '2023.02.12',
            '2023.02.13',
            '2023.02.14',
            '2023.02.15',
            '2023.02.16',
            '2023.02.17',
            '2023.02.18',
            '2023.02.19',
            '2023.02.20',
            '2023.02.21',
            '2023.02.22',
            '2023.02.23',
            '2023.02.24',
            '2023.02.25',
            '2023.02.26',
            '2023.02.27',
            '2023.02.28',
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
        ]));
    });
});
describe('checkIsInRagne 함수는 범위 내에 있는지 체크합니다', () => {
    it('START_DATE 는 달력의 범위 시작 상수, END_DATE는 범위 끝 상수로 사용됩니다.', () => {
        expect((0, index_util_1.checkIsInRange)({
            from: types_1.START_DATE,
            to: new types_1.PurpleDate([2023, 8, 31]),
            target: new types_1.PurpleDate([2023, 8, 30]),
        })).toBe(true);
        expect((0, index_util_1.checkIsInRange)({
            from: new types_1.PurpleDate([2023, 8, 31]),
            to: types_1.END_DATE,
            target: new types_1.PurpleDate([2023, 8, 30]),
        })).toBe(false);
        expect((0, index_util_1.checkIsInRange)({
            from: new types_1.PurpleDate([2023, 8, 31]),
            to: types_1.END_DATE,
            target: new types_1.PurpleDate([2023, 8, 31]),
        })).toBe(true);
        expect((0, index_util_1.checkIsInRange)({
            from: new types_1.PurpleDate([2023, 8, 31]),
            to: types_1.END_DATE,
            target: new types_1.PurpleDate([2023, 9, 1]),
        })).toBe(true);
    });
    it(`from | to 중에 ${types_1.EMPTY_DATE} 값은, 미선택으로 인식합니다`, () => {
        expect((0, index_util_1.checkIsInRange)({
            from: types_1.EMPTY_DATE,
            to: types_1.EMPTY_DATE,
            target: new types_1.PurpleDate([2023, 8, 30]),
        })).toBe(false);
        expect((0, index_util_1.checkIsInRange)({
            from: new types_1.PurpleDate([2023, 8, 31]),
            to: types_1.EMPTY_DATE,
            target: new types_1.PurpleDate([2023, 8, 30]),
        })).toBe(false);
        expect((0, index_util_1.checkIsInRange)({
            from: new types_1.PurpleDate([2023, 8, 31]),
            to: types_1.EMPTY_DATE,
            target: new types_1.PurpleDate([2023, 8, 31]),
        })).toBe(false);
        expect((0, index_util_1.checkIsInRange)({
            from: new types_1.PurpleDate([2023, 8, 31]),
            to: types_1.EMPTY_DATE,
            target: new types_1.PurpleDate([2023, 9, 1]),
        })).toBe(false);
        expect((0, index_util_1.checkIsInRange)({
            from: new types_1.PurpleDate([2023, 8, 1]),
            to: new types_1.PurpleDate([2023, 8, 31]),
            target: new types_1.PurpleDate([2023, 8, 2]),
        })).toBe(true);
        expect((0, index_util_1.checkIsInRange)({
            from: new types_1.PurpleDate([2023, 8, 1]),
            to: new types_1.PurpleDate([2023, 8, 31]),
            target: new types_1.PurpleDate([2023, 9, 2]),
        })).toBe(false);
    });
});
describe('Year & Month Controller', () => {
    const TempComponent = () => {
        const [displayDate, setDisplayDate] = (0, react_1.useState)(new types_1.PurpleDate([2019, 1, 1]));
        const result = (0, useBaseDatePicker_1.default)({
            displayDate,
            onUpdateDisplayDate: setDisplayDate,
        });
        return (react_1.default.createElement("div", null,
            react_1.default.createElement("div", null,
                react_1.default.createElement("button", { onClick: result.handleClickPrevYear }, "prev year"),
                react_1.default.createElement("button", { onClick: result.handleClickPrevMonth }, "prev month"),
                react_1.default.createElement("button", { onClick: result.handleClickNextMonth }, "next month"),
                react_1.default.createElement("button", { onClick: result.handleClickNextYear }, "next year")),
            react_1.default.createElement("div", null,
                "\uB144:",
                result.displayYear),
            react_1.default.createElement("div", null,
                "\uC6D4:",
                result.displayMonth)));
    };
    it('표시년월을 조절할 수 있습니다.', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_2.render)(react_1.default.createElement(TempComponent, null));
        const prevYearButton = react_2.screen.getByText('prev year');
        const prevMonthButton = react_2.screen.getByText('prev month');
        const nextMonthButton = react_2.screen.getByText('next month');
        const nextYearButton = react_2.screen.getByText('next year');
        expect(react_2.screen.getByText('년:2019')).toBeInTheDocument();
        expect(react_2.screen.getByText('월:1')).toBeInTheDocument();
        yield user_event_1.default.click(prevYearButton);
        yield user_event_1.default.click(prevYearButton);
        expect(react_2.screen.getByText('년:2017')).toBeInTheDocument();
        expect(react_2.screen.getByText('월:1')).toBeInTheDocument();
        yield user_event_1.default.click(prevMonthButton);
        expect(react_2.screen.getByText('년:2016')).toBeInTheDocument();
        expect(react_2.screen.getByText('월:12')).toBeInTheDocument();
        yield user_event_1.default.click(nextMonthButton);
        yield user_event_1.default.click(nextMonthButton);
        expect(react_2.screen.getByText('년:2017')).toBeInTheDocument();
        expect(react_2.screen.getByText('월:2')).toBeInTheDocument();
        yield user_event_1.default.click(nextYearButton);
        expect(react_2.screen.getByText('년:2018')).toBeInTheDocument();
        expect(react_2.screen.getByText('월:2')).toBeInTheDocument();
    }));
});
