mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-17 11:25:48 +02:00
Improved automated testing infrastructure
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { screen, waitFor } from '@testing-library/react';
|
||||
import { screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { render } from '../utils';
|
||||
import type { NotificationProvider } from '../../api/client';
|
||||
@@ -67,6 +67,9 @@ const createMockProvider = (
|
||||
daily_digest_enabled: false,
|
||||
daily_digest_time: null,
|
||||
printer_id: null,
|
||||
last_success: null,
|
||||
last_error: null,
|
||||
last_error_at: null,
|
||||
created_at: '2024-01-01T00:00:00Z',
|
||||
updated_at: '2024-01-01T00:00:00Z',
|
||||
...overrides,
|
||||
|
||||
@@ -38,8 +38,6 @@ const createMockPlug = (overrides: Partial<SmartPlug> = {}): SmartPlug => ({
|
||||
last_state: 'ON',
|
||||
last_checked: null,
|
||||
auto_off_executed: false,
|
||||
auto_off_pending: false,
|
||||
auto_off_pending_since: null,
|
||||
created_at: '2024-01-01T00:00:00Z',
|
||||
updated_at: '2024-01-01T00:00:00Z',
|
||||
...overrides,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { renderHook, act, waitFor } from '@testing-library/react';
|
||||
import { waitFor } from '@testing-library/react';
|
||||
|
||||
// Mock WebSocket
|
||||
class MockWebSocket {
|
||||
@@ -32,7 +32,7 @@ class MockWebSocket {
|
||||
}, 10);
|
||||
}
|
||||
|
||||
send(data: string) {
|
||||
send(_data: string) {
|
||||
// Mock send
|
||||
}
|
||||
|
||||
|
||||
@@ -103,9 +103,10 @@ export const handlers = [
|
||||
|
||||
http.post('/api/v1/smart-plugs/', async ({ request }) => {
|
||||
const body = (await request.json()) as Record<string, unknown>;
|
||||
const { id: _id, ...baseData } = mockSmartPlugs[0];
|
||||
const newPlug = {
|
||||
id: mockSmartPlugs.length + 1,
|
||||
...mockSmartPlugs[0],
|
||||
...baseData,
|
||||
...body,
|
||||
};
|
||||
return HttpResponse.json(newPlug);
|
||||
@@ -171,9 +172,10 @@ export const handlers = [
|
||||
|
||||
http.post('/api/v1/notifications/', async ({ request }) => {
|
||||
const body = (await request.json()) as Record<string, unknown>;
|
||||
const { id: _id, ...baseData } = mockNotificationProviders[0];
|
||||
const newProvider = {
|
||||
id: mockNotificationProviders.length + 1,
|
||||
...mockNotificationProviders[0],
|
||||
...baseData,
|
||||
...body,
|
||||
};
|
||||
return HttpResponse.json(newProvider);
|
||||
|
||||
@@ -63,7 +63,9 @@ class MockWebSocket {
|
||||
onmessage: ((event: MessageEvent) => void) | null = null;
|
||||
onerror: ((event: Event) => void) | null = null;
|
||||
|
||||
constructor(public url: string) {
|
||||
url: string;
|
||||
constructor(url: string) {
|
||||
this.url = url;
|
||||
setTimeout(() => this.onopen?.(new Event('open')), 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { render, RenderOptions } from '@testing-library/react';
|
||||
import { render } from '@testing-library/react';
|
||||
import type { RenderOptions } from '@testing-library/react';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { BrowserRouter } from 'react-router-dom';
|
||||
import { ThemeProvider } from '../contexts/ThemeContext';
|
||||
|
||||
Reference in New Issue
Block a user