aboutsummaryrefslogtreecommitdiffstats
path: root/frontend-vanilla/src/store.test.ts
diff options
context:
space:
mode:
authorAdam Mathes <adam@adammathes.com>2026-02-16 11:28:01 -0800
committerAdam Mathes <adam@adammathes.com>2026-02-16 11:28:01 -0800
commit52ea335714f2b495b92f87636c269b73b4067066 (patch)
tree56ba60da3189fabe1a5796214956e2c466a5c92e /frontend-vanilla/src/store.test.ts
parentcd4e599a6d7a13e08841d63257dca6d355eb2bb8 (diff)
downloadneko-52ea335714f2b495b92f87636c269b73b4067066.tar.gz
neko-52ea335714f2b495b92f87636c269b73b4067066.tar.bz2
neko-52ea335714f2b495b92f87636c269b73b4067066.zip
v3: persist sidebar state via cookie, default closed on tablet/mobile
Sidebar open/close state is now saved to a cookie (neko_sidebar) so it persists across page reloads. On first visit without a cookie, the sidebar defaults to closed on tablet and mobile (<=1024px viewport) and open on desktop. Removes the auto-open-on-resize behavior that was overriding user preference. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'frontend-vanilla/src/store.test.ts')
-rw-r--r--frontend-vanilla/src/store.test.ts42
1 files changed, 41 insertions, 1 deletions
diff --git a/frontend-vanilla/src/store.test.ts b/frontend-vanilla/src/store.test.ts
index 33deb7f..799db83 100644
--- a/frontend-vanilla/src/store.test.ts
+++ b/frontend-vanilla/src/store.test.ts
@@ -1,4 +1,4 @@
-import { describe, it, expect, vi } from 'vitest';
+import { describe, it, expect, vi, beforeEach } from 'vitest';
import { Store } from './store';
describe('Store', () => {
@@ -105,4 +105,44 @@ describe('Store', () => {
expect(localStorage.getItem('neko-font-theme')).toBe('serif');
expect(callback).toHaveBeenCalled();
});
+
+ describe('sidebar cookie persistence', () => {
+ beforeEach(() => {
+ // Clear sidebar cookie
+ document.cookie = 'neko_sidebar=; path=/; max-age=0';
+ });
+
+ it('should persist sidebar state to cookie', () => {
+ const store = new Store();
+ store.setSidebarVisible(false);
+ expect(document.cookie).toContain('neko_sidebar=0');
+
+ store.setSidebarVisible(true);
+ expect(document.cookie).toContain('neko_sidebar=1');
+ });
+
+ it('should read sidebar state from cookie on init', () => {
+ document.cookie = 'neko_sidebar=1; path=/';
+ const store = new Store();
+ expect(store.sidebarVisible).toBe(true);
+
+ document.cookie = 'neko_sidebar=0; path=/';
+ const store2 = new Store();
+ expect(store2.sidebarVisible).toBe(false);
+ });
+
+ it('should default to closed on tablet/mobile when no cookie', () => {
+ // jsdom defaults innerWidth to 0, which is <= 1024
+ const store = new Store();
+ expect(store.sidebarVisible).toBe(false);
+ });
+
+ it('should emit sidebar-toggle when toggling', () => {
+ const store = new Store();
+ const callback = vi.fn();
+ store.on('sidebar-toggle', callback);
+ store.toggleSidebar();
+ expect(callback).toHaveBeenCalled();
+ });
+ });
});