Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions apps/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<meta
name="theme-color"
content="#4f7a90"
/>
<link
rel="manifest"
href="/manifest.webmanifest"
/>
<title>ShotLab</title>
</head>
<body>
<div id="root"></div>
<script
type="module"
src="/src/main.tsx"
></script>
</body>
</html>
37 changes: 37 additions & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@shotlab/web",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"build": "vite build",
"dev": "vite --host 0.0.0.0",
"format": "oxfmt",
"format:check": "oxfmt --check",
"lint": "oxlint -f default",
"lint:ci": "oxlint -f github",
"test": "vitest run --passWithNoTests",
"test:watch": "vitest"
},
"dependencies": {
"@shotlab/meticulous-client": "workspace:*",
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.1",
"@mui/icons-material": "^9.1.1",
"@mui/material": "^9.1.2",
"@mui/system": "^9.1.2",
"@mui/x-charts": "^9.7.0",
"react": "^19.2.7",
"react-dom": "^19.2.7"
},
"devDependencies": {
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.2",
"@types/react": "^19",
"@types/react-dom": "^19",
"@vitejs/plugin-react": "^6.0.3",
"jsdom": "^29.1.1",
"vite": "^8.1.0"
}
}
24 changes: 24 additions & 0 deletions apps/web/public/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions apps/web/public/manifest.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "ShotLab",
"short_name": "ShotLab",
"display": "standalone",
"background_color": "#edf1f4",
"theme_color": "#4f7a90",
"start_url": "/",
"icons": [
{
"src": "/icon.svg",
"sizes": "any",
"type": "image/svg+xml",
"purpose": "any"
}
]
}
5 changes: 5 additions & 0 deletions apps/web/public/sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
self.addEventListener('install', () => self.skipWaiting());
self.addEventListener('activate', (event) =>
event.waitUntil(self.clients.claim()),
);
self.addEventListener('fetch', () => {});
77 changes: 77 additions & 0 deletions apps/web/src/app.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// @vitest-environment jsdom

import { render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';

const mocks = vi.hoisted(() => {
function createDeferred<T>() {
let resolve!: (value: T) => void;
let reject!: (reason?: unknown) => void;
const promise = new Promise<T>((nextResolve, nextReject) => {
resolve = nextResolve;
reject = nextReject;
});

return { promise, reject, resolve };
}

const deferreds = {
history: createDeferred<{ history: [] }>(),
lastProfile: createDeferred<{ title: string }>(),
machine: createDeferred<{
state: string;
water_temperature: number;
weight: number;
}>(),
settings: createDeferred<{ preheat: boolean }>(),
};

const client = {
getHistory: vi.fn(() => deferreds.history.promise),
getLastProfile: vi.fn(() => deferreds.lastProfile.promise),
getMachine: vi.fn(() => deferreds.machine.promise),
getSettings: vi.fn(() => deferreds.settings.promise),
};

return { client, deferreds };
});

vi.mock('./config', () => ({
readAppConfig: () => ({
meticulousBaseUrl: 'http://machine.local:8080',
}),
}));

vi.mock('./lib/create-dashboard-client', () => ({
createDashboardClient: () => mocks.client,
}));

import { App } from './app';

describe('App', () => {
it('renders machine fields before the other requests finish', async () => {
render(<App />);

mocks.deferreds.machine.resolve({
state: 'Idle',
water_temperature: 93.4,
weight: 0.2,
});

await screen.findByText('93.4 C');
expect(screen.getAllByText('Idle')).toHaveLength(2);
expect(screen.getByText('0.2 g')).toBeDefined();
expect(screen.queryByText('Bloom')).toBeNull();
expect(screen.queryByText('Off')).toBeNull();

mocks.deferreds.lastProfile.resolve({ title: 'Bloom' });
await screen.findByText('Bloom');
expect(screen.queryByText('Off')).toBeNull();

mocks.deferreds.settings.resolve({ preheat: false });
await screen.findByText('Off');

mocks.deferreds.history.resolve({ history: [] });
Comment thread
coderabbitai[bot] marked this conversation as resolved.
await screen.findByText('No history rows have been mapped yet.');
});
});
Loading