"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Settings_1 = require("./Settings");
const _chai_spec_1 = require("./_chai.spec");
describe("Settings", () => {
    afterEach(() => {
        // Always reset to defaults after each test to avoid test pollution
        Settings_1.Settings.reset();
    });
    describe("allowArchaicTimezoneOffsets", () => {
        it("defaults to false", () => {
            (0, _chai_spec_1.expect)(Settings_1.Settings.allowArchaicTimezoneOffsets.value).to.eql(false);
        });
        it("can be set to true", () => {
            Settings_1.Settings.allowArchaicTimezoneOffsets.value = true;
            (0, _chai_spec_1.expect)(Settings_1.Settings.allowArchaicTimezoneOffsets.value).to.eql(true);
        });
        it("can be set to false after being true", () => {
            Settings_1.Settings.allowArchaicTimezoneOffsets.value = true;
            Settings_1.Settings.allowArchaicTimezoneOffsets.value = false;
            (0, _chai_spec_1.expect)(Settings_1.Settings.allowArchaicTimezoneOffsets.value).to.eql(false);
        });
    });
    describe("resetToDefaults()", () => {
        it("resets allowArchaicTimezoneOffsets to false", () => {
            Settings_1.Settings.allowArchaicTimezoneOffsets.value = true;
            Settings_1.Settings.reset();
            (0, _chai_spec_1.expect)(Settings_1.Settings.allowArchaicTimezoneOffsets.value).to.eql(false);
        });
        it("can be called multiple times", () => {
            Settings_1.Settings.reset();
            Settings_1.Settings.reset();
            (0, _chai_spec_1.expect)(Settings_1.Settings.allowArchaicTimezoneOffsets.value).to.eql(false);
        });
        it("works when settings are already at defaults", () => {
            Settings_1.Settings.reset();
            (0, _chai_spec_1.expect)(Settings_1.Settings.allowArchaicTimezoneOffsets.value).to.eql(false);
        });
    });
    describe("Setting.onChange()", () => {
        it("notifies listeners when a setting changes", () => {
            let called = false;
            let receivedOld;
            let receivedNew;
            const unsubscribe = Settings_1.Settings.allowArchaicTimezoneOffsets.onChange((oldValue, newValue) => {
                called = true;
                receivedOld = oldValue;
                receivedNew = newValue;
            });
            Settings_1.Settings.allowArchaicTimezoneOffsets.value = true;
            (0, _chai_spec_1.expect)(called).to.eql(true);
            (0, _chai_spec_1.expect)(receivedOld).to.eql(false);
            (0, _chai_spec_1.expect)(receivedNew).to.eql(true);
            unsubscribe();
        });
        it("does not notify when setting the same value", () => {
            let callCount = 0;
            const unsubscribe = Settings_1.Settings.allowArchaicTimezoneOffsets.onChange(() => {
                callCount++;
            });
            Settings_1.Settings.allowArchaicTimezoneOffsets.value = false; // Already false
            (0, _chai_spec_1.expect)(callCount).to.eql(0);
            Settings_1.Settings.allowArchaicTimezoneOffsets.value = true;
            (0, _chai_spec_1.expect)(callCount).to.eql(1);
            Settings_1.Settings.allowArchaicTimezoneOffsets.value = true; // Already true
            (0, _chai_spec_1.expect)(callCount).to.eql(1);
            unsubscribe();
        });
        it("allows unsubscribing from changes", () => {
            let callCount = 0;
            const unsubscribe = Settings_1.Settings.allowArchaicTimezoneOffsets.onChange(() => {
                callCount++;
            });
            Settings_1.Settings.allowArchaicTimezoneOffsets.value = true;
            (0, _chai_spec_1.expect)(callCount).to.eql(1);
            unsubscribe();
            Settings_1.Settings.allowArchaicTimezoneOffsets.value = false;
            (0, _chai_spec_1.expect)(callCount).to.eql(1); // Should not increment
        });
        it("supports multiple listeners for the same setting", () => {
            let call1 = false;
            let call2 = false;
            const unsubscribe1 = Settings_1.Settings.allowArchaicTimezoneOffsets.onChange(() => {
                call1 = true;
            });
            const unsubscribe2 = Settings_1.Settings.allowArchaicTimezoneOffsets.onChange(() => {
                call2 = true;
            });
            Settings_1.Settings.allowArchaicTimezoneOffsets.value = true;
            (0, _chai_spec_1.expect)(call1).to.eql(true);
            (0, _chai_spec_1.expect)(call2).to.eql(true);
            unsubscribe1();
            unsubscribe2();
        });
        it("only notifies listeners for the specific setting that changed", () => {
            let archaicCalled = false;
            let bakerCalled = false;
            const unsubscribe1 = Settings_1.Settings.allowArchaicTimezoneOffsets.onChange(() => {
                archaicCalled = true;
            });
            const unsubscribe2 = Settings_1.Settings.allowBakerIslandTime.onChange(() => {
                bakerCalled = true;
            });
            Settings_1.Settings.allowArchaicTimezoneOffsets.value = true;
            (0, _chai_spec_1.expect)(archaicCalled).to.eql(true);
            (0, _chai_spec_1.expect)(bakerCalled).to.eql(false);
            unsubscribe1();
            unsubscribe2();
        });
    });
});
//# sourceMappingURL=Settings.spec.js.map