Repository: streamlit/streamlit
File: e2e_playwright/st_chat_input_test.py (Python)

Code before:
        name=file_name1,
        mimeType="text/plain",
        buffer=b"x" * (2 * 1024 * 1024),  # 2MB
    )

    expect(app.get_by_text(file_name1)).not_to_be_attached()
    chat_input = get_element_by_key(app, "chat_input_4")
    expect(chat_input).to_be_visible()
    file_upload_helper(app, chat_input, [file1])

    expect(app.get_by_text(file_name1)).to_be_visible()

    uploaded_files = chat_input.get_by_test_id("stChatUploadedFiles").first
    expect(uploaded_files).to_be_visible()
    uploaded_file = uploaded_files.get_by_test_id("stChatInputFile").first
    expect(uploaded_file).to_be_visible()

    uploaded_files.scroll_into_view_if_needed()

    # Reset hovering to not cause issues with the upload tooltip being
    # shown over the uploaded file tooltip hover target:
    reset_hovering(app)
    expect_help_tooltip(app, uploaded_files, "File must be 1.0MB or smaller.")


def test_single_file_upload_button_tooltip(app: Page):
    """Test that the single file upload button tooltip renders correctly."""
    app.set_viewport_size({"width": 750, "height": 2000})

    chat_input_upload_button = get_element_by_key(app, "chat_input_4").get_by_test_id(
        "stChatInputFileUploadButton"
    )
    expect(chat_input_upload_button).to_be_visible()
    chat_input_upload_button.scroll_into_view_if_needed()

    expect_help_tooltip(app, chat_input_upload_button, "Upload or drag and drop a file")
    # Hover on the tooltip hover target


def test_multi_file_upload_button_tooltip(app: Page):
    """Test that the multi file upload button tooltip renders correctly."""
    app.set_viewport_size({"width": 750, "height": 2000})

    chat_input_upload_button = get_element_by_key(app, "chat_input_5").get_by_test_id(
        "stChatInputFileUploadButton"
    )
    expect(chat_input_upload_button).to_be_visible()
    chat_input_upload_button.scroll_into_view_if_needed()

    expect_help_tooltip(app, chat_input_upload_button, "Upload or drag and drop files")


Review comment (bug):
**question:** How sure are we that this fixes the problem? 2 things I noticed:

1. We already skip this test for chromium, and I see in the flaky tests app that Firefox and Webkit are failing too.
2. In the logs from CI runs where this had to be re-run I see:

```
playwright._impl._errors.Error: Locator.click: Element is outside of the viewport
Call log:
  - waiting for locator(".st-key-chat_input_4").get_by_test_id("stChatInputFileUploadButton")
    - locator resolved to <div tabindex="0" role="presentation" data-testid="stChatInputFileUploadButton" class="st-emotion-cache-12m0k8p e15560op3">…</div>
  - attempting click action
    - scrolling into view if needed
    - done scrolling
```

```
AssertionError: Locator expected not to be attached
Actual value: attached 
Call log:
  - Expect "to_be_attached" with timeout 5000ms
  - waiting for get_by_test_id("stTooltipContent")
    9 × locator resolved to <div data-testid="stTooltipContent" class="stTooltipContent st-emotion-cache-c8ft24 etx0m6x2">…</div>
      - unexpected value "attached"
```

All of this is to say, I think this test is already in a bad state given the existing chromium skip flag. If we think this test is valuable, then we need to have high confidence that these changes will actually fix them. If we think this test is covered enough by other use cases (eg: unit tests), then we should consider just deleting it.

Code after:
    # Reset hovering again before hovering on error tooltip to ensure upload tooltip is dismissed
    reset_hovering(themed_app)

    uploaded_files.get_by_test_id("stTooltipHoverTarget").first.hover()
    expect(themed_app.get_by_text("json files are not allowed.")).to_be_visible()


@pytest.mark.skip_browser("chromium")
def test_file_upload_error_message_file_too_large(app: Page):
    """Test that shows error message for files exceeding max size limit."""
    app.set_viewport_size({"width": 750, "height": 2000})

    file_name1 = "large.txt"
    file1 = FilePayload(
        name=file_name1,
        mimeType="text/plain",
        buffer=b"x" * (2 * 1024 * 1024),  # 2MB
    )

    chat_input = get_element_by_key(app, "chat_input_4")
    expect(chat_input).to_be_visible()
    file_upload_helper(app, chat_input, [file1])

    uploaded_files = chat_input.get_by_test_id("stChatUploadedFiles").first
    expect(uploaded_files).to_be_visible()

    # Verify the file appears in the uploaded files list
    expect(uploaded_files.get_by_text(file_name1)).to_be_visible()

    uploaded_file = uploaded_files.get_by_test_id("stChatInputFile").first
    expect(uploaded_file).to_be_visible()

    uploaded_files.scroll_into_view_if_needed()

    # Reset hovering to not cause issues with the upload tooltip being
    # shown over the uploaded file tooltip hover target:
    reset_hovering(app)

    # Ensure the upload button tooltip has disappeared before checking the error tooltip
    expect(app.get_by_text("Upload or drag and drop a file")).not_to_be_attached()

    # Ensure the tooltip hover target is in viewport before hovering (WebKit requirement)
    hover_target = uploaded_files.get_by_test_id("stTooltipHoverTarget")
    hover_target.scroll_into_view_if_needed()

    expect_help_tooltip(app, uploaded_files, "File must be 1.0MB or smaller.")


def test_single_file_upload_button_tooltip(app: Page):
    """Test that the single file upload button tooltip renders correctly."""
    app.set_viewport_size({"width": 750, "height": 2000})