from pathlib import Path


def test_external_completion_html_is_defined_before_bootstrap_completion_block():
    text = Path('app/admin_ui/pages/tasks.py').read_text(encoding='utf-8')
    marker = 'async def task_detail_bootstrap_page'
    assert marker in text
    section = text[text.index(marker):]
    assignment = 'external_completion_html = _external_channel_completion_form_html(task_id, task, action_code, status, return_to_hidden)'
    use = '{external_completion_html}'
    completion = 'completion_html = ""'
    assert assignment in section
    assert section.index(assignment) < section.index(completion)
    assert section.index(assignment) < section.index(use)
