Skip to content

Commit 3eb27cb

Browse files
feat: Auto-seed data on startup and add reset page
- start.sh now automatically seeds test data after backend starts - Calls /api/dev/reseed endpoint which populates 'default' company - App already defaults to 'default' company via ApiClient - Added /reset-app page for easy localStorage reset during testing - Users no longer need to manually trigger data seeding
1 parent a7e2d73 commit 3eb27cb

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
@page "/reset-app"
2+
@inject IJSRuntime JS
3+
@inject NavigationManager Navigation
4+
5+
<div style="max-width: 600px; margin: 40px auto; padding: 20px; text-align: center;">
6+
<h2 style="margin-bottom: 24px;">🔧 Reset App (Debug Only)</h2>
7+
8+
@if (!_isReset)
9+
{
10+
<p style="margin-bottom: 32px;">This will clear all localStorage data and reset the app to onboarding state.</p>
11+
12+
<button class="btn" @onclick="ResetApp" style="background: #ff6b6b; color: white; padding: 12px 24px;">
13+
Reset App & Reload
14+
</button>
15+
16+
<div style="margin-top: 20px;">
17+
<a href="/" style="color: var(--text-secondary);">← Back to Home</a>
18+
</div>
19+
}
20+
else
21+
{
22+
<p style="color: #4CAF50; font-size: 1.2em;">✅ App reset! Reloading...</p>
23+
}
24+
</div>
25+
26+
@code {
27+
private bool _isReset = false;
28+
29+
private async Task ResetApp()
30+
{
31+
try
32+
{
33+
// Clear all localStorage
34+
await JS.InvokeVoidAsync("localStorage.clear");
35+
36+
_isReset = true;
37+
StateHasChanged();
38+
39+
// Reload the page
40+
await Task.Delay(1000);
41+
Navigation.NavigateTo("/", forceLoad: true);
42+
}
43+
catch (Exception ex)
44+
{
45+
Console.WriteLine($"Error resetting app: {ex.Message}");
46+
}
47+
}
48+
}

scripts/start.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ cd "$ROOT_DIR"
88
# Colors
99
GREEN='\033[0;32m'
1010
YELLOW='\033[1;33m'
11+
BLUE='\033[0;34m'
1112
NC='\033[0m'
1213

1314
# Configurable ports
1415
BACKEND_PORT=${BACKEND_PORT:-5280}
1516
FRONTEND_PORT=${FRONTEND_PORT:-5173}
1617

18+
# Run tests after starting? (set RUN_TESTS=1 to enable)
19+
RUN_TESTS=${RUN_TESTS:-0}
20+
1721
# PIDs for cleanup
1822
PIDS=()
1923
cleanup() {
@@ -68,6 +72,16 @@ wait_for_url() {
6872
start_backend
6973
start_frontend
7074

75+
# Wait for backend to be ready
76+
if [ -d "$ROOT_DIR/backend" ] || [ -d "$ROOT_DIR/api" ]; then
77+
wait_for_url "http://localhost:${BACKEND_PORT}/api/health"
78+
79+
# Auto-seed data on startup
80+
echo -e "${GREEN}Seeding test data...${NC}"
81+
curl -s -X POST "http://localhost:${BACKEND_PORT}/api/dev/reseed" >/dev/null 2>&1 || true
82+
echo -e "${GREEN}✓ Test data seeded${NC}"
83+
fi
84+
7185
wait_for_url "http://localhost:${FRONTEND_PORT}"
7286

7387
# Open in iOS Simulator by default (set IOS_SIM=0 to disable)
@@ -95,5 +109,25 @@ else
95109
fi
96110
fi
97111

112+
# Run e2e tests if requested
113+
if [ "$RUN_TESTS" = "1" ]; then
114+
echo -e "\n${BLUE}╔════════════════════════════════════════════════╗${NC}"
115+
echo -e "${BLUE}║ Running E2E Tests (Headed) ║${NC}"
116+
echo -e "${BLUE}╚════════════════════════════════════════════════╝${NC}"
117+
echo ""
118+
echo -e "${GREEN}Tests will run in visible browser windows${NC}"
119+
echo -e "${YELLOW}Press Ctrl+C to stop tests and servers${NC}"
120+
echo ""
121+
122+
# Wait a bit for everything to be fully ready
123+
sleep 2
124+
125+
# Run tests in headed mode so you can see them
126+
npm run test:e2e:headed
127+
128+
echo -e "\n${GREEN}✓ Tests completed${NC}"
129+
echo -e "${YELLOW}Servers are still running. Press Ctrl+C to stop.${NC}"
130+
fi
131+
98132
# Keep processes running
99133
wait

0 commit comments

Comments
 (0)