from lib.login import *


class UserModify001:
    name = 'user_modify_001'
    def teststeps(self):
        wd = GSTORE['wd']

        STEP(1, '点击搜索框')
        user_query = WebDriverWait(wd, 10).until(
            EC.element_to_be_clickable((By.XPATH, "//input[@placeholder='请输入用户名称']"))
        )
        user_query.click()
        sleep(2)

        STEP(2, '填写登录名')
        account_input = WebDriverWait(wd, 10).until(
            EC.presence_of_element_located((By.XPATH, "//input[@placeholder='请输入用户名称']"))
        )
        account_input.clear()
        account_input.send_keys("admin@test1")

        STEP(3, '勾选用户')
        select_click= WebDriverWait(wd, 10).until(
            EC.presence_of_element_located((By.XPATH, "//tbody//tr//td//div//label//span//span"))
        )
        select_click.click()
        sleep(2)

        STEP(4, '点击编辑按钮')
        user_update = WebDriverWait(wd, 10).until(
            EC.element_to_be_clickable((By.XPATH, "//div[contains(@class,'company-edmit-right')]//span[contains(text(),'编辑')]"))
        )
        user_update.click()
        sleep(2)

        STEP(5, '填写用户名称')
        account_name_input = WebDriverWait(wd, 10).until(
            EC.presence_of_element_located((By.XPATH, "//div[@class='el-input el-input--suffix']//input[@placeholder='请输入用户名称']"))
        )
        account_name_input.clear()
        account_name_input.send_keys("admin@update")

        STEP(6, '勾选修改密码按钮')
        user_passwd_click = WebDriverWait(wd, 10).until(
            EC.element_to_be_clickable((By.XPATH, "//div[contains(@class,'dialog-input')]//span[contains(@class,'el-checkbox__inner')]"))
        )
        user_passwd_click.click()
        sleep(2)

        STEP(6, '填写当前用户密码')
        current_passwd = WebDriverWait(wd, 10).until(
            EC.presence_of_element_located(
                (By.XPATH, "//input[contains(@placeholder,'请输当前登录用户的密码')]"))
        )
        current_passwd.clear()
        current_passwd.send_keys("ub@123456")

        STEP(7, '填写新密码')
        newpasswd = WebDriverWait(wd, 10).until(
            EC.presence_of_element_located(
                (By.XPATH, "//input[contains(@placeholder,'必须包含字母（不区分大小写）、数字和特殊字符，至少8个字符')]"))
        )
        newpasswd.clear()
        newpasswd.send_keys("ub@12345678")

        STEP(8, '填写确认密码')
        verify_passwd = WebDriverWait(wd, 10).until(
            EC.presence_of_element_located(
                (By.XPATH, "//input[@placeholder='请确认密码']"))
        )
        verify_passwd.clear()
        verify_passwd.send_keys("ub@12345678")

        STEP(9, '填写用户工号')
        sepasswd_input = WebDriverWait(wd, 10).until(
            EC.presence_of_element_located(
                (By.XPATH, "//input[@placeholder='请输入工号']"))
        )
        sepasswd_input.clear()
        sepasswd_input.send_keys("123456")

        STEP(9, '填写手机号')
        phone = WebDriverWait(wd, 10).until(
            EC.presence_of_element_located(
                (By.XPATH, "//input[@placeholder='请输入手机号码']"))
        )
        phone.clear()
        phone.send_keys("13169131242")

        STEP(10, '填写邮箱')
        sepasswd_input = WebDriverWait(wd, 10).until(
            EC.presence_of_element_located(
                (By.XPATH, "//input[@placeholder='请输入邮箱']"))
        )
        sepasswd_input.clear()
        sepasswd_input.send_keys("12341@qq.com")

        STEP(11, '填写备注')
        user_remark = WebDriverWait(wd, 10).until(
            EC.presence_of_element_located(
                (By.XPATH, "//input[@placeholder='备注']"))
        )
        user_remark.clear()
        user_remark.send_keys("测试用户")

        STEP(12, '点击确认')
        commit = WebDriverWait(wd, 10).until(
            EC.element_to_be_clickable((By.XPATH, "//div[contains(@aria-label,'编辑')]//span[contains(text(),'确 定')]"))
        )
        commit.click()

        STEP(13, '验证是否编辑成功')
        get_menu = WebDriverWait(wd, 10).until(
            EC.visibility_of_element_located((By.XPATH, "//p[@class='el-message__content']"))
        )
        get_menu1 = get_menu.text
        CHECK_POINT('检查是否出现成功提示弹窗', get_menu1 == "操作成功!")
        sleep(2)