fix(settings): проверять доступность текущего источника без гонок
This commit is contained in:
1 parent
b6f1b72500
commit
e5842b415b
8 files changed
+72
-17
No files matched your search
@@ -6,3 +6,11 @@ async function setup(page:Page){await page.route("**/health",r=>r.fulfill({heade
|
||||
test("Settings source: invalid backend URL stays draft without changing active source",async({page})=>{await setup(page);const input=page.getByRole("textbox",{name:"URL бекенда",exact:true});for(const value of ["bad","ftp://host.test","https://user:secret@host.test","https://host.test?token=secret"]){await input.fill(value);await input.press("Enter");await expect(page.locator("#main-content").getByRole("alert")).toContainText("Укажите HTTP(S) адрес");expect(await page.evaluate(()=>localStorage.getItem("routerlists:backend-url"))).toBeNull();await expect(input).toHaveValue(value)}})
|
||||
test("Settings source: URL canonicalizes and persists after Enter",async({page})=>{await setup(page);const input=page.getByRole("textbox",{name:"URL бекенда",exact:true});await input.fill(" http://LOCALHOST:8101/ ");await input.press("Enter");await expect(input).toHaveValue("http://localhost:8101");expect(await page.evaluate(()=>localStorage.getItem("routerlists:backend-url"))).toBe("http://localhost:8101");await page.reload();await expect(input).toHaveValue("http://localhost:8101")})
|
||||
test("Settings source: explicit demo/live mode persists",async({page})=>{await setup(page);await page.getByRole("button",{name:"Моковые",exact:true}).click();expect(await page.evaluate(()=>localStorage.getItem("routerlists:data-source"))).toBe("mock");await page.reload();await expect(page.getByRole("button",{name:"Моковые",exact:true})).toBeVisible();await page.getByRole("button",{name:"Живые",exact:true}).click();expect(await page.evaluate(()=>localStorage.getItem("routerlists:data-source"))).toBe("live")})
|
||||
for(const failed of [false,true])test("Settings health: old backend result ignored/"+failed,async({page})=>{
|
||||
await page.route("**/health",r=>r.fulfill({headers,json:{status:"ok"}}));let started=false,completed=false,release!:()=>void;const gate=new Promise<void>(r=>release=r)
|
||||
await page.route("http://localhost:8000/health",async r=>{started=true;await gate;try{await r.fulfill(failed?{headers,status:503,json:{error:"old health"}}:{headers,json:{status:"ok"}})}catch{}finally{completed=true}})
|
||||
try{await page.route("**/api/**",r=>r.fulfill({headers,json:{required:false}}));await page.goto("/settings");await expect.poll(()=>started).toBe(true);const input=page.getByRole("textbox",{name:"URL бекенда",exact:true});await input.fill("http://localhost:8101");await input.press("Enter");await expect(page.getByText("Доступен",{exact:true})).toBeVisible();release();await expect.poll(()=>completed).toBe(true);await expect(page.getByText("Доступен",{exact:true})).toBeVisible();await expect(page.getByText("Недоступен",{exact:true})).toHaveCount(0)}finally{release()}
|
||||
})
|
||||
test("Settings health: source switch does not inherit available status",async({page})=>{await setup(page);await expect(page.getByText("Доступен",{exact:true})).toBeVisible();let started=false,release!:()=>void;const gate=new Promise<void>(r=>release=r);await page.route("http://localhost:8101/health",async r=>{started=true;await gate;try{await r.fulfill({headers,json:{ok:false}})}catch{}});try{const input=page.getByRole("textbox",{name:"URL бекенда",exact:true});await input.fill("http://localhost:8101");await input.press("Enter");await expect.poll(()=>started).toBe(true);await expect(page.getByText("Проверка…",{exact:true})).toBeVisible();await expect(page.getByText("Доступен",{exact:true})).toHaveCount(0);release();await expect(page.getByText("Недоступен",{exact:true})).toBeVisible()}finally{release()}})
|
||||
test("Settings health: returning to source A rejects its old failed request",async({page})=>{await page.route("**/health",r=>r.fulfill({headers,json:{status:"ok"}}));await page.route("**/api/**",r=>r.fulfill({headers,json:{required:false}}));let count=0,freshA=false,completed=false,release!:()=>void;const gate=new Promise<void>(r=>release=r);await page.route("http://localhost:8000/health",async r=>{count++;if(freshA)return r.fulfill({headers,json:{status:"ok"}});await gate;try{await r.fulfill({headers,status:503,json:{error:"first A failed"}})}catch{}finally{completed=true}});try{await page.goto("/settings");await expect.poll(()=>count).toBeGreaterThan(0);const input=page.getByRole("textbox",{name:"URL бекенда",exact:true});await input.fill("http://localhost:8101");await input.press("Enter");await expect(page.getByText("Доступен",{exact:true})).toBeVisible();const previousARequests=count;freshA=true;await input.fill("http://localhost:8000");await input.press("Enter");await expect.poll(()=>count).toBeGreaterThan(previousARequests);await expect(page.getByText("Доступен",{exact:true})).toBeVisible();release();await expect.poll(()=>completed).toBe(true);await expect(page.getByText("Доступен",{exact:true})).toBeVisible()}finally{release()}})
|
||||
for(const payload of [{},{ok:false},"proxy html"])test("Settings health: HTTP 200 with invalid body is unavailable/"+JSON.stringify(payload),async({page})=>{await setup(page);await expect(page.getByText("Доступен",{exact:true})).toBeVisible();await page.route("**/health",r=>r.fulfill({headers,json:payload}));await page.getByRole("button",{name:"Проверить",exact:true}).click();await expect(page.getByText("Недоступен",{exact:true})).toBeVisible();await expect(page.getByText("Доступен",{exact:true})).toHaveCount(0)})
|
||||
Reference in new issue
Block a user