"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 bentleyjs_core_1 = require("@bentley/bentleyjs-core");
const imodeljs_frontend_1 = require("@bentley/imodeljs-frontend");
const frontend_1 = require("@bentley/oidc-signin-tool/lib/frontend");
const presentation_common_1 = require("@bentley/presentation-common");
const presentation_frontend_1 = require("@bentley/presentation-frontend");
const defaultRuleset = require("./rulesets/default.json");
const getRelatedDistinctValues = require("./rulesets/DistinctValues/getRelatedDistinctValues.json");
const getFilteredNodePaths = require("./rulesets/NodePaths/getFilteredNodePaths.json");
const getNodePaths = require("./rulesets/NodePaths/getNodePaths.json");
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.adminUserAccessToken;
        imodeljs_frontend_1.IModelApp.authorizationClient = new frontend_1.TestFrontendAuthorizationClient(accessToken);
        imodel = await imodeljs_frontend_1.CheckpointConnection.openRemote(iTwinId, iModelId);
    });
    after(() => {
        presentation_frontend_1.Presentation.terminate();
    });
    it("getNodes works as expected", async () => {
        const rootNodes = await presentation_frontend_1.Presentation.presentation.getNodes({
            imodel,
            rulesetOrId: defaultRuleset,
        });
        chai_1.expect(rootNodes.length).to.be.equal(1);
    });
    it("getNodesAndCount works as expected", async () => {
        const nodesAndCount = await presentation_frontend_1.Presentation.presentation.getNodesAndCount({
            imodel,
            rulesetOrId: defaultRuleset,
        });
        chai_1.expect(nodesAndCount.count).to.not.be.undefined;
    });
    it("getNodesCount works as expected", async () => {
        const count = await presentation_frontend_1.Presentation.presentation.getNodesCount({
            imodel,
            rulesetOrId: defaultRuleset,
        });
        chai_1.expect(count).to.not.be.undefined;
    });
    it("getNodePath works as expected", async () => {
        const key1 = { id: bentleyjs_core_1.Id64.fromString("0x1"), className: "BisCore:RepositoryModel" };
        const key2 = { id: bentleyjs_core_1.Id64.fromString("0x1"), className: "BisCore:Subject" };
        const key3 = { id: bentleyjs_core_1.Id64.fromString("0x10"), className: "BisCore:DefinitionPartition" };
        const key4 = { id: bentleyjs_core_1.Id64.fromString("0xe"), className: "BisCore:LinkPartition" };
        const keys = [[key1, key2, key3], [key1, key2, key4]];
        const result = await presentation_frontend_1.Presentation.presentation.getNodePaths({
            imodel,
            rulesetOrId: getNodePaths,
            instancePaths: keys,
            markedIndex: 1,
        });
        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: getFilteredNodePaths,
            filterText: "filter",
        });
        chai_1.expect(result).to.not.be.undefined;
    });
    it("getContentSources works as expected", async () => {
        const result = await presentation_frontend_1.Presentation.presentation.getContentSources({
            imodel,
            classes: [],
        });
        chai_1.expect(result).to.not.be.undefined;
    });
    it("getContentDescriptor works as expected", async () => {
        const key1 = { id: bentleyjs_core_1.Id64.fromString("0x1"), className: "BisCore:Subject" };
        const key2 = { id: bentleyjs_core_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: getRelatedDistinctValues,
            displayType: "Grid",
            keys,
        });
        chai_1.expect(descriptor).to.not.be.undefined;
    });
    it("getContentAndSize works as expected", async () => {
        const key1 = { id: bentleyjs_core_1.Id64.fromString("0x1"), className: "BisCore:Subject" };
        const key2 = { id: bentleyjs_core_1.Id64.fromString("0x17"), className: "BisCore:SpatialCategory" };
        const keys = new presentation_common_1.KeySet([key1, key2]);
        const contentAndSize = await presentation_frontend_1.Presentation.presentation.getContentAndSize({
            imodel,
            rulesetOrId: getRelatedDistinctValues,
            descriptor: {},
            keys,
        });
        chai_1.expect(contentAndSize).to.not.be.undefined;
    });
    it("getContent works as expected", async () => {
        const key1 = { id: bentleyjs_core_1.Id64.fromString("0x1"), className: "BisCore:Subject" };
        const key2 = { id: bentleyjs_core_1.Id64.fromString("0x17"), className: "BisCore:SpatialCategory" };
        const keys = new presentation_common_1.KeySet([key1, key2]);
        const content = await presentation_frontend_1.Presentation.presentation.getContent({
            imodel,
            rulesetOrId: getRelatedDistinctValues,
            descriptor: {},
            keys,
        });
        chai_1.expect(content).to.not.be.undefined;
    });
    it("getContentSetSize works as expected", async () => {
        const key1 = { id: bentleyjs_core_1.Id64.fromString("0x1"), className: "BisCore:Subject" };
        const key2 = { id: bentleyjs_core_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: getRelatedDistinctValues,
            descriptor: {},
            keys,
        });
        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",
        });
        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: bentleyjs_core_1.Id64.fromString("0x1"), className: "BisCore:Subject" },
        });
        chai_1.expect(displayLabel).to.not.be.undefined;
    });
    it("getDisplayLabelDefinitions works as expected", async () => {
        const key1 = { id: bentleyjs_core_1.Id64.fromString("0x1"), className: "BisCore:Subject" };
        const key2 = { id: bentleyjs_core_1.Id64.fromString("0x17"), className: "BisCore:SpatialCategory" };
        const displayLabels = await presentation_frontend_1.Presentation.presentation.getDisplayLabelDefinitions({
            imodel,
            keys: [key1, key2],
        });
        chai_1.expect(displayLabels).to.not.be.undefined;
    });
    it("getSelectionScopes works as expected", async () => {
        const scopeIds = await presentation_frontend_1.Presentation.selection.scopes.getSelectionScopes(imodel);
        chai_1.expect(scopeIds).to.not.be.undefined;
    });
    it("computeSelection works as expected", async () => {
        const computedSelections = await presentation_frontend_1.Presentation.selection.scopes.computeSelection(imodel, ["0x1"], "element");
        chai_1.expect(computedSelections).to.not.be.undefined;
    });
});
//# sourceMappingURL=PresentationRpc.test.js.map