import { test, expect, Page } from '@playwright/test';
import { strictEqual } from 'assert';

let page: Page;

test.beforeAll(async ({ browser }) => {
  page = await browser.newPage();
});

test.afterAll(async () => {
  if (page !== undefined) {
    await page.close();
  }
});

test('Login', async () => {
  // Login
  await page.goto('http://192.168.1.90:20001/');
  await expect(page).toHaveTitle(/^Sign in to /);
  await page.fill("input[name='username']", 'admin');
  await page.fill("input[name='password']", '1234');
  await page.click('id=kc-login');
  await page.waitForTimeout(2000);
  //   await page.click('id=acceptBtn');
});

test('Create Sub Branch Managenment', async () => {
  await page.click('id=menu-icon-branch-management');
  for (let i = 0; i < 10; i++) {
    await page.click('id=create-sub-branch-btn-สีลม');
    await page.fill("(//input[@id='input-tax-no'])[2]", `126084622028${i + 1}`);
    await page.fill("(//input[@id='input-name'])[2]", `สีลม${i + 1}`);
    await page.fill("(//input[@id='input-name-en'])[2]", `Silom${i + 1}`);
    await page.fill("(//input[@id='input-address'])[2]", `20/0${i + 1}`);
    await page.click("(//div[@id='select-province'])[2]");
    await page.click("//div[@role='option']");
    await page.click("(//div[@id='select-district'])[2]");
    await page.click("//span[text()='เมือง']");
    await page.click("(//div[@id='select-sub-district'])[2]");
    await page.click("//span[text()='ช้างเผือก']");
    await page.fill("(//input[@id='input-address-en'])[2]", `20/0${i + 1}`);
    await page.click('id=submitBtn');
  }
  await page.waitForTimeout(2000);
});
