#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@File    :   head_page_loctor_check.py
@Time    :   2024/11/07 15:50:19
@Author  :   dulip3ng 
@Version :   1.0
@Desc    :   None
'''

import pytest
from playwright.sync_api import expect, Page
from pages.login_page import LoginPage
from pages.home_page import HomePage
from pages.locator.head_page_locator import HeadPageLocator


"""
    #按钮等相关定位
    BLANK_LOC = "//a[contains(@id, '-FBTNDATACENTER-FBTNDATACENTER')]"
    BUTTON_ARGS_LOC = "//div[contains(@id, '-FMAINTAB_c-') and @class='k-content k-state-active']//div[contains(@id, '-BILLMENU_TOOLBAR')]/ul/li[contains(@class, 'k-item k-state-default kdmenuitem') and not(contains(@class, 'kd-menubtn-disabled'))]/span/span[text()='%s']"
    BUTTON_ARROW_ARGS_LOC = "//div[contains(@id, '-FMAINTAB_c-') and @class='k-content k-state-active']//div[contains(@id, '-BILLMENU_TOOLBAR')]/ul/li[contains(@class, 'k-item k-state-default kdmenuitem') and not(contains(@class, 'kd-menubtn-disabled'))]/span/span[text()='%s']/following-sibling::span"
    SUB_BUTTON_ARGS_LOC = "//div[contains(@id, '-FMAINTAB_c-') and @class='k-content k-state-active']//div[contains(@id, '-BILLMENU_TOOLBAR')]/ul/li[contains(@class, 'k-item k-state-default kdmenuitem') and not(contains(@class, 'kd-menubtn-disabled'))]//span[text()='%s']"
    SHEET_ARGS_LOC = "//div[contains(@id, '-FMAINTAB_c-') and @class='k-content k-state-active']//div[contains(@id, 'SPLITECONTAINER') and @splitter='first']//ul[@class  = 'k-tabstrip-items k-reset']/descendant::span[text()='%s']"
    #字段赋值相关定位
    TEXT_FIELD_ARGS_LOC = "//div[contains(@id, '-FMAINTAB_c-') and @class='k-content k-state-active']//div[contains(@id, 'SPLITECONTAINER') and @splitter='first']//div[contains(@id, 'TAB') and @class = 'k-content k-state-active']//span[translate(text(), ' ', '') = translate('%s', ' ', '')]/parent::div/following-sibling::div[1]/descendant::input[1]"
    BASE_FIELD_ARGS_LOC = "//div[contains(@id, '-FMAINTAB_c-') and @class='k-content k-state-active']//div[contains(@id, 'SPLITECONTAINER') and @splitter='first']//div[contains(@id, 'TAB') and @class = 'k-content k-state-active']//span[translate(text(), ' ', '') = translate('%s', ' ', '')]/parent::div/following-sibling::div[1]/descendant::input[1]"
    BASE_FIELD_SPAN_ARGS_LOC = "//div[contains(@id, '-FMAINTAB_c-') and @class='k-content k-state-active']//div[contains(@id, 'SPLITECONTAINER') and @splitter='first']//div[contains(@id, 'TAB') and @class = 'k-content k-state-active']//span[translate(text(), ' ', '') = translate('%s', ' ', '')]/parent::div/following-sibling::div[1]/descendant::input/following-sibling::span"
    BASE_ITEM_ARGS_LOC = "//div[@class = 'k-animation-container' and contains(@style, 'display: block')]//table[@class = 'k-selectable']/descendant::td[text() = '%s']"
    SELECT_FIELD_ARGS_LOC = "//div[contains(@id, '-FMAINTAB_c-') and @class='k-content k-state-active']//div[contains(@id, 'SPLITECONTAINER') and @splitter='first']//div[contains(@id, 'TAB') and @class = 'k-content k-state-active']//span[translate(text(), ' ', '') = translate('%s', ' ', '')]/parent::div/following-sibling::div[1]//span[@class = 'k-select']"
    SELECT_ITEM_ARGS_LOC = "//div[@class = 'k-animation-container']/div/div[2]/ul/li[text() = '%s']"
    #获取字段值相关定位
    TEXT_VALUE_INPUT_ARGS_LOC = "//div[contains(@id, '-FMAINTAB_c-') and @class='k-content k-state-active']//div[contains(@id, 'SPLITECONTAINER') and @splitter='first']//div[contains(@id, 'TAB') and @class = 'k-content k-state-active']//span[@role='kdspanlabel' and @title = '%s']/parent::div/following-sibling::div[contains(@class, 'kdItemContainer_editorct')]//input"
    TEXT_VALUE_SPAN_ARGS_LOC = "//div[contains(@id, '-FMAINTAB_c-') and @class='k-content k-state-active']//div[contains(@id, 'SPLITECONTAINER') and @splitter='first']//div[contains(@id, 'TAB') and @class = 'k-content k-state-active']//span[@role='kdspanlabel' and @title = '%s']/parent::div/following-sibling::div[1]/descendant::span[@class = 'ui-poplistedit-displayname']"
    SELECT_VALUE_ARGS_LOC = "//div[contains(@id, '-FMAINTAB_c-') and @class='k-content k-state-active']//div[contains(@id, 'SPLITECONTAINER') and @splitter='first']//div[contains(@id, 'TAB') and @class = 'k-content k-state-active']//span[@role='kdspanlabel' and @title = '%s']/parent::div/following-sibling::div[contains(@class, 'kdItemContainer_editorct')]//*[@class='k-input']"
    BASE_VALUE_ARGS_LOC = "//div[contains(@id, '-FMAINTAB_c-') and @class='k-content k-state-active']//div[contains(@id, 'SPLITECONTAINER') and @splitter='first']//div[contains(@id, 'TAB') and @class = 'k-content k-state-active']//span[translate(text(), ' ', '') = translate('%s', ' ', '')]/parent::div/following-sibling::div[1]/descendant::span[@class='ui-poplistedit-displayname']"
    #字段类型解析相关定位
    IS_SELECT_FIELD_ARGS_LOC = "//div[contains(@id, '-FMAINTAB_c-') and @class='k-content k-state-active']//div[contains(@id, 'SPLITECONTAINER') and @splitter='first']//div[contains(@id, 'TAB') and @class = 'k-content k-state-active']//span[translate(text(), ' ', '') = translate('%s', ' ', '')]/parent::div/following-sibling::div[1]//span[@class = 'k-icon k-i-arrow-s']"
    IS_BASE_FIELD_ARGS_LOC = "//div[contains(@id, '-FMAINTAB_c-') and @class='k-content k-state-active']//div[contains(@id, 'SPLITECONTAINER') and @splitter='first']//div[contains(@id, 'TAB') and @class = 'k-content k-state-active']//span[translate(text(), ' ', '') = translate('%s', ' ', '')]/parent::div/following-sibling::div[1]//span[@class = 'k-icon k-i-search']"
    PARSE_FIELD_TYPE_ARGS_LOC = "//div[contains(@id, '-FMAINTAB_c-') and @class='k-content k-state-active']//div[contains(@id, 'SPLITECONTAINER') and @splitter='first']//div[contains(@id, 'TAB') and @class = 'k-content k-state-active']//span[@role='kdspanlabel' and translate(@title, ' ', '') = translate('%s', ' ', '')]/parent::div/following-sibling::div[contains(@class, 'kdItemContainer_editorct')]/div"
    #错误信息相关定位
    ERROR_MESSAGE_LOC = ".//*[contains(@id,'-POPFLOATEERRMESSAGE')]/div[1]/span"
    ERROR_MSG_BUTTON_LOC = "//*[contains(@id,'-POPFLOATEERRMESSAGE')]/div[3]/button[1]"
    ERROR_MESSAGE_DETAIL_LOC = ".//span[@class = 'kd-msg-details']"
    WARNING_MESSAGE_LOC = ".//*[contains(@id,'-POPFLOATEMESSAGE')]/div[1]/span"
    WARNING_MSG_BUTTON_ARGS_LOC = "//div[contains(@id,'-POPFLOATEMESSAGE')]/div[contains(@id, 'btn')]/button[text() = '%s']"
    #审核印章
    CHECKED_IMAGE_LOC = "//img[@src = '.././images/biz/default/Common/WaterMarks/approved_2052.png' and contains(@style, 'display: block')]"
"""
@pytest.fixture(scope="module")
def page_object(page: Page):
    login_page = LoginPage(page)
    home_page = HomePage(page)
    return {"login_page": login_page, "home_page":home_page}

@pytest.fixture(scope="module", autouse=True)
def login(page: Page, page_object):
    login_page = page_object["login_page"]
    home_page = page_object["home_page"]
    page.goto("http://10.201.3.146/k3cloud/html5/")
    login_page.login('LTTC1222', '杜立朋', 'TallGiraffe_1')
    page.wait_for_load_state(state="networkidle", timeout=60000)
    home_page.search_bill("销售订单")
    page.wait_for_load_state(state="networkidle", timeout=60000)

def test_BLANK_LOC(page: Page):
    expect(page.locator(HeadPageLocator.BLANK_LOC)).to_be_attached()

def test_BUTTON_ARGS_LOC(page: Page):
    expect(page.locator(HeadPageLocator.BUTTON_ARGS_LOC % "保存")).to_be_attached()

def test_BUTTON_ARROW_ARGS_LOC(page: Page):
    expect(page.locator(HeadPageLocator.BUTTON_ARROW_ARGS_LOC % "保存")).to_be_attached()

def test_SUB_BUTTON_ARGS_LOC(page: Page):
    page.locator(HeadPageLocator.BUTTON_ARROW_ARGS_LOC % "保存").hover()
    expect(page.locator(HeadPageLocator.SUB_BUTTON_ARGS_LOC % "复制")).to_be_attached()

def test_SHEET_ARGS_LOC(page: Page):
    expect(page.locator(HeadPageLocator.SHEET_ARGS_LOC % "合同跟踪")).to_be_attached()

def test_TEXT_FIELD_ARGS_LOC(page: Page):
    expect(page.locator(HeadPageLocator.TEXT_FIELD_ARGS_LOC % "销售合同号")).to_be_attached()

def test_BASE_FIELD_ARGS_LOC(page: Page):
    expect(page.locator(HeadPageLocator.BASE_FIELD_ARGS_LOC % "生产类型")).to_be_attached()

def test_BASE_FIELD_SPAN_ARGS_LOC(page: Page):
    expect(page.locator(HeadPageLocator.BASE_FIELD_SPAN_ARGS_LOC % "生产类型")).to_be_attached()
@pytest.mark.skip
def test_BASE_ITEM_ARGS_LOC(page: Page):
    expect(page.locator(HeadPageLocator.BASE_ITEM_ARGS_LOC % "部件")).to_be_attached()

def test_SELECT_FIELD_ARGS_LOC(page: Page):
    expect(page.locator(HeadPageLocator.SELECT_FIELD_ARGS_LOC % "业务类型")).to_be_attached()

@pytest.mark.skip
def test_SELECT_ITEM_ARGS_LOC(page: Page):
    expect(page.locator(HeadPageLocator.SELECT_ITEM_ARGS_LOC % "直运销售")).to_be_attached()

def test_TEXT_VALUE_ARGS_LOC(page: Page):
    """
    :param page:
    :return:
    """
    expect(page.locator(HeadPageLocator.TEXT_VALUE_INPUT_ARGS_LOC % "销售合同号")).to_be_attached()
    expect(page.locator(HeadPageLocator.TEXT_VALUE_SPAN_ARGS_LOC % "价税合计")).to_be_attached()

def test_SELECT_VALUE_ARGS_LOC(page: Page):
    expect(page.locator(HeadPageLocator.SELECT_VALUE_ARGS_LOC % "数据来源")).to_be_attached()

def test_BASE_VALUE_ARGS_LOC(page: Page):
    expect(page.locator(HeadPageLocator.BASE_VALUE_ARGS_LOC % "销售类别")).to_be_attached()

def test_IS_SELECT_FIELD_ARGS_LOC(page: Page):
    expect(page.locator(HeadPageLocator.IS_SELECT_FIELD_ARGS_LOC % "业务类型")).to_be_attached()

def test_IS_BASE_FIELD_ARGS_LOC(page: Page):
    expect(page.locator(HeadPageLocator.IS_BASE_FIELD_ARGS_LOC % "销售类别")).to_be_attached()

def test_PARSE_FIELD_TYPE_ARGS_LOC(page: Page):
    expect(page.locator(HeadPageLocator.PARSE_FIELD_TYPE_ARGS_LOC % "销售类别")).to_be_attached()
