"use strict";
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 assert = require("assert");
const dirs = require("../../lib/dirs");
const configLoader = require("../../lib/config-loader");
const testRepo = require("../../lib/test-repo");
const path = require("path");
describe('test-repo module', function () {
    before(function () {
        configLoader.loadConfig({
            testRepoDir: path.join(dirs.appRootDir(), 'src', 'test', 'repo')
        });
    });
    it('should parse test repo', function () {
        return __awaiter(this, void 0, void 0, function* () {
            yield testRepo.parseTestRepo();
            assert(testRepo.getAllTestInfos().length > 0);
        });
    });
    it('test-repo.containsAsset positive test', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const asset1 = {
                name: 'Asset1',
                path: 'my/asset/path'
            };
            const asset2 = {
                name: 'Asset2',
                path: 'my/asset/path'
            };
            const assets = [asset1, asset2];
            assert(testRepo.containsAsset(assets, asset1));
            assert(testRepo.containsAsset(assets, asset2));
        });
    });
    it('test-repo.containsAsset negative test', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const asset1 = {
                name: 'Asset1',
                path: 'my/asset/path'
            };
            const asset2 = {
                name: 'Asset2',
                path: 'my/asset/path'
            };
            const assets = [asset1];
            assert(testRepo.containsAsset(assets, asset2) === false);
        });
    });
    it('test-repo.containsTag', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const test1 = {
                name: 'Test1',
                path: 'my/test/path',
                dataDriven: false,
                tags: []
            };
            const test2 = {
                name: 'Test2',
                path: 'my/test/path',
                dataDriven: false,
                tags: ['tag1']
            };
            const test3 = {
                name: 'Test3',
                path: 'my/test/path',
                dataDriven: false,
                tags: ['tag1', 'tag2']
            };
            assert(!testRepo.hasTag(test1, 'tag1'));
            assert(testRepo.hasTag(test2, 'tag1'));
            assert(testRepo.hasTag(test3, 'tag1'));
            assert(testRepo.hasTag(test3, 'tag2'));
        });
    });
    it('test-repo.getTestsByTagPredicate', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const testInfoCollection = [{
                    name: 'Test1',
                    path: 'my/test/path',
                    dataDriven: false,
                    tags: []
                }, {
                    name: 'Test2',
                    path: 'my/test/path',
                    dataDriven: false,
                    tags: ['Tag1']
                }, {
                    name: 'Test3',
                    path: 'my/test/path',
                    dataDriven: false,
                    tags: ['Tag1', 'Tag2']
                }, {
                    name: 'Test4',
                    path: 'my/test/path',
                    dataDriven: false,
                    tags: ['Tag1', 'Tag2', 'Tag3']
                }, {
                    name: 'Test5',
                    path: 'my/test/path',
                    dataDriven: false,
                    tags: ['Tag1', 'Tag3']
                }, {
                    name: 'Test6',
                    path: 'my/test/path',
                    dataDriven: false,
                    tags: ['tag-with_dashes']
                }];
            const testsWithTag1 = testRepo.getTestsByTagPredicate(testInfoCollection, 'Tag1');
            assert(testsWithTag1.length === 4);
            assert(testsWithTag1[0].name === 'Test2');
            assert(testsWithTag1[3].name === 'Test5');
            const testsWithTag1Not2 = testRepo.getTestsByTagPredicate(testInfoCollection, 'Tag1 && !Tag2');
            assert(testsWithTag1Not2.length === 2);
            assert(testsWithTag1Not2[0].name === 'Test2');
            assert(testsWithTag1Not2[1].name === 'Test5');
            const testsWithDashes = testRepo.getTestsByTagPredicate(testInfoCollection, 'tag-with_dashes');
            assert(testsWithDashes.length === 1);
            assert(testsWithDashes[0].name === 'Test6');
            const testsWithParens = testRepo.getTestsByTagPredicate(testInfoCollection, '(Tag1 && Tag2) || (Tag1 && Tag3)');
            assert(testsWithParens.length === 3);
            assert(testsWithParens[0].name === 'Test3');
            assert(testsWithParens[2].name === 'Test5');
        });
    });
    it('test-repo.getTestsForTemplate happy path', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const allTests = [{
                    name: 'Test1',
                    path: 'my/test/path',
                    dataDriven: false,
                    tags: []
                }, {
                    name: 'Test2',
                    path: 'my/test/path',
                    dataDriven: false,
                    tags: ['Tag1']
                }, {
                    name: 'Test3',
                    path: 'my/test/path',
                    dataDriven: false,
                    tags: ['Tag1', 'Tag2']
                }, {
                    name: 'Test4',
                    path: 'my/test/path',
                    dataDriven: false,
                    tags: ['Tag2', 'Tag3']
                }, {
                    name: 'Test5',
                    path: 'my/test/path',
                    dataDriven: false,
                    tags: ['Tag1', 'Tag2', 'Tag3']
                }, {
                    name: 'Test6',
                    path: 'my/test/path',
                    dataDriven: false,
                    tags: ['Tag1', 'Tag3']
                }];
            // Build and test template1
            const template1 = {
                name: 'template1',
                path: 'my/template/path',
                tests: [],
                includeTestsWithTags: 'Tag1 && !Tag2'
            };
            const testsFromTemplate1 = yield testRepo.getTestsForTemplate(allTests, template1);
            assert(testsFromTemplate1.length === 2);
            assert(testsFromTemplate1[0].name === 'Test2');
            assert(testsFromTemplate1[1].name === 'Test6');
            // Build and test template2
            const template2 = {
                name: 'template2',
                path: 'my/template/path',
                tests: [],
                includeTestsWithTags: 'Tag2 && !Tag1'
            };
            const testsFromTemplate2 = yield testRepo.getTestsForTemplate(allTests, template2);
            assert(testsFromTemplate2.length === 1);
            assert(testsFromTemplate2[0].name === 'Test4');
            testRepo.setAllTemplates([template1, template2]);
            // Build and test template3, made from template1 and template2
            const template3 = {
                tests: [],
                includeTestsFromTemplates: [
                    {
                        name: 'template1',
                        path: 'my/template/path'
                    }, {
                        name: 'template2',
                        path: 'my/template/path'
                    }
                ]
            };
            const testsFromTemplate3 = yield testRepo.getTestsForTemplate(allTests, template3);
            assert(testsFromTemplate3.length === 3);
            assert(testsFromTemplate3[0].name === 'Test2');
            assert(testsFromTemplate3[1].name === 'Test6');
            assert(testsFromTemplate3[2].name === 'Test4');
        });
    });
    it('test-repo.getTestsForTemplate with null template', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const allTests = [{
                    name: 'Test1',
                    path: 'my/test/path',
                    dataDriven: false,
                    tags: []
                }];
            // Build and test template1
            const allTemplates = [{
                    name: 'template1',
                    path: 'my/template/path',
                    tests: []
                }];
            testRepo.setAllTemplates(allTemplates);
            testRepo.setAllTestInfos(allTests);
            const testsFromTemplate = yield testRepo.getTestsForTemplate(allTests, null);
            assert(testsFromTemplate.length === 0);
        });
    });
    it('test-repo.excludeTestAssets', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const asset1 = {
                name: 'Asset1',
                path: 'my/asset/path'
            };
            const asset2 = {
                name: 'Asset2',
                path: 'my/asset/path'
            };
            const asset3 = {
                name: 'Asset3',
                path: 'my/asset/path'
            };
            const assets1 = [asset1, asset2, asset3];
            const assets2 = [asset1, asset3];
        });
    });
    it('test-repo.mergeTestAssets', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const asset1 = {
                name: 'Asset1',
                path: 'my/asset/path'
            };
            const asset2 = {
                name: 'Asset2',
                path: 'my/asset/path'
            };
            const asset3 = {
                name: 'Asset3',
                path: 'my/asset/path'
            };
            const assets1 = [asset1, asset2];
            const assets2 = [asset2, asset3];
            const mergedAssets = testRepo.mergeTestAssets(assets1, assets2);
            assert(mergedAssets.length === 3);
        });
    });
    it('test-repo.normalizeRelativePath', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const path1 = testRepo.normalizePartialPath('');
            const path2 = testRepo.normalizePartialPath(null);
            const path3 = testRepo.normalizePartialPath(' dir1/dir2 ');
            const path4 = testRepo.normalizePartialPath(' dir1\\dir2/ ');
            const path5 = testRepo.normalizePartialPath(' /dir1/dir2\\dir3/dir4 ');
            assert.strictEqual(path1, '');
            assert.strictEqual(path2, '');
            assert.strictEqual(path3, 'dir1/dir2');
            assert.strictEqual(path4, 'dir1/dir2');
            assert.strictEqual(path5, 'dir1/dir2/dir3/dir4');
        });
    });
});
//# sourceMappingURL=test-repo.test.js.map