This commit is contained in:
35
test/group-by-dir.test.ts
Normal file
35
test/group-by-dir.test.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { groupByDir } from '../src/renderer/src/components'
|
||||
import type { Change } from '../src/renderer/src/types'
|
||||
|
||||
function change(path: string): Change {
|
||||
return { path, status: 'M', add: 1, del: 0, deleted: false, staged: false, id: path }
|
||||
}
|
||||
|
||||
describe('groupByDir', () => {
|
||||
it('gives one group per folder when git returns the folder in separated runs', () => {
|
||||
const groups = groupByDir([
|
||||
change('tests/Feature/AlphaTest.php'),
|
||||
change('app/Models/User.php'),
|
||||
change('tests/Feature/BetaTest.php'),
|
||||
])
|
||||
expect(groups.map((g) => g.dir)).toEqual(['tests/Feature', 'app/Models'])
|
||||
expect(groups[0].rows.map((r) => r.path)).toEqual([
|
||||
'tests/Feature/AlphaTest.php',
|
||||
'tests/Feature/BetaTest.php',
|
||||
])
|
||||
})
|
||||
|
||||
it('keeps every row, so the keyboard cursor walks the full list', () => {
|
||||
const list = ['a/one.ts', 'b/two.ts', 'a/three.ts', 'four.ts'].map(change)
|
||||
const flat = groupByDir(list).flatMap((g) => g.rows)
|
||||
expect(flat).toHaveLength(list.length)
|
||||
expect(new Set(flat.map((r) => r.id)).size).toBe(list.length)
|
||||
})
|
||||
|
||||
it('puts a project-root file in the empty-string group', () => {
|
||||
expect(groupByDir([change('README.md')])).toEqual([
|
||||
{ dir: '', rows: [change('README.md')] },
|
||||
])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user