40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { describe, test, expect, afterEach, beforeEach } from 'vitest';
|
|
import React from 'react';
|
|
import { renderEditorHarness, EditorHarness } from '../../test-utils/editorHarness';
|
|
import { PageProvider } from '../../state/PageContext';
|
|
import { LeftPanel } from './LeftPanel';
|
|
|
|
let h: EditorHarness | null = null;
|
|
beforeEach(() => { window.localStorage.clear(); });
|
|
afterEach(() => { h?.unmount(); h = null; });
|
|
|
|
function mountPanel(): EditorHarness {
|
|
const hh = renderEditorHarness();
|
|
hh.mountChild(<PageProvider><LeftPanel /></PageProvider>);
|
|
return hh;
|
|
}
|
|
const activeTab = (hh: EditorHarness) => hh.container.querySelector('.panel-tab.active')?.textContent;
|
|
|
|
describe('LeftPanel remembers its tab', () => {
|
|
test('defaults to Blocks', () => {
|
|
h = mountPanel();
|
|
expect(activeTab(h)).toBe('Blocks');
|
|
});
|
|
|
|
test('clicking Pages then remounting shows Pages', () => {
|
|
h = mountPanel();
|
|
const pages = Array.from(h.container.querySelectorAll('.panel-tab')).find((b) => b.textContent === 'Pages') as HTMLElement;
|
|
h.act(() => { pages.click(); });
|
|
expect(activeTab(h)).toBe('Pages');
|
|
h.unmount();
|
|
h = mountPanel();
|
|
expect(activeTab(h)).toBe('Pages');
|
|
});
|
|
|
|
test('an unknown stored tab falls back to Blocks', () => {
|
|
window.localStorage.setItem('wsb:leftTab', JSON.stringify('bogus'));
|
|
h = mountPanel();
|
|
expect(activeTab(h)).toBe('Blocks');
|
|
});
|
|
});
|