Skip to content

Commit 922411b

Browse files
committed
fix: add missing database migrations to httpapi tests and fix HTML preview widget lifecycle
- Add MapRuleModel and other missing models to AutoMigrate in httpapi tests - Fix "no such table: map_rules" error in CI tests - Add didUpdateWidget() to HtmlPreview widget to handle content updates - Add dispose() method for proper cleanup
1 parent e81e720 commit 922411b

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

frontend/lib/widgets/html_preview.dart

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,24 @@ class _HtmlPreviewState extends State<HtmlPreview> {
1919
@override
2020
void initState() {
2121
super.initState();
22-
_controller =
23-
WebViewController()
24-
..setJavaScriptMode(JavaScriptMode.unrestricted)
25-
..loadHtmlString(widget.html, baseUrl: widget.baseUrl);
22+
_controller = WebViewController()
23+
..setJavaScriptMode(JavaScriptMode.unrestricted)
24+
..loadHtmlString(widget.html, baseUrl: widget.baseUrl);
25+
}
26+
27+
@override
28+
void didUpdateWidget(HtmlPreview oldWidget) {
29+
super.didUpdateWidget(oldWidget);
30+
// Reload HTML if content or baseUrl changed
31+
if (oldWidget.html != widget.html || oldWidget.baseUrl != widget.baseUrl) {
32+
_controller.loadHtmlString(widget.html, baseUrl: widget.baseUrl);
33+
}
34+
}
35+
36+
@override
37+
void dispose() {
38+
// WebViewController doesn't require explicit disposal in webview_flutter 4.x
39+
super.dispose();
2640
}
2741

2842
@override

internal/infrastructure/httpapi/proxy_api_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import (
77
"net/http/httptest"
88
"testing"
99

10+
mappingp "network-debugger/internal/features/mapping/infrastructure/persistence"
11+
processp "network-debugger/internal/features/process/infrastructure/persistence"
1012
proxyp "network-debugger/internal/features/proxy/infrastructure/persistence"
1113
proxyuc "network-debugger/internal/features/proxy/usecase"
14+
settingsp "network-debugger/internal/features/settings/infrastructure/persistence"
1215
dbinfra "network-debugger/internal/infrastructure/db"
1316
obs "network-debugger/internal/infrastructure/observability"
1417
pruntime "network-debugger/internal/infrastructure/proxyruntime"
@@ -20,7 +23,14 @@ func setupProxyDeps(t *testing.T) *Deps {
2023
if err != nil {
2124
t.Fatalf("db: %v", err)
2225
}
23-
if err := gdb.AutoMigrate(&proxyp.ProxyConfigModel{}); err != nil {
26+
if err := gdb.AutoMigrate(
27+
&proxyp.ProxyConfigModel{},
28+
&settingsp.RuntimeSettingsModel{},
29+
&settingsp.ThrottleProfileModel{},
30+
&mappingp.MapRuleModel{},
31+
&processp.ProcessDetectionConfigModel{},
32+
&processp.IconCacheModel{},
33+
); err != nil {
2434
t.Fatalf("migrate: %v", err)
2535
}
2636

internal/infrastructure/httpapi/throttle_profiles_e2e_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import (
99
"testing"
1010

1111
"network-debugger/internal/adapters/storage/memory"
12+
mappingp "network-debugger/internal/features/mapping/infrastructure/persistence"
13+
processp "network-debugger/internal/features/process/infrastructure/persistence"
14+
proxyp "network-debugger/internal/features/proxy/infrastructure/persistence"
1215
setp "network-debugger/internal/features/settings/infrastructure/persistence"
1316
cfgpkg "network-debugger/internal/infrastructure/config"
1417
obs "network-debugger/internal/infrastructure/observability"
@@ -25,7 +28,14 @@ func newTestServer(t *testing.T) (*httptest.Server, *gorm.DB) {
2528
if err != nil {
2629
t.Fatalf("db open: %v", err)
2730
}
28-
if err := gdb.AutoMigrate(&setp.RuntimeSettingsModel{}, &setp.ThrottleProfileModel{}); err != nil {
31+
if err := gdb.AutoMigrate(
32+
&setp.RuntimeSettingsModel{},
33+
&setp.ThrottleProfileModel{},
34+
&proxyp.ProxyConfigModel{},
35+
&mappingp.MapRuleModel{},
36+
&processp.ProcessDetectionConfigModel{},
37+
&processp.IconCacheModel{},
38+
); err != nil {
2939
t.Fatalf("migrate: %v", err)
3040
}
3141
cfg := cfgpkg.Config{Addr: ":0", CORSAllowOrigin: "*", DevMode: true}

0 commit comments

Comments
 (0)