"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 internal_1 = require("../../../internal");
const Persistence_1 = require("../../../Persistence");
const Storage_1 = require("../../../Storage");
// tslint:disable-next-line: max-func-body-length
describe('Persistence.CdmFolder.TypeAttribute', () => {
    /**
     * Testing that 'is.localized.describedAs' trait with a table of three entries (en, rs and cn)
     *  is fully preserved when running ModelJson TypeAttributePersistence ToData.
     */
    it('TestModelJsonToDataTypeAttribute', (done) => __awaiter(void 0, void 0, void 0, function* () {
        const corpus = new internal_1.CdmCorpusDefinition();
        corpus.storage.mount('local', new Storage_1.LocalAdapter('C:\\Root\\Path'));
        corpus.storage.defaultNamespace = 'local';
        const cdmTypeAttributeDefinition = corpus.MakeObject(internal_1.cdmObjectType.typeAttributeDef, 'TestSavingTraitAttribute', false);
        const englishConstantsList = ['en', 'Some description in English language'];
        const serbianConstantsList = ['sr', 'Opis na srpskom jeziku'];
        const chineseConstantsList = ['cn', '一些中文描述'];
        const listOfConstLists = [englishConstantsList, serbianConstantsList, chineseConstantsList];
        const constEntDef = corpus.MakeObject(internal_1.cdmObjectType.constantEntityDef, 'localizedDescriptions', false);
        constEntDef.constantValues = listOfConstLists;
        constEntDef.entityShape = corpus.MakeRef(internal_1.cdmObjectType.entityRef, 'localizedTable', true);
        const traitReference2 = corpus.MakeObject(internal_1.cdmObjectType.traitRef, 'is.localized.describedAs', false);
        traitReference2.arguments.push('localizedDisplayText', corpus.MakeRef(internal_1.cdmObjectType.entityRef, constEntDef, true));
        cdmTypeAttributeDefinition.appliedTraits.push(traitReference2);
        // tslint:disable-next-line: await-promise
        const result = yield Persistence_1.PersistenceLayer.toData(cdmTypeAttributeDefinition, undefined, undefined, Persistence_1.PersistenceLayer.modelJson);
        expect(result['cdm:traits'])
            .toBeTruthy();
        const argument = result['cdm:traits'][0].arguments[0];
        const constantValues = argument.value.entityReference.constantValues;
        expect(constantValues[0][0])
            .toBe('en');
        expect(constantValues[0][1])
            .toBe('Some description in English language');
        expect(constantValues[1][0])
            .toBe('sr');
        expect(constantValues[1][1])
            .toBe('Opis na srpskom jeziku');
        expect(constantValues[2][0])
            .toBe('cn');
        expect(constantValues[2][1])
            .toBe('一些中文描述');
        done();
    }));
});
//# sourceMappingURL=TypeAttribute.test.js.map