var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "@web-atoms/unit-test/dist/Assert", "@web-atoms/unit-test/dist/Test", "../../core/AtomSelectableList", "../../unit/AtomTest"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Assert_1 = require("@web-atoms/unit-test/dist/Assert");
    var Test_1 = require("@web-atoms/unit-test/dist/Test");
    var AtomSelectableList_1 = require("../../core/AtomSelectableList");
    var AtomTest_1 = require("../../unit/AtomTest");
    var AtomItemListTest = /** @class */ (function (_super) {
        __extends(AtomItemListTest, _super);
        function AtomItemListTest() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        AtomItemListTest.prototype.syncItems = function () {
            var items = [1, 2, 3, 4, 5];
            var list = new AtomSelectableList_1.default();
            var a = items;
            a.total = 20;
            list.replace(items);
            list.value = 2;
            list.replace([4, 5, 6, 2]);
            Assert_1.default.equals(2, list.value);
            Assert_1.default.equals(3, list.selectedIndex);
        };
        AtomItemListTest.prototype.singleItem = function () {
            var list = new AtomSelectableList_1.default();
            list.replace([1, 2, 3, 4, 5]);
            list.items[2].selected = true;
            Assert_1.default.equals(1, list.selectedItems.length);
            Assert_1.default.equals(3, list.value);
        };
        AtomItemListTest.prototype.setValue = function () {
            var list = new AtomSelectableList_1.default();
            list.replace([1, 2, 3, 4, 5]);
            list.value = 3;
            Assert_1.default.equals(1, list.selectedItems.length);
            Assert_1.default.equals(3, list.value);
        };
        AtomItemListTest.prototype.clearSelection = function () {
            var list = new AtomSelectableList_1.default();
            list.replace([1, 2, 3, 4]);
            list.value = 2;
            Assert_1.default.equals(1, list.selectedIndex);
            list.items[1].selected = false;
            Assert_1.default.equals(-1, list.selectedIndex);
        };
        AtomItemListTest.prototype.reselect = function () {
            var list = new AtomSelectableList_1.default();
            list.replace([1, 2, 3]);
            list.value = 2;
            Assert_1.default.equals(1, list.selectedIndex);
            list.items[1].selected = true;
        };
        AtomItemListTest.prototype.selectMultiple = function () {
            var list = new AtomSelectableList_1.default(true);
            list.replace([1, 2, 3, 4, 5]);
            list.items[1].selected = true;
            list.items[2].selected = true;
            Assert_1.default.equals(2, list.selectedItems.length);
            var v = list.value.join(", ");
            Assert_1.default.equals("2, 3", v);
        };
        AtomItemListTest.prototype.selectMultipleValues = function () {
            var list = new AtomSelectableList_1.default(true);
            list.replace([1, 2, 3, 4, 5]);
            list.value = [2, 3];
            Assert_1.default.equals(2, list.selectedItems.length);
            var v = list.value.join(", ");
            Assert_1.default.equals("2, 3", v);
        };
        AtomItemListTest.prototype.selectIndexMinusOne = function () {
            var list = new AtomSelectableList_1.default(false, function (x) { return x; });
            list.value = 2;
            list.replace([1, 2, 3, 4]);
            Assert_1.default.equals(1, list.selectedIndex);
            list.selectedIndex = -1;
            Assert_1.default.equals(-1, list.selectedIndex);
            Assert_1.default.isUndefined(list.value);
            list.selectedIndex = 2;
            Assert_1.default.equals(3, list.value);
        };
        AtomItemListTest.prototype.replaceMultipleSelectedValues = function () {
            var list = new AtomSelectableList_1.default(true, function (x) { return x.value; });
            list.value = ["v2", "v3"];
            list.replace([
                { label: "l1", value: "v1" },
                { label: "l2", value: "v2" },
                { label: "l3", value: "v3" },
                { label: "l4", value: "v4" }
            ]);
            Assert_1.default.equals(2, list.selectedItems.length);
            Assert_1.default.equals("l2,l3", list.selectedItems.map(function (x) { return x.item.label; }).sort().join(","));
        };
        AtomItemListTest.prototype.selectMethod = function () {
            var list = new AtomSelectableList_1.default();
            list.replace([1, 2]);
            list.select(1);
            Assert_1.default.equals(0, list.selectedIndex);
            list.deselect(1);
            Assert_1.default.equals(-1, list.selectedIndex);
            list.toggle(1);
            Assert_1.default.equals(0, list.selectedIndex);
        };
        AtomItemListTest.prototype.selectItemMethod = function () {
            var list = new AtomSelectableList_1.default();
            list.replace([1, 2]);
            var one = list.items[0];
            list.select(one);
            Assert_1.default.equals(0, list.selectedIndex);
            list.deselect(one);
            Assert_1.default.equals(-1, list.selectedIndex);
            list.toggle(one);
            Assert_1.default.equals(0, list.selectedIndex);
        };
        AtomItemListTest.prototype.find = function () {
            var list = new AtomSelectableList_1.default(true, function (x) { return x.value; });
            list.value = ["v2", "v3"];
            list.replace([
                { label: "l1", value: "v1" },
                { label: "l2", value: "v2" },
                { label: "l3", value: "v3" },
                { label: "l4", value: "v4" }
            ]);
            var item = list.find(function (x) { return x.value === "v4"; });
            Assert_1.default.equals("l4", item.item.label);
            var item2 = list.find(item.item);
            Assert_1.default.equals("l4", item2.item.label);
        };
        AtomItemListTest.prototype.getLabels = function () {
            var list = new AtomSelectableList_1.default(true, function (x) { return x.value; }, function (x) { return x.label; });
            list.value = ["v2", "v3"];
            list.replace([
                { label: "l1", value: "v1" },
                { label: "l2", value: "v2" },
                { label: "l3", value: "v3" },
                { label: "l4", value: "v4" }
            ]);
            var label = list.label.join(",");
            Assert_1.default.equals("l2,l3", label);
        };
        __decorate([
            Test_1.default,
            __metadata("design:type", Function),
            __metadata("design:paramtypes", []),
            __metadata("design:returntype", void 0)
        ], AtomItemListTest.prototype, "syncItems", null);
        __decorate([
            Test_1.default,
            __metadata("design:type", Function),
            __metadata("design:paramtypes", []),
            __metadata("design:returntype", void 0)
        ], AtomItemListTest.prototype, "singleItem", null);
        __decorate([
            Test_1.default,
            __metadata("design:type", Function),
            __metadata("design:paramtypes", []),
            __metadata("design:returntype", void 0)
        ], AtomItemListTest.prototype, "setValue", null);
        __decorate([
            Test_1.default,
            __metadata("design:type", Function),
            __metadata("design:paramtypes", []),
            __metadata("design:returntype", void 0)
        ], AtomItemListTest.prototype, "clearSelection", null);
        __decorate([
            Test_1.default,
            __metadata("design:type", Function),
            __metadata("design:paramtypes", []),
            __metadata("design:returntype", void 0)
        ], AtomItemListTest.prototype, "reselect", null);
        __decorate([
            Test_1.default,
            __metadata("design:type", Function),
            __metadata("design:paramtypes", []),
            __metadata("design:returntype", void 0)
        ], AtomItemListTest.prototype, "selectMultiple", null);
        __decorate([
            Test_1.default,
            __metadata("design:type", Function),
            __metadata("design:paramtypes", []),
            __metadata("design:returntype", void 0)
        ], AtomItemListTest.prototype, "selectMultipleValues", null);
        __decorate([
            Test_1.default,
            __metadata("design:type", Function),
            __metadata("design:paramtypes", []),
            __metadata("design:returntype", void 0)
        ], AtomItemListTest.prototype, "selectIndexMinusOne", null);
        __decorate([
            Test_1.default,
            __metadata("design:type", Function),
            __metadata("design:paramtypes", []),
            __metadata("design:returntype", void 0)
        ], AtomItemListTest.prototype, "replaceMultipleSelectedValues", null);
        __decorate([
            Test_1.default,
            __metadata("design:type", Function),
            __metadata("design:paramtypes", []),
            __metadata("design:returntype", void 0)
        ], AtomItemListTest.prototype, "selectMethod", null);
        __decorate([
            Test_1.default,
            __metadata("design:type", Function),
            __metadata("design:paramtypes", []),
            __metadata("design:returntype", void 0)
        ], AtomItemListTest.prototype, "selectItemMethod", null);
        __decorate([
            Test_1.default,
            __metadata("design:type", Function),
            __metadata("design:paramtypes", []),
            __metadata("design:returntype", void 0)
        ], AtomItemListTest.prototype, "find", null);
        __decorate([
            Test_1.default,
            __metadata("design:type", Function),
            __metadata("design:paramtypes", []),
            __metadata("design:returntype", void 0)
        ], AtomItemListTest.prototype, "getLabels", null);
        return AtomItemListTest;
    }(AtomTest_1.AtomTest));
    exports.AtomItemListTest = AtomItemListTest;
});
//# sourceMappingURL=AtomItemListTest.js.map