Untitled

 avatar
unknown
python
2 years ago
3.0 kB
4
Indexable
import time
import os
from rich.prompt import IntPrompt, Confirm
from rich.console import Console
from typing import List
from rich.progress import track
from ui_automation.scripts.generate_tests.utils.get_paths import FilePathAction
from ui_automation.scripts.generate_tests.utils.theme import custom_theme

console = Console(theme=custom_theme)


def check_if_file_already_exist(test_name):
    file_path = os.path.join('src', 'automation', test_name)
    if os.path.exists(path=file_path):
        return True
    return False


def ask_test_type():
    tests_types = ['E2E Test','UI Test']
    x = [f'{n}' for n in range(1, len(tests_types))]
    print(x)
    console.print("🧪 What is your test type?", style='question')
    console.print("\n".join([f'({index}) {item}' for index, item in enumerate(tests_types, start=1)]))
    input_message = "Your choice"
    user_input = IntPrompt.ask(input_message, choices=[f'{n}' for n in range(1, len(tests_types)+1)])
    return user_input


def ask_test_name():
    console.print("🧪 What is your test name? separate by underscore", style='question')
    input_message = 'Your test name: '
    while True:
        user_input = console.input(input_message)
        if not user_input:
            console.print(":face_with_thermometer: [prompt.invalid]Test name is required")
        elif check_if_file_already_exist(user_input):
            console.print(":face_with_thermometer: [prompt.invalid]Test already exist, please choose other name")
        else:
            break
    return user_input


def ask_abstract_class_name(test_name: str):
    abstract_class_name = ''.join(x.title() for x in test_name.split('_'))
    console.print(
        f'🧪 Your abstract class name is [bold #00FFD1]{abstract_class_name}[/], enter a new name or press enter to '
        f'keep the name', style='question')
    user_input = console.input()
    if user_input != '':
        abstract_class_name = user_input
    return abstract_class_name


def ask_approve_files_creation(files_list: List):
    console.print("\n".join([f'[green bold]{x.type.value}[/] [magenta]{x.path}[magenta]' for x in files_list]))
    input_message = "Create test files?:"
    user_input = Confirm.ask(input_message, default=True)
    return user_input


def ask_is_test_flow():
    console.print("🧪 Is your test is part of flow?", style='question')
    user_input = Confirm.ask(default=False)
    return user_input


def prompt_message_inputs():
    console.rule("🧪🧪 Test Generator 🧪🧪", style='#E3FDFD')
    test_type = ask_test_type()
    test_name = ask_test_name()
    abstract_class_name = ask_abstract_class_name(test_name)
    return test_type, test_name, abstract_class_name


def show_processing_files_message():
    for i in track(range(3), description="Creating files..."):
        time.sleep(1)  # Simulate work being done


def show_file_action_message(file: FilePathAction):
    console.print(f'✅  {file.type.value} file: [magenta]{file.path}[/]', style='print_file')
Editor is loading...