"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const field_1 = require("../types/field");
const filter_1 = require("../types/filter");
const conditionalFormatting_1 = require("./conditionalFormatting");
// Mock field for testing
const mockNumericField = {
    name: 'test_field',
    table: 'test_table',
    type: field_1.DimensionType.NUMBER,
    fieldType: field_1.FieldType.DIMENSION,
    sql: 'test_sql',
    tableLabel: 'Test Table',
    label: 'Test Field',
    hidden: false,
};
describe('hasMatchingConditionalRules', () => {
    describe('LESS_THAN_OR_EQUAL operator', () => {
        it('should return true when field value is less than rule value', () => {
            const config = (0, conditionalFormatting_1.createConditionalFormattingConfigWithSingleColor)('#ff0000');
            const rule = (0, conditionalFormatting_1.createConditionalFormattingRuleWithValues)();
            rule.operator = filter_1.FilterOperator.LESS_THAN_OR_EQUAL;
            rule.values = [10];
            config.rules = [rule];
            const result = (0, conditionalFormatting_1.hasMatchingConditionalRules)(mockNumericField, 5, // less than 10
            {}, config);
            expect(result).toBe(true);
        });
        it('should return true when field value equals rule value', () => {
            const config = (0, conditionalFormatting_1.createConditionalFormattingConfigWithSingleColor)('#ff0000');
            const rule = (0, conditionalFormatting_1.createConditionalFormattingRuleWithValues)();
            rule.operator = filter_1.FilterOperator.LESS_THAN_OR_EQUAL;
            rule.values = [10];
            config.rules = [rule];
            const result = (0, conditionalFormatting_1.hasMatchingConditionalRules)(mockNumericField, 10, // equals 10
            {}, config);
            expect(result).toBe(true);
        });
        it('should return false when field value is greater than rule value', () => {
            const config = (0, conditionalFormatting_1.createConditionalFormattingConfigWithSingleColor)('#ff0000');
            const rule = (0, conditionalFormatting_1.createConditionalFormattingRuleWithValues)();
            rule.operator = filter_1.FilterOperator.LESS_THAN_OR_EQUAL;
            rule.values = [10];
            config.rules = [rule];
            const result = (0, conditionalFormatting_1.hasMatchingConditionalRules)(mockNumericField, 15, // greater than 10
            {}, config);
            expect(result).toBe(false);
        });
    });
    describe('GREATER_THAN_OR_EQUAL operator', () => {
        it('should return true when field value is greater than rule value', () => {
            const config = (0, conditionalFormatting_1.createConditionalFormattingConfigWithSingleColor)('#ff0000');
            const rule = (0, conditionalFormatting_1.createConditionalFormattingRuleWithValues)();
            rule.operator = filter_1.FilterOperator.GREATER_THAN_OR_EQUAL;
            rule.values = [10];
            config.rules = [rule];
            const result = (0, conditionalFormatting_1.hasMatchingConditionalRules)(mockNumericField, 15, // greater than 10
            {}, config);
            expect(result).toBe(true);
        });
        it('should return true when field value equals rule value', () => {
            const config = (0, conditionalFormatting_1.createConditionalFormattingConfigWithSingleColor)('#ff0000');
            const rule = (0, conditionalFormatting_1.createConditionalFormattingRuleWithValues)();
            rule.operator = filter_1.FilterOperator.GREATER_THAN_OR_EQUAL;
            rule.values = [10];
            config.rules = [rule];
            const result = (0, conditionalFormatting_1.hasMatchingConditionalRules)(mockNumericField, 10, // equals 10
            {}, config);
            expect(result).toBe(true);
        });
        it('should return false when field value is less than rule value', () => {
            const config = (0, conditionalFormatting_1.createConditionalFormattingConfigWithSingleColor)('#ff0000');
            const rule = (0, conditionalFormatting_1.createConditionalFormattingRuleWithValues)();
            rule.operator = filter_1.FilterOperator.GREATER_THAN_OR_EQUAL;
            rule.values = [10];
            config.rules = [rule];
            const result = (0, conditionalFormatting_1.hasMatchingConditionalRules)(mockNumericField, 5, // less than 10
            {}, config);
            expect(result).toBe(false);
        });
    });
    describe('Edge cases', () => {
        it('should handle multiple values with LESS_THAN_OR_EQUAL', () => {
            const config = (0, conditionalFormatting_1.createConditionalFormattingConfigWithSingleColor)('#ff0000');
            const rule = (0, conditionalFormatting_1.createConditionalFormattingRuleWithValues)();
            rule.operator = filter_1.FilterOperator.LESS_THAN_OR_EQUAL;
            rule.values = [5, 15];
            config.rules = [rule];
            // Should match if value is <= any of the rule values
            const result = (0, conditionalFormatting_1.hasMatchingConditionalRules)(mockNumericField, 10, // <= 15 (second value)
            {}, config);
            expect(result).toBe(true);
        });
        it('should handle multiple values with GREATER_THAN_OR_EQUAL', () => {
            const config = (0, conditionalFormatting_1.createConditionalFormattingConfigWithSingleColor)('#ff0000');
            const rule = (0, conditionalFormatting_1.createConditionalFormattingRuleWithValues)();
            rule.operator = filter_1.FilterOperator.GREATER_THAN_OR_EQUAL;
            rule.values = [5, 15];
            config.rules = [rule];
            // Should match if value is >= any of the rule values
            const result = (0, conditionalFormatting_1.hasMatchingConditionalRules)(mockNumericField, 10, // >= 5 (first value)
            {}, config);
            expect(result).toBe(true);
        });
    });
});
//# sourceMappingURL=conditionalFormatting.test.js.map