"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
const chai_1 = require("chai");
const core_bentley_1 = require("@itwin/core-bentley");
const core_frontend_1 = require("@itwin/core-frontend");
const frontend_1 = require("@itwin/oidc-signin-tool/lib/cjs/frontend");
const presentation_common_1 = require("@itwin/presentation-common");
const presentation_frontend_1 = require("@itwin/presentation-frontend");
const TestContext_1 = require("./setup/TestContext");
describe("PresentationRpcInterface tests", () => {
    let imodel;
    before(async function () {
        const testContext = await TestContext_1.TestContext.instance();
        if (!testContext.settings.runPresentationRpcTests) {
            this.skip();
        }
        await presentation_frontend_1.Presentation.initialize();
        const iModelId = testContext.iModelWithChangesets.iModelId;
        const iTwinId = testContext.iModelWithChangesets.iTwinId;
        const accessToken = testContext.serviceAuthToken;
        core_frontend_1.IModelApp.authorizationClient = new frontend_1.TestFrontendAuthorizationClient(accessToken);
        imodel = await core_frontend_1.CheckpointConnection.openRemote(iTwinId, iModelId);
    });
    after(() => {
        presentation_frontend_1.Presentation.terminate();
    });
    /* eslint-disable @typescript-eslint/no-deprecated */
    it("getNodes works as expected", async () => {
        const rootNodes = await presentation_frontend_1.Presentation.presentation.getNodesIterator({
            imodel,
            rulesetOrId: createNodesRuleset(),
        });
        (0, chai_1.expect)(rootNodes).to.not.be.empty;
    });
    it("getNodesCount works as expected", async () => {
        const count = await presentation_frontend_1.Presentation.presentation.getNodesCount({
            imodel,
            rulesetOrId: createNodesRuleset(),
        });
        (0, chai_1.expect)(count).to.not.be.undefined;
    });
    it("getNodePaths works as expected", async () => {
        const result = await presentation_frontend_1.Presentation.presentation.getNodePaths({
            imodel,
            rulesetOrId: createNodesRuleset(),
            instancePaths: [[{ id: core_bentley_1.Id64.fromString("0x1"), className: "BisCore:RepositoryModel" }]],
            markedIndex: 0,
        });
        (0, chai_1.expect)(result).to.not.be.undefined;
    });
    it("getFilteredNodePaths works as expected", async () => {
        const result = await presentation_frontend_1.Presentation.presentation.getFilteredNodePaths({
            imodel,
            rulesetOrId: createNodesRuleset(),
            filterText: "",
        });
        (0, chai_1.expect)(result).to.not.be.undefined;
    });
    /* eslint-enable @typescript-eslint/no-deprecated */
    it("getContentSources works as expected", async () => {
        const result = await presentation_frontend_1.Presentation.presentation.getContentSources({
            imodel,
            classes: ["BisCore:Subject"],
        });
        (0, chai_1.expect)(result).to.not.be.undefined;
    });
    it("getContentDescriptor works as expected", async () => {
        const key1 = { id: core_bentley_1.Id64.fromString("0x1"), className: "BisCore:Subject" };
        const key2 = { id: core_bentley_1.Id64.fromString("0x17"), className: "BisCore:SpatialCategory" };
        const keys = new presentation_common_1.KeySet([key1, key2]);
        const descriptor = await presentation_frontend_1.Presentation.presentation.getContentDescriptor({
            imodel,
            rulesetOrId: createContentRuleset(),
            displayType: "Grid",
            keys,
        });
        (0, chai_1.expect)(descriptor).to.not.be.undefined;
    });
    it("getContentAndSize works as expected", async () => {
        const key1 = { id: core_bentley_1.Id64.fromString("0x1"), className: "BisCore:Subject" };
        const key2 = { id: core_bentley_1.Id64.fromString("0x17"), className: "BisCore:SpatialCategory" };
        const keys = new presentation_common_1.KeySet([key1, key2]);
        // eslint-disable-next-line @typescript-eslint/no-deprecated
        const contentAndSize = await presentation_frontend_1.Presentation.presentation.getContentAndSize({
            imodel,
            rulesetOrId: createContentRuleset(),
            descriptor: {},
            keys,
        });
        (0, chai_1.expect)(contentAndSize).to.not.be.undefined;
    });
    it("getContent works as expected", async () => {
        const key1 = { id: core_bentley_1.Id64.fromString("0x1"), className: "BisCore:Subject" };
        const key2 = { id: core_bentley_1.Id64.fromString("0x17"), className: "BisCore:SpatialCategory" };
        const keys = new presentation_common_1.KeySet([key1, key2]);
        // eslint-disable-next-line @typescript-eslint/no-deprecated
        const content = await presentation_frontend_1.Presentation.presentation.getContent({
            imodel,
            rulesetOrId: createContentRuleset(),
            descriptor: {},
            keys,
        });
        (0, chai_1.expect)(content).to.not.be.undefined;
    });
    it("getContentSetSize works as expected", async () => {
        const key1 = { id: core_bentley_1.Id64.fromString("0x1"), className: "BisCore:Subject" };
        const key2 = { id: core_bentley_1.Id64.fromString("0x17"), className: "BisCore:SpatialCategory" };
        const keys = new presentation_common_1.KeySet([key1, key2]);
        const contentSetSize = await presentation_frontend_1.Presentation.presentation.getContentSetSize({
            imodel,
            rulesetOrId: createContentRuleset(),
            descriptor: {},
            keys,
        });
        (0, chai_1.expect)(contentSetSize).to.not.be.undefined;
    });
    it("getElementProperties works as expected", async () => {
        const result = await presentation_frontend_1.Presentation.presentation.getElementProperties({
            imodel,
            elementId: "0x1",
        });
        (0, chai_1.expect)(result).to.not.be.undefined;
    });
    it("getDisplayLabelDefinition works as expected", async () => {
        const displayLabel = await presentation_frontend_1.Presentation.presentation.getDisplayLabelDefinition({
            imodel,
            key: { id: core_bentley_1.Id64.fromString("0x1"), className: "BisCore:Subject" },
        });
        (0, chai_1.expect)(displayLabel).to.not.be.undefined;
    });
    it("getDisplayLabelDefinitions works as expected", async () => {
        const key1 = { id: core_bentley_1.Id64.fromString("0x1"), className: "BisCore:Subject" };
        const key2 = { id: core_bentley_1.Id64.fromString("0x17"), className: "BisCore:SpatialCategory" };
        const displayLabels = await presentation_frontend_1.Presentation.presentation.getDisplayLabelDefinitionsIterator({
            imodel,
            keys: [key1, key2],
        });
        (0, chai_1.expect)(displayLabels).to.not.be.undefined;
    });
    it("getSelectionScopes works as expected", async () => {
        // eslint-disable-next-line @typescript-eslint/no-deprecated
        const scopeIds = await presentation_frontend_1.Presentation.selection.scopes.getSelectionScopes(imodel);
        (0, chai_1.expect)(scopeIds).to.not.be.undefined;
    });
    it("computeSelection works as expected", async () => {
        // eslint-disable-next-line @typescript-eslint/no-deprecated
        const computedSelections = await presentation_frontend_1.Presentation.selection.scopes.computeSelection(imodel, ["0x1"], "element");
        (0, chai_1.expect)(computedSelections).to.not.be.undefined;
    });
});
/* eslint-disable @typescript-eslint/no-deprecated */
const createNodesRuleset = () => ({
    id: "nodes",
    rules: [
        {
            ruleType: presentation_common_1.RuleTypes.RootNodes,
            specifications: [
                {
                    specType: presentation_common_1.ChildNodeSpecificationTypes.InstanceNodesOfSpecificClasses,
                    classes: {
                        schemaName: "BisCore",
                        classNames: ["Model"],
                        arePolymorphic: true,
                    },
                },
            ],
        },
    ],
});
/* eslint-enable @typescript-eslint/no-deprecated */
const createContentRuleset = () => ({
    id: "content",
    rules: [
        {
            ruleType: presentation_common_1.RuleTypes.Content,
            specifications: [
                {
                    specType: presentation_common_1.ContentSpecificationTypes.SelectedNodeInstances,
                },
            ],
        },
    ],
});
//# sourceMappingURL=PresentationRpc.test.js.map