"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
const internal_1 = require("../../../internal");
const CdmCollectionHelperFunctions_1 = require("./CdmCollectionHelperFunctions");
describe('Cdm/CdmCollection/CdmFolderCollection', () => {
    it('TestFolderCollectionAdd', () => {
        const manifest = CdmCollectionHelperFunctions_1.generateManifest();
        const parentFolder = new internal_1.CdmFolderDefinition(manifest.ctx, 'parentFolder');
        parentFolder.namespace = 'theNamespace';
        parentFolder.folderPath = 'parentFolderPath/';
        const childFolders = parentFolder.childFolders;
        const childFolder = new internal_1.CdmFolderDefinition(manifest.ctx, 'childFolder1');
        expect(childFolders.length)
            .toEqual(0);
        const addedChildFolder = childFolders.push(childFolder);
        expect(childFolders.length)
            .toEqual(1);
        expect(childFolders.allItems[0])
            .toEqual(childFolder);
        expect(addedChildFolder)
            .toEqual(childFolder);
        expect(childFolder.ctx)
            .toEqual(manifest.ctx);
        expect(childFolder.name)
            .toEqual('childFolder1');
        expect(childFolder.owner)
            .toEqual(parentFolder);
        expect(childFolder.namespace)
            .toEqual('theNamespace');
        expect(childFolder.folderPath)
            .toEqual(`${parentFolder.folderPath}${childFolder.name}/`);
    });
    it('TestFolderCollectionInsert', () => {
        const manifest = CdmCollectionHelperFunctions_1.generateManifest();
        const parentFolder = new internal_1.CdmFolderDefinition(manifest.ctx, 'parentFolder');
        parentFolder.inDocument = manifest;
        parentFolder.namespace = 'namespace';
        parentFolder.folderPath = 'parentFolderPath/';
        const childFolders = parentFolder.childFolders;
        const childFolder = new internal_1.CdmFolderDefinition(manifest.ctx, 'childFolder1');
        const child1 = childFolders.push('child1');
        const child2 = childFolders.push('child2');
        manifest.isDirty = false;
        childFolders.insert(1, childFolder);
        expect(childFolders.length)
            .toEqual(3);
        expect(manifest.isDirty)
            .toBeTruthy();
        expect(childFolders.allItems[0])
            .toEqual(child1);
        expect(childFolders.allItems[1])
            .toEqual(childFolder);
        expect(childFolders.allItems[2])
            .toEqual(child2);
        expect(childFolder.ctx)
            .toEqual(manifest.ctx);
        expect(childFolder.name)
            .toEqual('childFolder1');
        expect(childFolder.owner)
            .toEqual(parentFolder);
        expect(childFolder.namespace)
            .toEqual('namespace');
        expect(childFolder.folderPath)
            .toEqual(`${parentFolder.folderPath}${childFolder.name}/`);
    });
    it('TestFolderCollectionAddWithNameParameter', () => {
        const manifest = CdmCollectionHelperFunctions_1.generateManifest();
        const parentFolder = new internal_1.CdmFolderDefinition(manifest.ctx, 'parentFolder');
        parentFolder.namespace = 'namespace';
        parentFolder.folderPath = 'parentFolderPath/';
        const childFolders = parentFolder.childFolders;
        expect(childFolders.length)
            .toEqual(0);
        const childFolder = childFolders.push('childFolder1');
        expect(childFolders.length)
            .toEqual(1);
        expect(childFolders.allItems[0])
            .toEqual(childFolder);
        expect(childFolder.ctx)
            .toEqual(manifest.ctx);
        expect(childFolder.name)
            .toEqual('childFolder1');
        expect(childFolder.owner)
            .toEqual(parentFolder);
        expect(childFolder.namespace)
            .toEqual('namespace');
        expect(childFolder.folderPath)
            .toEqual(`${parentFolder.folderPath}${childFolder.name}/`);
    });
    it('TestFolderCollectionAddRange', () => {
        const manifest = CdmCollectionHelperFunctions_1.generateManifest();
        const parentFolder = new internal_1.CdmFolderDefinition(manifest.ctx, 'parentFolder');
        parentFolder.namespace = 'namespace';
        parentFolder.folderPath = 'parentFolderPath/';
        const childFolders = parentFolder.childFolders;
        const childFolder = new internal_1.CdmFolderDefinition(manifest.ctx, 'childFolder1');
        const childFolder2 = new internal_1.CdmFolderDefinition(manifest.ctx, 'childFolder2');
        const childList = [childFolder, childFolder2];
        expect(childFolders.length)
            .toEqual(0);
        childFolders.concat(childList);
        expect(childFolders.length)
            .toEqual(2);
        expect(childFolders.allItems[0])
            .toEqual(childFolder);
        expect(childFolder.ctx)
            .toEqual(manifest.ctx);
        expect(childFolder.name)
            .toEqual('childFolder1');
        expect(childFolder.owner)
            .toEqual(parentFolder);
        expect(childFolder.namespace)
            .toEqual('namespace');
        expect(childFolder.folderPath)
            .toEqual(`${parentFolder.folderPath}${childFolder.name}/`);
    });
    it('TestFolderCollectionRemove', () => {
        const manifest = CdmCollectionHelperFunctions_1.generateManifest();
        const parentFolder = new internal_1.CdmFolderDefinition(manifest.ctx, 'parentFolder');
        parentFolder.namespace = 'namespace';
        parentFolder.folderPath = 'parentFolderPath/';
        const childFolders = parentFolder.childFolders;
        const childFolder = new internal_1.CdmFolderDefinition(manifest.ctx, 'childFolder1');
        expect(childFolders.length)
            .toEqual(0);
        childFolders.push(childFolder);
        expect(childFolders.length)
            .toEqual(1);
        childFolders.remove(childFolder);
        expect(childFolders.length)
            .toEqual(0);
    });
});
//# sourceMappingURL=CdmFolderCollection.test.js.map