UNPKG

@nerdo/code-reviewer

Version:

A web-based visual git diff tool for reviewing code changes between commits, branches, and tags

100 lines (99 loc) 4.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const FileTreeService_1 = require("../FileTreeService"); const FileChange_1 = require("../../entities/FileChange"); (0, vitest_1.describe)('FileTreeService', () => { (0, vitest_1.it)('should build file tree with changes', () => { const fileTreeService = new FileTreeService_1.FileTreeService(); const baseTree = makeTestBaseTree(); const changes = makeTestFileChanges(); const result = fileTreeService.buildFileTreeWithChanges(baseTree, changes); (0, vitest_1.expect)(result.children[0].children[0].change).toBeDefined(); (0, vitest_1.expect)(result.children[0].children[0].change?.changeType).toBe(FileChange_1.FileChangeType.Modified); }); (0, vitest_1.it)('should sort file tree with directories first', () => { const fileTreeService = new FileTreeService_1.FileTreeService(); const unsortedTree = makeTestUnsortedTree(); const sorted = fileTreeService.sortFileTree(unsortedTree); (0, vitest_1.expect)(sorted.children[0].name).toBe('a-dir'); (0, vitest_1.expect)(sorted.children[1].name).toBe('c-dir'); (0, vitest_1.expect)(sorted.children[2].name).toBe('a-file.txt'); (0, vitest_1.expect)(sorted.children[3].name).toBe('b-file.txt'); }); (0, vitest_1.it)('should recursively sort nested directories', () => { const fileTreeService = new FileTreeService_1.FileTreeService(); const nestedTree = makeTestNestedTree(); const sorted = fileTreeService.sortFileTree(nestedTree); (0, vitest_1.expect)(sorted.children[0].children[0].name).toBe('components'); (0, vitest_1.expect)(sorted.children[0].children[1].name).toBe('a.ts'); (0, vitest_1.expect)(sorted.children[0].children[2].name).toBe('z.ts'); }); function makeTestBaseTree() { return { name: '/', path: '/', type: 'directory', children: [ { name: 'src', path: 'src', type: 'directory', children: [ { name: 'index.ts', path: 'src/index.ts', type: 'file' }, { name: 'utils.ts', path: 'src/utils.ts', type: 'file' } ] }, { name: 'README.md', path: 'README.md', type: 'file' } ] }; } function makeTestFileChanges() { return [ { path: 'src/index.ts', changeType: FileChange_1.FileChangeType.Modified, additions: 10, deletions: 5 }, { path: 'src/new.ts', changeType: FileChange_1.FileChangeType.Added, additions: 20, deletions: 0 } ]; } function makeTestUnsortedTree() { return { name: '/', path: '/', type: 'directory', children: [ { name: 'b-file.txt', path: 'b-file.txt', type: 'file' }, { name: 'a-dir', path: 'a-dir', type: 'directory', children: [] }, { name: 'a-file.txt', path: 'a-file.txt', type: 'file' }, { name: 'c-dir', path: 'c-dir', type: 'directory', children: [] } ] }; } function makeTestNestedTree() { return { name: '/', path: '/', type: 'directory', children: [ { name: 'src', path: 'src', type: 'directory', children: [ { name: 'z.ts', path: 'src/z.ts', type: 'file' }, { name: 'components', path: 'src/components', type: 'directory', children: [] }, { name: 'a.ts', path: 'src/a.ts', type: 'file' } ] } ] }; } });