#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@File    :   login_page_loctor_check.py
@Time    :   2024/11/06 16:15:39
@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.home_page_locator import HomePageLocator

@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"]
    page.goto("http://10.201.3.146/k3cloud/html5/")
    login_page.login('LTTC1222', '杜立朋', 'TallGiraffe_1')

def test_SEARCH_LOC(page: Page):
    expect(page.locator(HomePageLocator.SEARCH_LOC)).to_be_attached(timeout=10_000)

def test_ORGANIZATION_LOC(page: Page):
    expect(page.locator(HomePageLocator.ORGANIZATION_LOC)).to_be_attached()

def test_ORG_ITEM_ARGS_LOC(page: Page):
    page.locator(HomePageLocator.ORGANIZATION_LOC).click()
    expect(page.locator(HomePageLocator.ORG_ITEM_ARGS_LOC % '100.1')).to_be_attached()

def test_BILL_TAB_ARGS_LOC(page: Page):
    expect(page.locator(HomePageLocator.BILL_TAB_ARGS_LOC % '待办任务列表')).to_be_attached()

def test_BILL_CLOSE_ARGS_LOC(page: Page):
    expect(page.locator(HomePageLocator.BILL_CLOSE_ARGS_LOC % '待办任务列表')).to_be_attached()

def test_ALL_OPEN_FORM_BTN_LOC(page: Page):
    expect(page.locator(HomePageLocator.ALL_OPEN_FORM_BTN_LOC)).to_be_attached()

def test_CLOSE_ALL_BILLS_ITEM_LOC(page: Page):
    page.locator(HomePageLocator.ALL_OPEN_FORM_BTN_LOC).click()
    expect(page.locator(HomePageLocator.CLOSE_ALL_BILLS_ITEM_LOC)).to_be_attached()

def test_BILL_LIST_ARGS_LOC(page: Page, page_object):
    home_page = page_object.get("home_page")
    home_page.search_bill("销售订单")
    expect(page.locator(HomePageLocator.BILL_LIST_ARGS_LOC % ("销售订单", 1))).to_be_attached()

def test_IS_BILL_OPENING_ARGS_LOC(page: Page):
    expect(page.locator(HomePageLocator.IS_BILL_OPENING_ARGS_LOC % '待办任务列表')).to_be_attached()

@pytest.mark.skip
def test_WARNING_MSG_BTN_ARGS_LOC(page: Page):
    expect(page.locator(HomePageLocator.WARNING_MSG_BTN_ARGS_LOC)).to_be_attached()




