fix(terminal): keep default terminal tab names unique after closing tabs (#2718) (#2731)

This commit is contained in:
Serhii Dziupin
2026-08-07 09:09:32 +03:00
committed by GitHub
parent bc380e6e1b
commit 3fc136c95e
2 changed files with 57 additions and 2 deletions
@@ -123,3 +123,38 @@ describe('terminal state reconciliation', () => {
expect(useTerminalStore.getState().buffers.size).toBe(0);
});
});
describe('default terminal tab labels', () => {
afterEach(() => useTerminalStore.getState().clearAll());
const labels = () =>
useTerminalStore.getState().getDirectoryState('/repo')!.tabs.map((tab) => tab.label);
// Regression for https://github.com/openchamber/openchamber/issues/2718
test('does not reuse the number of a closed tab', () => {
const first = setup();
useTerminalStore.getState().createTab('/repo');
expect(labels()).toEqual(['Terminal', 'Terminal 2']);
useTerminalStore.getState().closeTab('/repo', first);
useTerminalStore.getState().createTab('/repo');
expect(labels()).toEqual(['Terminal 2', 'Terminal 3']);
});
test('numbers past a user-renamed "Terminal N" label instead of duplicating it', () => {
const first = setup();
useTerminalStore.getState().setTabLabel('/repo', first, 'Terminal 5');
useTerminalStore.getState().createTab('/repo');
expect(labels()).toEqual(['Terminal 5', 'Terminal 6']);
});
test('ignores custom labels and starts over at "Terminal" when no default-labeled tabs remain', () => {
const first = setup();
useTerminalStore.getState().setTabLabel('/repo', first, 'build');
useTerminalStore.getState().createTab('/repo');
expect(labels()).toEqual(['build', 'Terminal']);
});
});