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 Legalentitly Person', async () => {
  await page.click('id=menu-icon-customer-management');
  await page.click("(//div[@id='btn-add'])[1]");
  await page.click('id=add-customer-legal-entity');
  await page.click("(//div[@id='input-source-nationality'])[3]");
  await page.click("//span[text()='บางรัก']");
  await page.fill("(//input[@id='input-customer-name'])[3]", 'ลอย');
  await page.fill("(//input[@id='input-customer-name-en'])[3]", 'Loi');
  await page.fill("(//input[@id='input-owner-name'])[3]", 'ปิงปิง');
  await page.fill("(//input[@id='input-customerEnglishName'])[3]", 'Bangrak');
  await page.fill("(//input[@id='input-customerName'])[3]", 'บางรัก');
  await page.fill("(//input[@id='input-taxNo'])[3]", '1284262822028');
  await page.fill("(//input[@id='input-registerName'])[3]", 'ปองพล กันธะณะ');
  await page.fill("(//input[@id='input-authorizedCapital'])[3]", '20000000');
  await page.click("(//input[@aria-label='จดทะเบียนเมื่อ'])[3]");
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2560']");
  await page.click("(//div[text()='30'])[2]");
  await page.fill("(//input[@id='input-address-0'])[3]", '20/02');
  await page.click("(//div[@id='select-province-0'])[3]");
  await page.click("//span[text()='เชียงใหม่']");
  await page.click("(//div[@id='select-district-0'])[3]");
  await page.waitForTimeout(2000);
  await page.click("//div[@role='option']");
  await page.click("(//div[@id='select-sub-district-0'])[3]");
  await page.waitForTimeout(2000);
  await page.click("//div[@role='option']");
  await page.fill("(//input[@id='input-address-en-0'])[3]", '20/02');
  await page.fill(
    "(//input[@id='input-employment-office'])[3]",
    'กรุงเทพมหานคร',
  );
  await page.click("(//div[@id='select-business-type'])[3]");
  await page.click("//span[text()='ประมง']");
  await page.click("(//div[@id='select-job-position'])[3]");
  await page.click("(//div[@role='option'])[1]");
  await page.fill(
    "(//input[@id='input-job-description'])[3]",
    'ตรวจสอบการทำการลักษณะงาน',
  );
  await page.click("(//input[@aria-label='วันที่จ่ายค่าแรง'])[3]");
  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("(//input[@id='input-sales-person'])[3]", 'พนักงานขาย');
  await page.fill("(//input[@id='input-mail'])[3]", 'jws@local.com');
  await page.fill("(//input[@id='input-telephone'])[3]", '0864228464');
  await page.setInputFiles(
    "(//input[contains(@class,'q-field__input fit')])[3]",
    '/Users/linping/Desktop/Chamomind&FrappeT/JWS_TestScript/tests/Datafile/Pic1.jpg',
  ); // UploadFile
  await page.click('id=submitBtn');
  await page.waitForTimeout(2000);
});

test('Create Legalentitly Person Second', async () => {
  await page.click("(//div[@id='btn-add'])[1]");
  await page.click('id=add-customer-legal-entity');
  await page.fill("(//input[@id='input-customer-name'])[3]", 'ลาภ');
  await page.fill("(//input[@id='input-customer-name-en'])[3]", 'Lab');
  await page.fill("(//input[@id='input-owner-name'])[3]", 'ปิงปิง');
  await page.fill("(//input[@id='input-customerEnglishName'])[3]", 'Silom');
  await page.fill("(//input[@id='input-customerName'])[3]", 'สีลม');
  await page.fill("(//input[@id='input-taxNo'])[3]", '1284262822028');
  await page.fill("(//input[@id='input-registerName'])[3]", 'ปองพล กันธะณะ');
  await page.fill("(//input[@id='input-authorizedCapital'])[3]", '20000000');
  await page.click("(//input[@aria-label='จดทะเบียนเมื่อ'])[3]");
  await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
  await page.click("//div[text()='2560']");
  await page.click("(//div[text()='30'])[2]");
  await page.fill("(//input[@id='input-address-0'])[3]", '20/02');
  await page.click("(//div[@id='select-province-0'])[3]");
  await page.click("//span[text()='เชียงใหม่']");
  await page.click("(//div[@id='select-district-0'])[3]");
  await page.waitForTimeout(2000);
  await page.click("//div[@role='option']");
  await page.click("(//div[@id='select-sub-district-0'])[3]");
  await page.waitForTimeout(2000);
  await page.click("//div[@role='option']");
  await page.fill("(//input[@id='input-address-en-0'])[3]", '20/02');
  await page.fill(
    "(//input[@id='input-employment-office'])[3]",
    'กรุงเทพมหานคร',
  );
  await page.click("(//div[@id='select-business-type'])[3]");
  await page.click("//span[text()='ประมง']");
  await page.click("(//div[@id='select-job-position'])[3]");
  await page.click("(//div[@role='option'])[1]");
  await page.fill(
    "(//input[@id='input-job-description'])[3]",
    'ตรวจสอบการทำการลักษณะงาน',
  );
  await page.click("(//input[@aria-label='วันที่จ่ายค่าแรง'])[3]");
  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("(//input[@id='input-sales-person'])[3]", 'พนักงานขาย');
  await page.fill("(//input[@id='input-mail'])[3]", 'jws@local.com');
  await page.fill("(//input[@id='input-telephone'])[3]", '0864228464');
  await page.setInputFiles(
    "(//input[contains(@class,'q-field__input fit')])[3]",
    '/Users/linping/Desktop/Chamomind&FrappeT/JWS_TestScript/tests/Datafile/Pic1.jpg',
  ); // UploadFile
  await page.click('id=submitBtn');
  await page.waitForTimeout(2000);
});
