Files
feuerwerk/tests/editor/documents.test.ts
T

66 lines
2.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'vitest';
import { closeDocument, openDocument, replaceDocument } from '../../src/editor/documents';
import { tabRowLayout } from '../../src/editor/tabRow';
const row = (docs: string[], active: string | null) => ({ docs, active });
describe('open documents', () => {
it('puts a new document right of the one showing', () => {
expect(openDocument(row(['a', 'b', 'c'], 'a'), 'x')).toEqual(row(['a', 'x', 'b', 'c'], 'x'));
});
it('puts it last while a fixed tab is showing', () => {
expect(openDocument(row(['a', 'b'], null), 'x')).toEqual(row(['a', 'b', 'x'], 'x'));
expect(openDocument(row([], null), 'x')).toEqual(row(['x'], 'x'));
});
it('only brings an open document up – one tab per document', () => {
expect(openDocument(row(['a', 'b', 'c'], 'c'), 'a')).toEqual(row(['a', 'b', 'c'], 'a'));
});
it('shows the left neighbour after the one showing closes', () => {
expect(closeDocument(row(['a', 'b', 'c'], 'b'), 'b')).toEqual(row(['a', 'c'], 'a'));
});
it('shows the right one when the first closes, and nothing when the last goes', () => {
expect(closeDocument(row(['a', 'b'], 'a'), 'a')).toEqual(row(['b'], 'b'));
expect(closeDocument(row(['a'], 'a'), 'a')).toEqual(row([], null));
});
it('keeps what is showing when another tab closes', () => {
expect(closeDocument(row(['a', 'b', 'c'], 'c'), 'a')).toEqual(row(['b', 'c'], 'c'));
expect(closeDocument(row(['a', 'b'], null), 'b')).toEqual(row(['a'], null));
});
it('ignores a document that is not open', () => {
const before = row(['a'], 'a');
expect(closeDocument(before, 'x')).toBe(before);
});
it('lets a tab go on to another document in its place', () => {
expect(replaceDocument(row(['a', 'b', 'c'], 'b'), 'b', 'x')).toEqual(row(['a', 'x', 'c'], 'x'));
});
it('drops the other tab of a document it goes on to', () => {
expect(replaceDocument(row(['a', 'b', 'c'], 'a'), 'a', 'c')).toEqual(row(['c', 'b'], 'c'));
});
it('leaves the row alone for a tab that is not open', () => {
const before = row(['a'], 'a');
expect(replaceDocument(before, 'x', 'y')).toBe(before);
expect(replaceDocument(before, 'a', 'a')).toBe(before);
});
});
describe('tab row without an active tab', () => {
it('fills the row in order when a kind with no document is showing', () => {
const tabs = [
{ key: 'a', width: 50 },
{ key: 'b', width: 50 },
{ key: 'c', width: 50 },
];
const layout = tabRowLayout({ tabs, available: 132, gap: 2, overflowWidth: 28, active: null });
expect(layout).toEqual({ shown: ['a', 'b'], hidden: ['c'] });
});
});