|
1 | 1 | import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' |
2 | 2 | import { QueryClient, onlineManager } from '@tanstack/query-core' |
3 | | -import { render } from '@solidjs/testing-library' |
| 3 | +import { fireEvent, render } from '@solidjs/testing-library' |
4 | 4 | import { createLocalStorage } from '@solid-primitives/storage' |
5 | 5 | import { Devtools } from '../Devtools' |
6 | 6 | import { PiPProvider, QueryDevtoolsContext, ThemeContext } from '../contexts' |
@@ -186,4 +186,62 @@ describe('Devtools', () => { |
186 | 186 | ).not.toBeInTheDocument() |
187 | 187 | }) |
188 | 188 | }) |
| 189 | + |
| 190 | + describe('open and close', () => { |
| 191 | + it('should render the panel when the open button is clicked', () => { |
| 192 | + const rendered = renderDevtools() |
| 193 | + |
| 194 | + fireEvent.click(rendered.getByLabelText('Open Tanstack query devtools')) |
| 195 | + |
| 196 | + expect( |
| 197 | + rendered.getByLabelText('Tanstack query devtools'), |
| 198 | + ).toBeInTheDocument() |
| 199 | + }) |
| 200 | + |
| 201 | + it('should hide the open button when the panel is open', () => { |
| 202 | + const rendered = renderDevtools() |
| 203 | + |
| 204 | + fireEvent.click(rendered.getByLabelText('Open Tanstack query devtools')) |
| 205 | + |
| 206 | + expect( |
| 207 | + rendered.queryByLabelText('Open Tanstack query devtools'), |
| 208 | + ).not.toBeInTheDocument() |
| 209 | + }) |
| 210 | + |
| 211 | + it('should hide the panel when the close button is clicked', () => { |
| 212 | + const rendered = renderDevtools({ initialIsOpen: true }) |
| 213 | + |
| 214 | + fireEvent.click(rendered.getByLabelText('Close tanstack query devtools')) |
| 215 | + |
| 216 | + expect( |
| 217 | + rendered.queryByLabelText('Tanstack query devtools'), |
| 218 | + ).not.toBeInTheDocument() |
| 219 | + }) |
| 220 | + |
| 221 | + it('should render the open button after the panel is closed', () => { |
| 222 | + const rendered = renderDevtools({ initialIsOpen: true }) |
| 223 | + |
| 224 | + fireEvent.click(rendered.getByLabelText('Close tanstack query devtools')) |
| 225 | + |
| 226 | + expect( |
| 227 | + rendered.getByLabelText('Open Tanstack query devtools'), |
| 228 | + ).toBeInTheDocument() |
| 229 | + }) |
| 230 | + |
| 231 | + it('should persist "open" as "true" to "localStorage" when the open button is clicked', () => { |
| 232 | + const rendered = renderDevtools() |
| 233 | + |
| 234 | + fireEvent.click(rendered.getByLabelText('Open Tanstack query devtools')) |
| 235 | + |
| 236 | + expect(localStorage.getItem('TanstackQueryDevtools.open')).toBe('true') |
| 237 | + }) |
| 238 | + |
| 239 | + it('should persist "open" as "false" to "localStorage" when the close button is clicked', () => { |
| 240 | + const rendered = renderDevtools({ initialIsOpen: true }) |
| 241 | + |
| 242 | + fireEvent.click(rendered.getByLabelText('Close tanstack query devtools')) |
| 243 | + |
| 244 | + expect(localStorage.getItem('TanstackQueryDevtools.open')).toBe('false') |
| 245 | + }) |
| 246 | + }) |
189 | 247 | }) |
0 commit comments