From 1971749449cce3bf15c76a4d2facbfcf3933fd43 Mon Sep 17 00:00:00 2001 From: Himself65 Date: Fri, 9 Jun 2023 02:00:09 +0800 Subject: [PATCH] test: add test cases for page setting atom (#2736) --- apps/web/src/atoms/__tests__/atom.spec.ts | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/apps/web/src/atoms/__tests__/atom.spec.ts b/apps/web/src/atoms/__tests__/atom.spec.ts index 829ad0d6d1..9099e78b53 100644 --- a/apps/web/src/atoms/__tests__/atom.spec.ts +++ b/apps/web/src/atoms/__tests__/atom.spec.ts @@ -20,8 +20,45 @@ import { createStore } from 'jotai'; import { describe, expect, test } from 'vitest'; import { WorkspaceAdapters } from '../../adapters/workspace'; +import { + pageSettingFamily, + pageSettingsAtom, + recentPageSettingsAtom, +} from '../index'; import { rootCurrentWorkspaceAtom } from '../root'; +describe('page mode atom', () => { + test('basic', () => { + const store = createStore(); + const page0SettingAtom = pageSettingFamily('page0'); + store.set(page0SettingAtom, { + mode: 'page', + }); + + expect(store.get(pageSettingsAtom)).toEqual({ + page0: { + mode: 'page', + }, + }); + + expect(store.get(recentPageSettingsAtom)).toEqual([ + { + id: 'page0', + mode: 'page', + }, + ]); + + const page1SettingAtom = pageSettingFamily('page1'); + store.set(page1SettingAtom, { + mode: 'edgeless', + }); + expect(store.get(recentPageSettingsAtom)).toEqual([ + { id: 'page1', mode: 'edgeless' }, + { id: 'page0', mode: 'page' }, + ]); + }); +}); + describe('currentWorkspace atom', () => { test('should be defined', async () => { const store = createStore();