/// <reference lib="dom" />
import { expect } from "e2e";
import { test, WEB, runPromise } from "./t3.ts";
import { run } from "./shell.ts";
const TITLE = "ΠΟΛΥ ΣΗΜΑΝΤΙΚΕΣ ΑΛΛΑΓΕΣ !";
test("A real host-returned Greek title has title-match ranking for either sigma", WEB, async ({t3,app,browser,screen}) => {
 const project = await t3.project("Greek host title");
 await runPromise(run("git",["remote","add","origin","https://github.com/ESN-TEI-of-Piraeus/Greece-EK.git"],{cwd:project}));
 await t3.open('/pull-requests');
 await screen.getByText(TITLE,{exact:true}).waitFor({timeout:60000});
 const results:Record<string,boolean> = {};
 for(const [name,query] of [["final","αλλαγες"],["medial","αλλαγεσ"]]) {
  await screen.getByRole('searchbox','Search pull requests').fill(query);
  await browser.mouse.move(10,400);
  await browser.evaluate(() => new Promise(resolve => setTimeout(resolve,20000)));
  results[name] = await browser.evaluate(title => {
   const leaf = [...document.querySelectorAll('*')].find(e=>e.textContent===title && e.children.length===0);
   const row = leaf?.closest('button');
   return !!row && !row.textContent?.includes('matched in the description');
  },TITLE);
  await app.screenshot(`host-title-${name}-sigma`);
 }
 expect(results).toEqual({final:true,medial:true});
});
