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 Natural Person No input Data', async () => {
  await page.click('id=menu-icon-customer-management');
  await page.click("(//div[@id='btn-add'])[1]");
  await page.click('id=add-customer-natural-person');
  await page.click('id=submitBtn');
  await page.waitForTimeout(2000);
  await page.click('id=cancelBtn');
  await page.waitForTimeout(2000);
});

test('Create Natural Person No Input Employee name', async () => {
  await page.click("(//div[@id='btn-add'])[1]");
  await page.click('id=add-customer-natural-person');
  await page.fill("(//input[@id='input-employer-id'])[3]", '');
  await page.fill("(//input[@id='input-tax-no'])[3]", '1242822482204');
  await page.fill("(//input[@id='input-customer-name'])[3]", 'โคโม่');
  await page.fill("(//input[@id='input-customer-name-en'])[3]", 'Como');
  await page.fill("(//input[@id='input-customerName'])[3]", 'ปองพล กันธะณะ');
  await page.fill("(//input[@id='input-address-0'])[3]", '20/02');
  await page.click("(//div[@id='select-province-0'])[3]");
  await page.click("//div[@role='option']");
  await page.click("(//div[@id='select-district-0'])[3]");
  await page.waitForTimeout(1000);
  await page.click("//div[@role='option']");
  await page.click("(//div[@id='select-sub-district-0'])[3]");
  await page.waitForTimeout(1000);
  await page.click("//div[@role='option']");
  await page.fill("(//input[@id='input-address-en-0'])[3]", '20/02');
  await page.click('id=submitBtn');
  await page.waitForTimeout(2000);
});

test('Create Natural Person No Input Tax No', async () => {
  await page.click("(//div[@id='btn-add'])[1]");
  await page.click('id=add-customer-natural-person');
  await page.fill("(//input[@id='input-employer-id'])[3]", 'ปิง');
  await page.fill("(//input[@id='input-tax-no'])[3]", '');
  await page.fill("(//input[@id='input-customer-name'])[3]", 'โคโม่');
  await page.fill("(//input[@id='input-customer-name-en'])[3]", 'Como');
  await page.fill("(//input[@id='input-customerName'])[3]", 'ปองพล กันธะณะ');
  await page.fill("(//input[@id='input-address-0'])[3]", '20/02');
  await page.click("(//div[@id='select-province-0'])[3]");
  await page.click("//div[@role='option']");
  await page.click("(//div[@id='select-district-0'])[3]");
  await page.waitForTimeout(1000);
  await page.click("//div[@role='option']");
  await page.click("(//div[@id='select-sub-district-0'])[3]");
  await page.waitForTimeout(1000);
  await page.click("//div[@role='option']");
  await page.fill("(//input[@id='input-address-en-0'])[3]", '20/02');
  await page.click('id=cancelBtn');

  await page.waitForTimeout(2000);
});

test('Create Natural Person No Input Customer Name TH', async () => {
  await page.click("(//div[@id='btn-add'])[1]");
  await page.click('id=add-customer-natural-person');
  await page.fill("(//input[@id='input-employer-id'])[3]", 'ปิง');
  await page.fill("(//input[@id='input-tax-no'])[3]", '1242822482204');
  await page.fill("(//input[@id='input-customer-name'])[3]", '');
  await page.fill("(//input[@id='input-customer-name-en'])[3]", 'Como');
  await page.fill("(//input[@id='input-customerName'])[3]", 'ปองพล กันธะณะ');
  await page.fill("(//input[@id='input-address-0'])[3]", '20/02');
  await page.click("(//div[@id='select-province-0'])[3]");
  await page.click("//div[@role='option']");
  await page.click("(//div[@id='select-district-0'])[3]");
  await page.waitForTimeout(1000);
  await page.click("//div[@role='option']");
  await page.click("(//div[@id='select-sub-district-0'])[3]");
  await page.waitForTimeout(1000);
  await page.click("//div[@role='option']");
  await page.fill("(//input[@id='input-address-en-0'])[3]", '20/02');
  await page.click('id=submitBtn');
  await page.waitForTimeout(2000);
});

test('Create Natural Person No Input Customer Name EN', async () => {
  await page.click("(//div[@id='btn-add'])[1]");
  await page.click('id=add-customer-natural-person');
  await page.fill("(//input[@id='input-employer-id'])[3]", 'ปิง');
  await page.fill("(//input[@id='input-tax-no'])[3]", '1242822482204');
  await page.fill("(//input[@id='input-customer-name'])[3]", 'โคโม่');
  await page.fill("(//input[@id='input-customer-name-en'])[3]", '');
  await page.fill("(//input[@id='input-customerName'])[3]", 'ปองพล กันธะณะ');
  await page.fill("(//input[@id='input-address-0'])[3]", '20/02');
  await page.click("(//div[@id='select-province-0'])[3]");
  await page.click("//div[@role='option']");
  await page.click("(//div[@id='select-district-0'])[3]");
  await page.waitForTimeout(1000);
  await page.click("//div[@role='option']");
  await page.click("(//div[@id='select-sub-district-0'])[3]");
  await page.waitForTimeout(1000);
  await page.click("//div[@role='option']");
  await page.fill("(//input[@id='input-address-en-0'])[3]", '20/02');
  await page.click('id=submitBtn');
  await page.waitForTimeout(2000);
});

test('Create Natural Person No Input Customername', async () => {
  await page.click("(//div[@id='btn-add'])[1]");
  await page.click('id=add-customer-natural-person');
  await page.fill("(//input[@id='input-employer-id'])[3]", 'ปิง');
  await page.fill("(//input[@id='input-tax-no'])[3]", '1242822482204');
  await page.fill("(//input[@id='input-customer-name'])[3]", 'โคโม่');
  await page.fill("(//input[@id='input-customer-name-en'])[3]", 'Como');
  await page.fill("(//input[@id='input-customerName'])[3]", '');
  await page.fill("(//input[@id='input-address-0'])[3]", '20/02');
  await page.click("(//div[@id='select-province-0'])[3]");
  await page.click("//div[@role='option']");
  await page.click("(//div[@id='select-district-0'])[3]");
  await page.waitForTimeout(1000);
  await page.click("//div[@role='option']");
  await page.click("(//div[@id='select-sub-district-0'])[3]");
  await page.waitForTimeout(1000);
  await page.click("//div[@role='option']");
  await page.fill("(//input[@id='input-address-en-0'])[3]", '20/02');
  await page.click('id=submitBtn');
  await page.waitForTimeout(2000);
});

test('Create Natural Person No Input Address TH', async () => {
  await page.click("(//div[@id='btn-add'])[1]");
  await page.click('id=add-customer-natural-person');
  await page.fill("(//input[@id='input-employer-id'])[3]", 'ปิง');
  await page.fill("(//input[@id='input-tax-no'])[3]", '1242822482204');
  await page.fill("(//input[@id='input-customer-name'])[3]", 'โคโม่');
  await page.fill("(//input[@id='input-customer-name-en'])[3]", 'Como');
  await page.fill("(//input[@id='input-customerName'])[3]", 'ปองพล กันธะณะ');
  await page.fill("(//input[@id='input-address-0'])[3]", '');
  await page.click("(//div[@id='select-province-0'])[3]");
  await page.click("//div[@role='option']");
  await page.click("(//div[@id='select-district-0'])[3]");
  await page.waitForTimeout(1000);
  await page.click("//div[@role='option']");
  await page.click("(//div[@id='select-sub-district-0'])[3]");
  await page.waitForTimeout(1000);
  await page.click("//div[@role='option']");
  await page.fill("(//input[@id='input-address-en-0'])[3]", '20/02');
  await page.click('id=submitBtn');
  await page.waitForTimeout(2000);
  await page.click('id=cancelBtn');
  await page.waitForTimeout(2000);
});

test('Create Natural Person Not Select Province', async () => {
  await page.click("(//div[@id='btn-add'])[1]");
  await page.click('id=add-customer-natural-person');
  await page.fill("(//input[@id='input-employer-id'])[3]", 'ปิง');
  await page.fill("(//input[@id='input-tax-no'])[3]", '1242822482204');
  await page.fill("(//input[@id='input-customer-name'])[3]", 'โคโม่');
  await page.fill("(//input[@id='input-customer-name-en'])[3]", 'Como');
  await page.fill("(//input[@id='input-customerName'])[3]", 'ปองพล กันธะณะ');
  await page.fill("(//input[@id='input-address-0'])[3]", '20/02');
  await page.fill("(//input[@id='input-address-en-0'])[3]", '20/02');
  await page.click('id=submitBtn');
  await page.waitForTimeout(2000);
  await page.click('id=cancelBtn');
  await page.waitForTimeout(2000);
});

test('Create Natural Person Not Select District', async () => {
  await page.click("(//div[@id='btn-add'])[1]");
  await page.click('id=add-customer-natural-person');
  await page.fill("(//input[@id='input-employer-id'])[3]", 'ปิง');
  await page.fill("(//input[@id='input-tax-no'])[3]", '1242822482204');
  await page.fill("(//input[@id='input-customer-name'])[3]", 'โคโม่');
  await page.fill("(//input[@id='input-customer-name-en'])[3]", 'Como');
  await page.fill("(//input[@id='input-customerName'])[3]", 'ปองพล กันธะณะ');
  await page.fill("(//input[@id='input-address-0'])[3]", '20/02');
  await page.click("(//div[@id='select-province-0'])[3]");
  await page.click("//div[@role='option']");
  await page.fill("(//input[@id='input-address-en-0'])[3]", '20/02');
  await page.click('id=submitBtn');
  await page.waitForTimeout(2000);
  await page.click('id=cancelBtn');
  await page.waitForTimeout(2000);
});

test('Create Natural Person Not Select Sub District', async () => {
  await page.click("(//div[@id='btn-add'])[1]");
  await page.click('id=add-customer-natural-person');
  await page.fill("(//input[@id='input-employer-id'])[3]", 'ปิง');
  await page.fill("(//input[@id='input-tax-no'])[3]", '1242822482204');
  await page.fill("(//input[@id='input-customer-name'])[3]", 'โคโม่');
  await page.fill("(//input[@id='input-customer-name-en'])[3]", 'Como');
  await page.fill("(//input[@id='input-customerName'])[3]", 'ปองพล กันธะณะ');
  await page.fill("(//input[@id='input-address-0'])[3]", '20/02');
  await page.click("(//div[@id='select-province-0'])[3]");
  await page.click("//div[@role='option']");
  await page.click("(//div[@id='select-district-0'])[3]");
  await page.waitForTimeout(1000);
  await page.click("//div[@role='option']");
  await page.fill("(//input[@id='input-address-en-0'])[3]", '20/02');
  await page.click('id=submitBtn');
  await page.waitForTimeout(2000);
  await page.click('id=cancelBtn');
  await page.waitForTimeout(2000);
});

test('Create Natural Person Not Input Address ENG', async () => {
  await page.click("(//div[@id='btn-add'])[1]");
  await page.click('id=add-customer-natural-person');
  await page.fill("(//input[@id='input-employer-id'])[3]", 'ปิง');
  await page.fill("(//input[@id='input-tax-no'])[3]", '1242822482204');
  await page.fill("(//input[@id='input-customer-name'])[3]", 'โคโม่');
  await page.fill("(//input[@id='input-customer-name-en'])[3]", 'Como');
  await page.fill("(//input[@id='input-customerName'])[3]", 'ปองพล กันธะณะ');
  await page.fill("(//input[@id='input-address-0'])[3]", '20/02');
  await page.click("(//div[@id='select-province-0'])[3]");
  await page.click("//div[@role='option']");
  await page.click("(//div[@id='select-district-0'])[3]");
  await page.waitForTimeout(1000);
  await page.click("//div[@role='option']");
  await page.click("(//div[@id='select-sub-district-0'])[3]");
  await page.waitForTimeout(1000);
  await page.click("//div[@role='option']");
  await page.fill("(//input[@id='input-address-en-0'])[3]", '');
  await page.click('id=submitBtn');
  await page.waitForTimeout(2000);
  await page.click('id=cancelBtn');
  await page.waitForTimeout(2000);
});
