From 07e883ca12ff1483e7a771fb556da018e414bd9d Mon Sep 17 00:00:00 2001 From: Michael Sweeney Date: Sat, 26 Oct 2024 00:36:50 -0700 Subject: [PATCH] added more tests for useSnapshot --- tests/proxyMap.test.tsx | 104 ++++++++++++++++++++++++++++++++++++++++ tests/proxySet.test.tsx | 104 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+) diff --git a/tests/proxyMap.test.tsx b/tests/proxyMap.test.tsx index b11a7a72..44ccb453 100644 --- a/tests/proxyMap.test.tsx +++ b/tests/proxyMap.test.tsx @@ -466,6 +466,110 @@ describe('ui updates - useSnapshot', async () => { }) }) + it('should update ui when calling has before and after settiing multile keys and deleting a single one (first item)', async () => { + const state = proxyMap() + const TestComponent = () => { + const snap = useSnapshot(state) + + return ( + <> +

has key: {`${snap.has('key')}`}

+

has key2: {`${snap.has('key2')}`}

+ + + + ) + } + + const { getByText } = render( + + + , + ) + + await waitFor(() => { + getByText('has key: false') + getByText('has key2: false') + }) + + fireEvent.click(getByText('set keys')) + await waitFor(() => { + getByText('has key: true') + getByText('has key2: true') + }) + + fireEvent.click(getByText('delete keys')) + await waitFor(() => { + getByText('has key: false') + getByText('has key2: true') + }) + }) + + it('should update ui when calling has before and after settiing multile keys and deleting a single one (first item)', async () => { + const state = proxyMap() + const TestComponent = () => { + const snap = useSnapshot(state) + + return ( + <> +

has key: {`${snap.has('key')}`}

+

has key2: {`${snap.has('key2')}`}

+ + + + ) + } + + const { getByText } = render( + + + , + ) + + await waitFor(() => { + getByText('has key: false') + getByText('has key2: false') + }) + + fireEvent.click(getByText('set keys')) + await waitFor(() => { + getByText('has key: true') + getByText('has key2: true') + }) + + fireEvent.click(getByText('delete keys')) + await waitFor(() => { + getByText('has key: true') + getByText('has key2: false') + }) + }) + it('should update ui when clearing the map', async () => { const state = proxyMap() const TestComponent = () => { diff --git a/tests/proxySet.test.tsx b/tests/proxySet.test.tsx index a5c9b07e..f9b4cd53 100644 --- a/tests/proxySet.test.tsx +++ b/tests/proxySet.test.tsx @@ -462,6 +462,110 @@ describe('ui updates - useSnapshot', async () => { }) }) + it('should update ui when calling has before and after settiing multiple values and deleting a single one (first item)', async () => { + const state = proxySet() + const TestComponent = () => { + const snap = useSnapshot(state) + + return ( + <> +

has value: {`${snap.has('value')}`}

+

has value2: {`${snap.has('value2')}`}

+ + + + ) + } + + const { getByText } = render( + + + , + ) + + await waitFor(() => { + getByText('has value: false') + getByText('has value2: false') + }) + + fireEvent.click(getByText('add values')) + await waitFor(() => { + getByText('has value: true') + getByText('has value2: true') + }) + + fireEvent.click(getByText('delete values')) + await waitFor(() => { + getByText('has value: false') + getByText('has value2: true') + }) + }) + + it('should update ui when calling has before and after settiing multiple values and deleting a single one (second item)', async () => { + const state = proxySet() + const TestComponent = () => { + const snap = useSnapshot(state) + + return ( + <> +

has value: {`${snap.has('value')}`}

+

has value2: {`${snap.has('value2')}`}

+ + + + ) + } + + const { getByText } = render( + + + , + ) + + await waitFor(() => { + getByText('has value: false') + getByText('has value2: false') + }) + + fireEvent.click(getByText('add values')) + await waitFor(() => { + getByText('has value: true') + getByText('has value2: true') + }) + + fireEvent.click(getByText('delete values')) + await waitFor(() => { + getByText('has value: true') + getByText('has value2: false') + }) + }) + it('should update ui when clearing the set', async () => { const state = proxySet() const TestComponent = () => {