"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const testHelper_1 = require("../../testHelper");
const projectionTestUtils_1 = require("../../Utilities/projectionTestUtils");
/**
 *  Class for testing the array type with a set of foundational operations in a projection
 */
describe('Cdm/Projection/TestProjectionArray', () => {
    /**
     * The path between TestDataPath and TestName.
     */
    const testsSubpath = 'Cdm/Projection/ProjectionArrayTest';
    /**
     * All possible combinations of the different resolution directives
     */
    const resOptsCombinations = [
        [],
        ['referenceOnly'],
        ['normalized'],
        ['structured'],
        ['referenceOnly', 'normalized'],
        ['referenceOnly', 'structured'],
        ['normalized', 'structured'],
        ['referenceOnly', 'normalized', 'structured']
    ];
    /**
     * Test Array type on an entity attribute.
     */
    it('TestEntityAttribute', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestEntityAttribute';
        const entityName = 'ThreeMusketeers';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
        const entity = yield corpus.fetchObjectAsync(`local:/${entityName}.cdm.json/${entityName}`);
        const nonStructuredResolvedEntity = yield projectionTestUtils_1.projectionTestUtils.getResolvedEntity(corpus, entity, []);
        // Original set of attributes: ["name", "age", "address"]
        // in non-structured form 
        // Expand 1...3;
        // renameFormat = {m}{o};
        // alterTraits = { has.expansionInfo.list(expansionName: "{a}", ordinal: "{o}", memberAttribute: "{mo}") , "argumentsContainWildcards" : true }
        // addArtifactAttribute : "personCount"
        // alterTraits = { indicates.expansionInfo.count(expansionName: "{a}") , apply to "personCount" , "argumentsContainWildcards" : true }
        expect(nonStructuredResolvedEntity.attributes.length)
            .toEqual(10);
        projectionTestUtils_1.projectionTestUtils.validateExpansionInfoTrait(nonStructuredResolvedEntity.attributes.allItems[0], "name1", 1, "ThreePeople", "name");
        projectionTestUtils_1.projectionTestUtils.validateExpansionInfoTrait(nonStructuredResolvedEntity.attributes.allItems[1], "age1", 1, "ThreePeople", "age");
        projectionTestUtils_1.projectionTestUtils.validateExpansionInfoTrait(nonStructuredResolvedEntity.attributes.allItems[2], "address1", 1, "ThreePeople", "address");
        projectionTestUtils_1.projectionTestUtils.validateExpansionInfoTrait(nonStructuredResolvedEntity.attributes.allItems[3], "name2", 2, "ThreePeople", "name");
        projectionTestUtils_1.projectionTestUtils.validateExpansionInfoTrait(nonStructuredResolvedEntity.attributes.allItems[4], "age2", 2, "ThreePeople", "age");
        projectionTestUtils_1.projectionTestUtils.validateExpansionInfoTrait(nonStructuredResolvedEntity.attributes.allItems[5], "address2", 2, "ThreePeople", "address");
        projectionTestUtils_1.projectionTestUtils.validateExpansionInfoTrait(nonStructuredResolvedEntity.attributes.allItems[6], "name3", 3, "ThreePeople", "name");
        projectionTestUtils_1.projectionTestUtils.validateExpansionInfoTrait(nonStructuredResolvedEntity.attributes.allItems[7], "age3", 3, "ThreePeople", "age");
        projectionTestUtils_1.projectionTestUtils.validateExpansionInfoTrait(nonStructuredResolvedEntity.attributes.allItems[8], "address3", 3, "ThreePeople", "address");
        expect(nonStructuredResolvedEntity.attributes.allItems[9].name)
            .toEqual('personCount');
        expect(nonStructuredResolvedEntity.attributes.allItems[9].appliedTraits.allItems[1].namedReference)
            .toEqual('indicates.expansionInfo.count');
        expect(nonStructuredResolvedEntity.attributes.allItems[9].appliedTraits.allItems[1].arguments.allItems[0].value)
            .toEqual('ThreePeople');
        // Original set of attributes: ["name", "age", "address"]
        // in structured form 
        // alterTraits = { is.dataFormat.list }
        // addAttributeGroup: favoriteMusketeers
        const structuredResolvedEntity = yield projectionTestUtils_1.projectionTestUtils.getResolvedEntity(corpus, entity, ['structured']);
        expect(structuredResolvedEntity.attributes.length)
            .toEqual(1);
        const attGroupDefinition = projectionTestUtils_1.projectionTestUtils.validateAttributeGroup(structuredResolvedEntity.attributes, 'favoriteMusketeers');
        expect(attGroupDefinition.exhibitsTraits.item('is.dataFormat.list'))
            .not
            .toBeUndefined();
    }));
    /**
     * Test Array type on an type attribute.
     */
    it('TestTypeAttribute', () => __awaiter(void 0, void 0, void 0, function* () {
        const testName = 'TestTypeAttribute';
        const entityName = 'Person';
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, testName);
        for (const resOpt of resOptsCombinations) {
            yield projectionTestUtils_1.projectionTestUtils.loadEntityForResolutionOptionAndSave(corpus, testName, testsSubpath, entityName, resOpt);
        }
        const entity = yield corpus.fetchObjectAsync(`local:/${entityName}.cdm.json/${entityName}`);
        const nonStructuredResolvedEntity = yield projectionTestUtils_1.projectionTestUtils.getResolvedEntity(corpus, entity, []);
        // Original set of attributes: ["Favorite Terms"]
        // in non-structured form 
        // Expand 1...2;
        // renameFormat = Term {o};
        // alterTraits = { has.expansionInfo.list(expansionName: "{a}", ordinal: "{o}") , "argumentsContainWildcards" : true }
        // addArtifactAttribute : "number of favorite terms"
        // alterTraits = { indicates.expansionInfo.count(expansionName: "{a}") , apply to "number of favorite terms" , "argumentsContainWildcards" : true }
        expect(nonStructuredResolvedEntity.attributes.length)
            .toEqual(3);
        expect(nonStructuredResolvedEntity.attributes.allItems[0].name)
            .toEqual('Term 1');
        expect(nonStructuredResolvedEntity.attributes.allItems[1].name)
            .toEqual('Term 2');
        expect(nonStructuredResolvedEntity.attributes.allItems[2].name)
            .toEqual('number of favorite terms');
        expect(nonStructuredResolvedEntity.attributes.allItems[2].appliedTraits.allItems[1].namedReference)
            .toEqual('indicates.expansionInfo.count');
        expect(nonStructuredResolvedEntity.attributes.allItems[2].appliedTraits.allItems[1].arguments.allItems[0].value)
            .toEqual('Favorite Terms');
        // Original set of attributes: ["Favorite Terms"]
        // in structured form 
        // alterTraits = { is.dataFormat.list }
        const structuredResolvedEntity = yield projectionTestUtils_1.projectionTestUtils.getResolvedEntity(corpus, entity, ['structured']);
        expect(structuredResolvedEntity.attributes.length)
            .toEqual(1);
        expect(structuredResolvedEntity.attributes.allItems[0].name)
            .toEqual('Favorite Terms');
        expect(structuredResolvedEntity.attributes.allItems[0].appliedTraits.item('is.dataFormat.list'))
            .not
            .toBeUndefined();
    }));
});
//# sourceMappingURL=ProjectionArray.test.js.map