Skip to content

**suggestion (testing):** Add tests around the new warningMessage / shouldSkipYouTubeDataApi behavior. #448

@shakeelmohamed

Description

@shakeelmohamed

suggestion (testing): Add tests around the new warningMessage / shouldSkipYouTubeDataApi behavior.

These helpers now change runtime behavior locally / under file:// (warning banner, skipping YouTube Data API, disabling search/autocomplete), but none of the tests assert this.

Please add coverage for at least:

  • When shouldSkipYouTubeDataApi() is true (as in the current Playwright setup), .warning-message is rendered with the expected text.
  • Search/autocomplete in this mode: typeahead is not attached to .search-input, and search still supports direct video ID/URL playback.

You can either extend this Form suite or add a small e2e suite that:

  • Waits for .warning-message and asserts its text.
  • Verifies autocomplete is disabled (e.g., window.getAutocompleteSuggestions is not called or typeahead-specific DOM is absent on .search-input).

Suggested implementation:

        await page.goto(indexHTMLURL);

        // Test that warning message is rendered when YouTube Data API is skipped
        const warningElement = await page.waitForSelector(".warning-message", { state: "visible" });
        const warningText = await warningElement.textContent();
        assert.ok(
          warningText && warningText.toLowerCase().includes("youtube data api"),
          `Warning text should mention YouTube Data API, got: "${warningText}"`
        );

        // Test that error element exists and can be controlled
        const errorElement = await page.$(".error-message");
        assert.ok(errorElement, "Error element should exist");

        // Verify that autocomplete/typeahead is disabled when skipping YouTube Data API
        const searchInput = await page.$(".search-input");
        assert.ok(searchInput, "Search input should exist");

        // Common typeahead.js DOM hooks: no menu / hint inputs should be present
        const typeaheadMenu = await page.$(".tt-menu");
        assert.strictEqual(
          typeaheadMenu,
          null,
          "Typeahead menu (.tt-menu) should not be present when YouTube Data API is skipped"
        );

        const typeaheadHint = await page.$(".tt-hint");
        assert.strictEqual(
          typeaheadHint,
          null,
          "Typeahead hint input (.tt-hint) should not be present when YouTube Data API is skipped"
        );

        // Verify that direct video ID / URL playback still works without autocomplete
        const directVideoId = "dQw4w9WgXcQ";
        await searchInput.fill(directVideoId);
        await searchInput.press("Enter");

        const playerFrame = await page.waitForSelector(
          'iframe[src*="youtube.com"], iframe[src*="youtube-nocookie.com"]',
          { timeout: 10000 }
        );
        assert.ok(playerFrame, "Player iframe should be rendered for direct video ID search");

        // Test that we can programmatically show/hide the error
  1. If your actual warning copy differs, replace the includes("youtube data api") check with a stricter assertion on the exact expected string.
  2. If your autocomplete implementation uses different DOM markers than .tt-menu / .tt-hint, update those selectors to match the actual typeahead-specific elements added in the non-shouldSkipYouTubeDataApi path.
  3. If the search interaction in this form uses a different trigger than pressing Enter on .search-input (e.g., clicking a search button or submitting a specific form), adjust the fill/press logic accordingly to follow the existing tests in test/form.js.
  4. If the player is rendered with a non-iframe container or a different selector than a YouTube iframe, update the waitForSelector to use the actual player element/selector used elsewhere in your e2e tests.

Originally posted by @sourcery-ai[bot] in #447 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions