feat(pwa): installable web app + landing web entry
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 10s
CI / integration (pull_request) Successful in 19s
CI / ui (pull_request) Successful in 1m8s
CI / conformance (pull_request) Successful in 9s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m43s
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 10s
CI / integration (pull_request) Successful in 19s
CI / ui (pull_request) Successful in 1m8s
CI / conformance (pull_request) Successful in 9s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m43s
Make the web SPA an installable PWA and surface it to users: - manifest.webmanifest + an install-only service worker + 192/512/maskable icons (ui/public); PWA head tags in index.html; the .webmanifest MIME type registered in the gateway (the distroless image has no /etc/mime.types). - Platform-adaptive install CTA (components/InstallApp.svelte + lib/pwa): one-tap on Chromium, manual Add-to-Home-Screen instructions on iOS Safari, hidden elsewhere / once installed / inside a Mini App. Shown under the logged-out login card and at the bottom of Settings. - The landing gains a third entry linking /app/ (the brand tile), with a caption under all three (Telegram / VK / Веб-версия). The service worker is navigation-only (network-first, cached-shell fallback); hashed assets and the Connect stream are untouched. It exists to satisfy Chromium's installability requirement and is the single growth point for a future opt-in offline mode. Tests: pwa.ts unit tests; a webui probe (manifest/sw.js content-type + the SPA-fallback-to-HTML trap); e2e for the one-tap CTA, the iOS instructions modal and the landing web entry. Docs: ARCHITECTURE §13, FUNCTIONAL (+ru), gateway README.
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"testing/fstest"
|
||||
)
|
||||
|
||||
// get drives the handler with a GET for the given path and returns the response.
|
||||
@@ -55,3 +56,56 @@ func TestAppMountServesShellStripsPrefixAndCachesAssets(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// testFS mirrors what Vite emits into dist/: the SPA shell, the PWA manifest + service worker at
|
||||
// the root (copied from ui/public), and a hash-named asset. The compile-time embedded dist/ holds
|
||||
// only a placeholder shell, so the manifest/sw.js serving is exercised over this in-memory FS.
|
||||
func testFS() fstest.MapFS {
|
||||
return fstest.MapFS{
|
||||
"index.html": {Data: []byte("<!doctype html><title>shell</title>")},
|
||||
"manifest.webmanifest": {Data: []byte(`{"name":"Эрудит"}`)},
|
||||
"sw.js": {Data: []byte("self.addEventListener('fetch', () => {});")},
|
||||
"assets/app-abc123.js": {Data: []byte("export const x = 1;")},
|
||||
}
|
||||
}
|
||||
|
||||
// TestHandlerServesManifestWithManifestType: the PWA manifest is served with the manifest MIME
|
||||
// type (registered in init, since the distroless image has no /etc/mime.types), not sniffed to
|
||||
// text/plain, which some browsers reject.
|
||||
func TestHandlerServesManifestWithManifestType(t *testing.T) {
|
||||
h := handlerFor(testFS(), "/app/", "index.html")
|
||||
resp := get(t, h, "/app/manifest.webmanifest")
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("status = %d, want 200", resp.StatusCode)
|
||||
}
|
||||
if ct := resp.Header.Get("Content-Type"); !strings.HasPrefix(ct, "application/manifest+json") {
|
||||
t.Errorf("Content-Type = %q, want application/manifest+json", ct)
|
||||
}
|
||||
}
|
||||
|
||||
// TestHandlerServesServiceWorkerAsJavaScript: sw.js is served as JavaScript from the root, so its
|
||||
// registration (scope /app/) succeeds.
|
||||
func TestHandlerServesServiceWorkerAsJavaScript(t *testing.T) {
|
||||
h := handlerFor(testFS(), "/app/", "index.html")
|
||||
resp := get(t, h, "/app/sw.js")
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("status = %d, want 200", resp.StatusCode)
|
||||
}
|
||||
if ct := resp.Header.Get("Content-Type"); !strings.HasPrefix(ct, "text/javascript") {
|
||||
t.Errorf("Content-Type = %q, want text/javascript", ct)
|
||||
}
|
||||
}
|
||||
|
||||
// TestHandlerFallsBackToShellForUnknownManifestPath guards the trap: a manifest/sw path NOT emitted
|
||||
// into dist/ falls back to the SPA shell as text/html, on which SW registration would fail. The two
|
||||
// tests above pin that the real files are served instead of the shell.
|
||||
func TestHandlerFallsBackToShellForUnknownManifestPath(t *testing.T) {
|
||||
h := handlerFor(testFS(), "/app/", "index.html")
|
||||
resp := get(t, h, "/app/not-emitted.webmanifest")
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("status = %d, want 200", resp.StatusCode)
|
||||
}
|
||||
if ct := resp.Header.Get("Content-Type"); !strings.HasPrefix(ct, "text/html") {
|
||||
t.Errorf("Content-Type = %q, want text/html (SPA shell fallback)", ct)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user