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('Open Natural Person', async () => {
  await page.click('id=menu-icon-customer-management');
  await page.click('id=row-table-โคโม่');
  await page.click("(//div[@id='btn-add']//a)[1]");
  await page.click("(//div[@id='btn-add']//div)[2]");
  await page.waitForTimeout(2000);
});

test('Create Sub Branch Natural Person', async () => {
  await page.fill('id=form-dialog-input-branch-no', '20');
  await page.fill('id=form-dialog-input-customer-name', 'สยาม');
  await page.fill('id=form-dialog-input-customer-english-name', 'siam');
  await page.fill('id=form-dialog-input-address-0', '20/022');
  await page.click('id=form-dialog-select-province-0');
  await page.click("//div[@role='option']");
  await page.click('id=form-dialog-select-district-0');
  await page.waitForTimeout(1000);
  await page.click("//div[@role='option']");
  await page.click('id=form-dialog-select-sub-district-0');
  await page.waitForTimeout(1000);
  await page.click("//div[@role='option']");
  await page.fill('id=form-dialog-input-address-en-0', '20/022');
  await page.fill('id=form-dialog-input-employment-office', 'กรุงเทพมหานคร');
  await page.click('id=form-dialog-select-business-type');
  await page.click("//span[text()='ประมง']");
  await page.click("(//div[@id='form-dialog-select-job-position'])[1]");
  await page.click("(//div[@role='option'])[1]");
  await page.fill(
    'id=form-dialog-input-job-description',
    'ตรวจสอบการทำการลักษณะงาน',
  );
  await page.click('id=form-dialog-input-start-date');
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2561']");
  await page.click("//div[text()='12']");
  await page.fill('id=form-dialog-input-sales-person', 'พนักงานขาย');
  await page.fill('id=form-dialog-input-mail', 'jws@local.com');
  await page.fill('id=form-dialog-input-telephone', '0864228464');
  // await page.setInputFiles(
  //   "//input[@id='f_55bbcb5d-4316-43c8-93cf-99c4f1f60115']",
  //   '/Users/linping/Desktop/Chamomind&FrappeT/JWS_TestScript/tests/Datafile/Pic1.jpg',
  // ); // UploadFile
  await page.click("(//button[@id='submitBtn'])[2]");
  await page.waitForTimeout(2000);
});
