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 Personnel พนักงาน ชาย', async () => {
  await page.click('id=menu-icon-personnel-management');
  for (let i = 1; i < 5; i++) {
    await page.click('id=btn-add');
    await page.click('id=btn-add-personne');
    await page.fill('id=input-username', `user${i + 1}`);
    // await page.click('id=select-user-type');
    // await page.click("//span[text()='พนักงาน']");
    await page.click('id=select-user-role');
    await page.click("//span[text()='System']");
    await page.click("//div[@role='option']");
    await page.fill('id=input-first-name', `ทดสอบ${i + 1}`);
    await page.fill('id=input-last-name', `ทดสอบ${i + 1}`);
    await page.fill('id=input-first-name-en', `Firstname${i + 1}`);
    await page.fill('id=input-last-name-en', `Lastname${i + 1}`);
    await page.click('id=select-gender');
    await page.click("//span[text()='ชาย']");
    await page.click('id=input-birth-date');
    await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
    await page.click("//div[text()='2021']");
    await page.click("//div[text()='10']");
    await page.fill('id=input-address', `20/0${i + 1}`);
    await page.click('id=select-province');
    await page.click("//span[text()='เชียงใหม่']");
    await page.click('id=select-district');
    await page.click("//span[text()='เมือง']");
    await page.click('id=select-sub-district');
    await page.click("//span[text()='ช้างเผือก']");
    await page.fill('id=input-address-en', `20/0${i + 1}`);
    await page.fill('id=input-regis-no', `282228222242${i + 1}`);
    await page.click('id=input-start-date');
    await page.click(`//div[text()='1${i + 1}']`);
    await page.click('id=input-retire-date');
    await page.click(`//div[text()='2${i + 1}']`);
    await page.click('id=submitBtn');
    await page.click('id=btn-ok-dialog');
  }
  await page.waitForTimeout(4000);
});

test('Create Personnel พนักงาน หญิง', async () => {
  for (let i = 1; i < 10; i++) {
    await page.click('id=btn-add');
    await page.click('id=btn-add-personne');
    await page.fill('id=input-username', `user${i + 5}`);
    // await page.click('id=select-user-type');
    // await page.click("//span[text()='พนักงาน']");
    await page.click('id=select-user-role');
    await page.click("//span[text()='System']");
    await page.click("//div[@role='option']");
    await page.fill('id=input-first-name', `ทดสอบ${i + 5}`);
    await page.fill('id=input-last-name', `ทดสอบ${i + 5}`);
    await page.fill('id=input-first-name-en', `Firstname${i + 5}`);
    await page.fill('id=input-last-name-en', `Lastname${i + 5}`);
    await page.click('id=select-gender');
    await page.click("//span[text()='หญิง']");
    await page.click('id=input-birth-date');
    await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
    await page.click("//div[text()='2021']");
    await page.click("//div[text()='10']");
    await page.fill('id=input-address', `20/0${i + 5}`);
    await page.click('id=select-province');
    await page.click("//span[text()='เชียงใหม่']");
    await page.click('id=select-district');
    await page.click("//span[text()='เมือง']");
    await page.click('id=select-sub-district');
    await page.click("//span[text()='ช้างเผือก']");
    await page.fill('id=input-address-en', `20/0${i + 5}`);
    await page.fill('id=input-regis-no', `282228222242${i + 5}`);
    await page.click('id=input-start-date');
    await page.click(`//div[text()='1${i + 5}']`);
    await page.click('id=input-retire-date');
    await page.click(`//div[text()='2${i + 5}']`);
    await page.click('id=submitBtn');
    await page.click('id=btn-ok-dialog');
  }
  await page.waitForTimeout(4000);
});

test('Create Personnel พนักงานส่งเอกสาร ชาย', async () => {
  for (let i = 1; i < 5; i++) {
    await page.click('id=btn-add');
    await page.click('id=btn-add-personne');
    await page.fill('id=input-username', `user0${i + 1}`);
    await page.click('id=select-user-type');
    await page.click("//span[text()='พนักงานส่งเอกสาร']");
    await page.click('id=select-user-role');
    await page.click("//span[text()='System']");
    await page.click("//div[@role='option']");
    await page.fill('id=input-first-name', `ทดสอบ${i + 1}`);
    await page.fill('id=input-last-name', `ทดสอบ${i + 1}`);
    await page.fill('id=input-first-name-en', `Firstname${i + 1}`);
    await page.fill('id=input-last-name-en', `Lastname${i + 1}`);
    await page.click('id=select-gender');
    await page.click("//span[text()='ชาย']");
    await page.click('id=input-birth-date');
    await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
    await page.click("//div[text()='2021']");
    await page.click("//div[text()='10']");
    await page.fill('id=input-address', `20/0${i + 1}`);
    await page.click('id=select-province');
    await page.click("//span[text()='เชียงใหม่']");
    await page.click('id=select-district');
    await page.click("//span[text()='เมือง']");
    await page.click('id=select-sub-district');
    await page.click("//span[text()='ช้างเผือก']");
    await page.fill('id=input-address-en', `20/0${i + 1}`);
    await page.fill('id=input-regis-no', `282228222222${i + 1}`);
    await page.click('id=input-start-date');
    await page.click(`//div[text()='1${i + 1}']`);
    await page.click('id=input-retire-date');
    await page.click(`//div[text()='2${i + 1}']`);
    await page.click('id=submitBtn');
    await page.click('id=btn-ok-dialog');
  }
  await page.waitForTimeout(4000);
});

test('Create Personnel พนักงานส่งเอกสาร หญิง', async () => {
  for (let i = 1; i < 10; i++) {
    await page.click('id=btn-add');
    await page.click('id=btn-add-personne');
    await page.fill('id=input-username', `user0${i + 5}`);
    await page.click('id=select-user-type');
    await page.click("//span[text()='พนักงานส่งเอกสาร']");
    await page.click('id=select-user-role');
    await page.click("//span[text()='System']");
    await page.click("//div[@role='option']");
    await page.fill('id=input-first-name', `ทดสอบ${i + 5}`);
    await page.fill('id=input-last-name', `ทดสอบ${i + 5}`);
    await page.fill('id=input-first-name-en', `Firstname${i + 5}`);
    await page.fill('id=input-last-name-en', `Lastname${i + 5}`);
    await page.click('id=select-gender');
    await page.click("//span[text()='หญิง']");
    await page.click('id=input-birth-date');
    await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
    await page.click("//div[text()='2021']");
    await page.click("//div[text()='10']");
    await page.fill('id=input-address', `20/0${i + 5}`);
    await page.click('id=select-province');
    await page.click("//span[text()='เชียงใหม่']");
    await page.click('id=select-district');
    await page.click("//span[text()='เมือง']");
    await page.click('id=select-sub-district');
    await page.click("//span[text()='ช้างเผือก']");
    await page.fill('id=input-address-en', `20/0${i + 5}`);
    await page.fill('id=input-regis-no', `282228222224${i + 5}`);
    await page.click('id=input-start-date');
    await page.click(`//div[text()='1${i + 5}']`);
    await page.click('id=input-retire-date');
    await page.click(`//div[text()='2${i + 5}']`);
    await page.click('id=submitBtn');
    await page.click('id=btn-ok-dialog');
  }
  await page.waitForTimeout(4000);
});

test('Create Personnel ตัวแทน ชาย', async () => {
  for (let i = 1; i < 5; i++) {
    await page.click('id=btn-add');
    await page.click('id=btn-add-personne');
    await page.fill('id=input-username', `user00${i + 1}`);
    await page.click('id=select-user-type');
    await page.click("//span[text()='ตัวแทน']");
    await page.click('id=select-user-role');
    await page.click("//span[text()='System']");
    await page.click("//div[@role='option']");
    await page.fill('id=input-first-name', `ทดสอบ${i + 1}`);
    await page.fill('id=input-last-name', `ทดสอบ${i + 1}`);
    await page.fill('id=input-first-name-en', `Firstname${i + 1}`);
    await page.fill('id=input-last-name-en', `Lastname${i + 1}`);
    await page.click('id=select-gender');
    await page.click("//span[text()='ชาย']");
    await page.click('id=input-birth-date');
    await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
    await page.click("//div[text()='2021']");
    await page.click("//div[text()='10']");
    await page.fill('id=input-address', `20/0${i + 1}`);
    await page.click('id=select-province');
    await page.click("//span[text()='เชียงใหม่']");
    await page.click('id=select-district');
    await page.click("//span[text()='เมือง']");
    await page.click('id=select-sub-district');
    await page.click("//span[text()='ช้างเผือก']");
    await page.fill('id=input-address-en', `20/0${i + 1}`);
    await page.click('id=submitBtn');
    await page.click('id=btn-ok-dialog');
  }
  await page.waitForTimeout(4000);
});

test('Create Personnel ตัวแทน หญิง', async () => {
  for (let i = 1; i < 10; i++) {
    await page.click('id=btn-add');
    await page.click('id=btn-add-personne');
    await page.fill('id=input-username', `user00${i + 5}`);
    await page.click('id=select-user-type');
    await page.click("//span[text()='ตัวแทน']");
    await page.click('id=select-user-role');
    await page.click("//span[text()='System']");
    await page.click("//div[@role='option']");
    await page.fill('id=input-first-name', `ทดสอบ${i + 5}`);
    await page.fill('id=input-last-name', `ทดสอบ${i + 5}`);
    await page.fill('id=input-first-name-en', `Firstname${i + 5}`);
    await page.fill('id=input-last-name-en', `Lastname${i + 5}`);
    await page.click('id=select-gender');
    await page.click("//span[text()='หญิง']");
    await page.click('id=input-birth-date');
    await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
    await page.click("//div[text()='2021']");
    await page.click("//div[text()='10']");
    await page.fill('id=input-address', `20/0${i + 5}`);
    await page.click('id=select-province');
    await page.click("//span[text()='เชียงใหม่']");
    await page.click('id=select-district');
    await page.click("//span[text()='เมือง']");
    await page.click('id=select-sub-district');
    await page.click("//span[text()='ช้างเผือก']");
    await page.fill('id=input-address-en', `20/0${i + 5}`);
    await page.click('id=submitBtn');
    await page.click('id=btn-ok-dialog');
  }
  await page.waitForTimeout(4000);
});

test('Create Personnel เอเจนซี่ ชาย', async () => {
  for (let i = 1; i < 5; i++) {
    await page.click('id=btn-add');
    await page.click('id=btn-add-personne');
    await page.fill('id=input-username', `user000${i + 1}`);
    await page.click('id=select-user-type');
    await page.click("//span[text()='เอเจนซี่']");
    await page.click('id=select-user-role');
    await page.click("//span[text()='System']");
    await page.click("//div[@role='option']");
    await page.fill('id=input-first-name', `ทดสอบ${i + 1}`);
    await page.fill('id=input-last-name', `ทดสอบ${i + 1}`);
    await page.fill('id=input-first-name-en', `Firstname${i + 1}`);
    await page.fill('id=input-last-name-en', `Lastname${i + 1}`);
    await page.click('id=select-gender');
    await page.click("//span[text()='ชาย']");
    await page.click('id=input-birth-date');
    await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
    await page.click("//div[text()='2021']");
    await page.click("//div[text()='10']");
    await page.fill('id=input-address', `20/0${i + 1}`);
    await page.click('id=select-province');
    await page.click("//span[text()='เชียงใหม่']");
    await page.click('id=select-district');
    await page.click("//span[text()='เมือง']");
    await page.click('id=select-sub-district');
    await page.click("//span[text()='ช้างเผือก']");
    await page.fill('id=input-address-en', `20/0${i + 1}`);
    await page.click('id=input-source-nationality');
    await page.click("(//span[text()='ไทย'])[2]");
    await page.click('id=input-import-nationality');
    await page.click("(//span[text()='ไทย'])[3]");
    await page.click('id=select-trainig-place');
    await page.click("//span[text()='สถานที่อบรมแรงงานเมียนมา-แม่สอด จ.ตาก']");
    await page.fill('id=input-checkpoint', 'แม่สอด');
    await page.fill('id=input-checkpoint-en', 'Maesod');
    await page.click('id=submitBtn');
    await page.click('id=btn-ok-dialog');
  }
  await page.waitForTimeout(4000);
});

test('Create Personnel เอเจนซี่ หญิง', async () => {
  for (let i = 1; i < 10; i++) {
    await page.click('id=btn-add');
    await page.click('id=btn-add-personne');
    await page.fill('id=input-username', `user000${i + 5}`);
    await page.click('id=select-user-type');
    await page.click("//span[text()='เอเจนซี่']");
    await page.click('id=select-user-role');
    await page.click("//span[text()='System']");
    await page.click("//div[@role='option']");
    await page.fill('id=input-first-name', `ทดสอบ${i + 5}`);
    await page.fill('id=input-last-name', `ทดสอบ${i + 5}`);
    await page.fill('id=input-first-name-en', `Firstname${i + 5}`);
    await page.fill('id=input-last-name-en', `Lastname${i + 5}`);
    await page.click('id=select-gender');
    await page.click("//span[text()='หญิง']");
    await page.click('id=input-birth-date');
    await page.click("(//button[@class='dp__btn dp__month_year_select'])[2]");
    await page.click("//div[text()='2021']");
    await page.click("//div[text()='10']");
    await page.fill('id=input-address', `20/0${i + 5}`);
    await page.click('id=select-province');
    await page.click("//span[text()='เชียงใหม่']");
    await page.click('id=select-district');
    await page.click("//span[text()='เมือง']");
    await page.click('id=select-sub-district');
    await page.click("//span[text()='ช้างเผือก']");
    await page.fill('id=input-address-en', `20/0${i + 5}`);
    await page.click('id=input-source-nationality');
    await page.click("(//span[text()='ไทย'])[2]");
    await page.click('id=input-import-nationality');
    await page.click("(//span[text()='ไทย'])[3]");
    await page.click('id=select-trainig-place');
    await page.click("//span[text()='สถานที่อบรมแรงงานเมียนมา-แม่สอด จ.ตาก']");
    await page.fill('id=input-checkpoint', 'แม่สอด');
    await page.fill('id=input-checkpoint-en', 'Maesod');
    await page.click('id=submitBtn');
    await page.click('id=btn-ok-dialog');
  }
  await page.waitForTimeout(4000);
});
