feat: redesign the web console with Vue and isolated account workspaces
This commit is contained in:
@@ -6,6 +6,7 @@ Only disposable demo accounts and a synthetic administrator password are used.
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
import re
|
||||
import socket
|
||||
import tempfile
|
||||
import threading
|
||||
@@ -14,7 +15,8 @@ import unittest
|
||||
from unittest.mock import patch
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
from .test_workbench_browser import AVAILABLE, EDGE, OfflineUpdates
|
||||
from ranch_web.tests.test_api import FrontendAssets
|
||||
from .test_workbench_browser import AVAILABLE, EDGE, OfflineUpdates, GAME_PAGES, GLOBAL_PAGES, assert_navigation
|
||||
|
||||
if AVAILABLE:
|
||||
from playwright.sync_api import expect
|
||||
@@ -99,7 +101,7 @@ class BasePathBrowserTests(unittest.TestCase):
|
||||
expect(page.locator("#auth-form")).to_be_visible()
|
||||
expect(page.locator("#admin-password")).to_be_enabled()
|
||||
expect(page.locator("#auth-form")).to_have_attribute("action", prefix + "/api/auth/login")
|
||||
self.assertEqual(page.locator("#app, nav, #account-tabs, #page-tabs, #page-host").count(), 0)
|
||||
self.assertEqual(page.locator("#app, nav, #sidebar, #topbar, #account-select, #account-tabs, #page-tabs, #page-host").count(), 0)
|
||||
self.assertEqual(page.locator("script").count(), 1)
|
||||
expect(page.locator("script")).to_have_attribute("src", prefix + "/static/login.js")
|
||||
expect(page.locator('link[rel="stylesheet"]')).to_have_attribute("href", prefix + "/static/login.css")
|
||||
@@ -118,26 +120,45 @@ class BasePathBrowserTests(unittest.TestCase):
|
||||
page.locator('#auth-form button[type="submit"]').click()
|
||||
self.assertEqual(login.value.status, 200)
|
||||
self.assertEqual(login.value.request.post_data_json, {"password": self.password})
|
||||
expect(page).to_have_url(base + "/")
|
||||
expect(page).to_have_url(re.compile("^" + re.escape(base + "/") + r"(?:#.*)?$"))
|
||||
expect(page.locator("#app")).to_be_visible()
|
||||
expect(page.locator("#status-text")).to_have_text("工作台已连接")
|
||||
assert_navigation(page)
|
||||
expect(page.locator("#status-text")).to_contain_text("已连接")
|
||||
expect(page.locator("#save-status")).to_have_text("策略已自动保存")
|
||||
expect(page.locator('link[rel="stylesheet"]')).to_have_attribute("href", prefix + "/static/styles.css")
|
||||
assets = FrontendAssets(page.content())
|
||||
self.assertTrue(assets.scripts)
|
||||
self.assertTrue(assets.stylesheets)
|
||||
for url in assets.urls:
|
||||
self.assertTrue(url.startswith(prefix + "/static/"), url)
|
||||
self.assertNotIn(prefix + prefix, url)
|
||||
response = context.request.get(origin + url)
|
||||
self.assertEqual(response.status, 200, url)
|
||||
self.assertEqual(context.cookies()[0]["path"], prefix or "/")
|
||||
self.assertEqual(page.evaluate("localStorage.length + sessionStorage.length"), 0)
|
||||
|
||||
for key in "login incubator bag ranch daily hatching mainline battles gifts commissions exploration maps statistics plans yields".split():
|
||||
page.locator(f'.page-tab[data-page="{key}"]').click()
|
||||
for key in GAME_PAGES:
|
||||
page.locator(f'.nav-link[data-page="{key}"]').click()
|
||||
panel = page.locator(f'.page-panel[data-page="{key}"]:not([hidden])')
|
||||
expect(panel.locator('.page-loading[data-loading="false"]')).to_have_count(1)
|
||||
self.assertEqual(panel.locator(".page-error:not([hidden])").count(), 0)
|
||||
if key == "bag":
|
||||
route_url = page.url
|
||||
self.assertEqual(urlsplit(route_url).fragment, f"/accounts/{account}/bag")
|
||||
page.reload(wait_until="networkidle")
|
||||
expect(page).to_have_url(route_url)
|
||||
expect(page.locator("#account-select")).to_have_value(account)
|
||||
expect(page.locator('.nav-link[data-page="bag"]')).to_have_attribute("aria-current", "page")
|
||||
expect(panel.locator('.page-loading[data-loading="false"]')).to_have_count(1)
|
||||
for key in GLOBAL_PAGES:
|
||||
page.locator(f'.nav-link[data-page="{key}"]').click()
|
||||
expect(page.locator(f'.nav-link[data-page="{key}"]')).to_have_attribute("aria-current", "page")
|
||||
|
||||
# The server redirects an authenticated login URL back to this workbench.
|
||||
page.goto(base + "/login", wait_until="networkidle")
|
||||
expect(page).to_have_url(base + "/")
|
||||
expect(page.locator("#status-text")).to_have_text("工作台已连接")
|
||||
self.assertEqual(urlsplit(page.url).path, prefix + "/")
|
||||
expect(page.locator("#status-text")).to_contain_text("已连接")
|
||||
cookies = context.cookies()
|
||||
page.locator(".menu > summary").first.click()
|
||||
page.locator('.nav-link[data-page="system"]').click()
|
||||
with page.expect_response(base + "/api/auth/logout") as logout:
|
||||
page.locator('[data-command="admin-logout"]').click()
|
||||
self.assertEqual(logout.value.status, 200)
|
||||
@@ -148,7 +169,8 @@ class BasePathBrowserTests(unittest.TestCase):
|
||||
assert_login()
|
||||
self.assertEqual(escapes, [], "Browser requests escaped the configured prefix or local server")
|
||||
self.assertEqual(errors, [], "JavaScript or CSP errors")
|
||||
self.assertTrue(any(request.url == base + "/static/paths.js" for request in requests))
|
||||
for url, _ in assets.scripts:
|
||||
self.assertTrue(any(request.url == origin + url for request in requests), url)
|
||||
|
||||
def test_preserved_prefix(self):
|
||||
self.check_deployment("/ranch")
|
||||
|
||||
Reference in New Issue
Block a user