"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const field_1 = require("../types/field");
const timeFrames_1 = require("../types/timeFrames");
const bigNumber_1 = require("./bigNumber");
describe('resolveGranularityInLabel', () => {
    it('replaces ${field.granularity} with lowercase granularity value', () => {
        expect((0, bigNumber_1.resolveGranularityInLabel)('compared to last ${events_date.granularity}', { events_date: timeFrames_1.DateGranularity.WEEK })).toBe('compared to last week');
    });
    it('replaces multiple different field references', () => {
        expect((0, bigNumber_1.resolveGranularityInLabel)('${events_date.granularity} and ${orders_created.granularity}', {
            events_date: timeFrames_1.DateGranularity.MONTH,
            orders_created: timeFrames_1.DateGranularity.WEEK,
        })).toBe('month and week');
    });
    it('replaces multiple occurrences of the same field', () => {
        expect((0, bigNumber_1.resolveGranularityInLabel)('${events_date.granularity} over ${events_date.granularity}', { events_date: timeFrames_1.DateGranularity.MONTH })).toBe('month over month');
    });
    it('returns label unchanged when no placeholders present', () => {
        expect((0, bigNumber_1.resolveGranularityInLabel)('static label', {
            events_date: timeFrames_1.DateGranularity.DAY,
        })).toBe('static label');
    });
    it('returns label unchanged when granularity map is empty', () => {
        expect((0, bigNumber_1.resolveGranularityInLabel)('compared to last ${events_date.granularity}', {})).toBe('compared to last ${events_date.granularity}');
    });
    it('leaves unmatched placeholders as-is', () => {
        expect((0, bigNumber_1.resolveGranularityInLabel)('${events_date.granularity} vs ${unknown_field.granularity}', { events_date: timeFrames_1.DateGranularity.DAY })).toBe('day vs ${unknown_field.granularity}');
    });
    it('returns undefined when label is undefined', () => {
        expect((0, bigNumber_1.resolveGranularityInLabel)(undefined, {
            events_date: timeFrames_1.DateGranularity.WEEK,
        })).toBeUndefined();
    });
    it('works with all DateGranularity values', () => {
        const map = { d: timeFrames_1.DateGranularity.DAY };
        expect((0, bigNumber_1.resolveGranularityInLabel)('${d.granularity}', map)).toBe('day');
        map.d = timeFrames_1.DateGranularity.WEEK;
        expect((0, bigNumber_1.resolveGranularityInLabel)('${d.granularity}', map)).toBe('week');
        map.d = timeFrames_1.DateGranularity.MONTH;
        expect((0, bigNumber_1.resolveGranularityInLabel)('${d.granularity}', map)).toBe('month');
        map.d = timeFrames_1.DateGranularity.QUARTER;
        expect((0, bigNumber_1.resolveGranularityInLabel)('${d.granularity}', map)).toBe('quarter');
        map.d = timeFrames_1.DateGranularity.YEAR;
        expect((0, bigNumber_1.resolveGranularityInLabel)('${d.granularity}', map)).toBe('year');
    });
    it('renders a standard-grain override verbatim (not lowercased)', () => {
        expect((0, bigNumber_1.resolveGranularityInLabel)('Revenue by ${events_date.granularity}', {
            events_date: { verbatim: 'Week starting Monday' },
        })).toBe('Revenue by Week starting Monday');
    });
});
describe('getGranularityMapFromItems', () => {
    it('maps time interval child dimensions to their base field id', () => {
        const itemsMap = {
            orders_order_date_week: {
                fieldType: field_1.FieldType.DIMENSION,
                type: field_1.DimensionType.DATE,
                table: 'orders',
                name: 'order_date_week',
                label: 'Order date week',
                timeInterval: timeFrames_1.TimeFrames.WEEK,
                timeIntervalBaseDimensionName: 'order_date',
            },
        };
        expect((0, bigNumber_1.getGranularityMapFromItems)(itemsMap)).toEqual({
            orders_order_date: timeFrames_1.DateGranularity.WEEK,
        });
    });
    it('maps a custom time interval dimension to its label', () => {
        const itemsMap = {
            orders_order_date_fiscal_quarter: {
                fieldType: field_1.FieldType.DIMENSION,
                type: field_1.DimensionType.STRING,
                table: 'orders',
                name: 'order_date_fiscal_quarter',
                label: 'Fiscal quarter',
                customTimeInterval: 'fiscal_quarter',
                timeIntervalBaseDimensionName: 'order_date',
            },
        };
        expect((0, bigNumber_1.getGranularityMapFromItems)(itemsMap)).toEqual({
            orders_order_date: 'Fiscal quarter',
        });
    });
    it('uses the verbatim override label for a standard grain with timeIntervalLabel', () => {
        const itemsMap = {
            orders_order_date_week: {
                fieldType: field_1.FieldType.DIMENSION,
                type: field_1.DimensionType.DATE,
                table: 'orders',
                name: 'order_date_week',
                label: 'Order date week starting monday',
                timeInterval: timeFrames_1.TimeFrames.WEEK,
                timeIntervalLabel: 'Week starting Monday',
                timeIntervalBaseDimensionName: 'order_date',
            },
        };
        expect((0, bigNumber_1.getGranularityMapFromItems)(itemsMap)).toEqual({
            orders_order_date: { verbatim: 'Week starting Monday' },
        });
    });
});
//# sourceMappingURL=bigNumber.test.js.map