Skip to content

webviewer-ask-ai: e2e functional test implementation#83

Merged
lbittner-pdftron merged 6 commits intomainfrom
e2e-testing-as229-new-tests
Apr 7, 2026
Merged

webviewer-ask-ai: e2e functional test implementation#83
lbittner-pdftron merged 6 commits intomainfrom
e2e-testing-as229-new-tests

Conversation

@Mohammed-AbdulRahman-Apryse
Copy link
Copy Markdown
Collaborator

Using Playwright:

  1. tests\e2e\webviewer-ask-ai.spec.js: The e2e tests implementation
  2. mocks\webviewer-ask-ai.mock.js: The mocking used within e2e tests
  3. playwright.config.js: Playwright configuration
  4. package.json: Adding scripts to start mocking version and start playwright tests
  5. server\serve.js: Injecting the application mode (either default or mocking) in index.html to be used globally.
  6. client\ui\functionMap.js: If mocking mode is activated, empty the ASSISTANT_MESSAGES to avoid OpenAI LLM connection
  7. client\chatbot\chatbot.js: If mocking mode is activated, avoid OpenAI LLM connection and generate mocked AI responses.
  8. server\handler.js: If mocking mode is activated, avoid OpenAI LLM.

Description

Resources

Checklist

  • I understand that this is a public repo and my changes will be publicly visible

If you are adding a new sample

  • I have added an entry to the root level README
  • The name of my sample is consistent with the other samples
  • I have added a README to my sample
  • The sample is fully functional
  • I have updated lerna.json with the new sample name

If you are removing an old sample

  • I have removed the entry from the root level README
  • I have removed the sample from lerna.json

Using Playwright:
1. __tests__\e2e\webviewer-ask-ai.spec.js: The e2e tests implementation
2. __mocks__\webviewer-ask-ai.mock.js: The mocking used within e2e tests
3. playwright.config.js: Playwright configuration
4. package.json: Adding scripts to start mocking version and start playwright tests
5. server\serve.js: Injecting the application mode (either default or mocking) in index.html to be used globally.
6. client\ui\functionMap.js: If mocking mode is activated, empty the ASSISTANT_MESSAGES to avoid OpenAI LLM connection
7. client\chatbot\chatbot.js: If mocking mode is activated, avoid OpenAI LLM connection and generate mocked AI responses.
8. server\handler.js: If mocking mode is activated, avoid OpenAI LLM.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Playwright-based E2E coverage for the webviewer-ask-ai sample by introducing a “mocking mode” that avoids OpenAI/backend calls and provides deterministic client-side mock responses.

Changes:

  • Added Playwright configuration and E2E spec(s) for key UI flows.
  • Introduced a shared mock module and “mocking mode” plumbing across server + client to bypass LLM calls.
  • Updated npm scripts and dependencies to support running E2E tests.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
webviewer-ask-ai/server/serve.js Injects MODE_ENV into index.html and serves mock modules for browser usage.
webviewer-ask-ai/server/handler.js Skips LLM endpoint initialization when mocking mode is enabled.
webviewer-ask-ai/client/ui/functionMap.js Clears initial assistant messages in mocking mode to avoid backend/LLM dependency.
webviewer-ask-ai/client/chatbot/chatbot.js Returns deterministic mock responses when mocking mode is enabled.
webviewer-ask-ai/mocks/webviewer-ask-ai.mock.js Defines mocking-mode detection + canned responses for E2E.
webviewer-ask-ai/tests/e2e/webviewer-ask-ai.spec.js Implements Playwright E2E flows (panel presence, ask question, summarize selection, toggle panel).
webviewer-ask-ai/playwright.config.js Adds Playwright test runner configuration.
webviewer-ask-ai/package.json Adds scripts and devDependencies to run Playwright E2E with mocking mode.
webviewer-ask-ai/package-lock.json Locks updated dependencies used for Playwright + mocking mode.
webviewer-ask-ai/tests/package.playwright.json Adds an extra Playwright-related package file under __tests__.
Files not reviewed (1)
  • webviewer-ask-ai/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Copy Markdown
Contributor

@lbittner-pdftron lbittner-pdftron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start, but it needs a bit of work still.

The point of these tests is to verify that the functionality is working. The tests you have written simulate the functionality, but they do not assert anything.

I would expect an e2e tests for this sample to look something like this (in pseudocode)

-> Mock the server response to return "Hello world"
-> Highlight some text
-> Ask a question through the AskAI UI
-> Assert that the server responds with "Hello world"

1. Removed old mocking from the original source code. Affected files:
  a. client\chatbot\chatbot.js
  b. client\ui\functionMap.js
  c. server\handler.js
  d. __mocks__\webviewer-ask-ai.mock.js
2. Removed injecting mocking mode. Affected files:
  a. package.json
  b. server\serve.js
3. Mocking connection to OpenAI via intercept the /api/chat HTTP call. Affected file __mocks__\webviewer-ask-ai.mock.js
4. Re-write three tests to call the new mocking from __mocks__\webviewer-ask-ai.mock.js when validating the existence of the chatbot toggle button, chatbot panel, and Summarizing selection button. Affected file __tests__\e2e\webviewer-ask-ai.spec.js. The three tests:
  a. Chatbot toggle button exists in DOM
  b. Chatbot panel exists in DOM
  c. Summarizing selection button exists in DOM
5. Exposing global declarations via globalThis. Affected files:
  a. client\globals.js
  b. client\chatbot\chatbot.js
  c. client\ui\functionMap.js
  d. __tests__\e2e\webviewer-ask-ai.spec.js
6. Importing Node.js built-in modules using the "node:". Affected file server\handler.js
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Playwright-based E2E coverage for the “webviewer-ask-ai” sample and introduces supporting infrastructure (server startup behavior + mocking hooks) to run tests reliably without hitting real LLM services.

Changes:

  • Add Playwright configuration + E2E tests and API mocking.
  • Adjust server startup to support Playwright runs (no auto-browser open, stable port defaulting).
  • Update client/server code paths to support test/mocking flows and dependency upgrades.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
webviewer-ask-ai/server/serve.js Adds deterministic port handling and --no-open/NO_OPEN support for Playwright.
webviewer-ask-ai/server/handler.js Refactors export style, node: imports, formatting, and changes error payload behavior.
webviewer-ask-ai/playwright.config.js Introduces Playwright config and webServer integration.
webviewer-ask-ai/package.json Adds Playwright scripts/devDependency and bumps several deps.
webviewer-ask-ai/package-lock.json Lockfile updates for new deps + dependency upgrades.
webviewer-ask-ai/mainsamplesource.json Fixes server entry path reference.
webviewer-ask-ai/client/ui/functionMap.js Refactors summarization handling and changes UI element references to globalThis.
webviewer-ask-ai/client/globals.js Exposes some globals onto globalThis for cross-module usage.
webviewer-ask-ai/client/chatbot/chatbot.js Removes redundant try/catch, uses globalThis for spinner/bubble DOM targets, tweaks contextual question update logic.
webviewer-ask-ai/tests/package.playwright.json Adds an additional Playwright package manifest under __tests__.
webviewer-ask-ai/tests/e2e/webviewer-ask-ai.spec.js New Playwright E2E tests for UI existence and text popup behavior.
webviewer-ask-ai/mocks/webviewer-ask-ai.mock.js Adds /api/chat request mocking for deterministic E2E runs.
Files not reviewed (1)
  • webviewer-ask-ai/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

 1. Indicating the project requires Node >= 20. Affected files:
  a. package.json
  b. readme.md
2. Removed unused depenceies. Affected file package-lock.json.
3. Removed the unused __tests__/package.playwright.json
4. Pass the same timeout to toBeVisible() for consistency. Affected file __tests__\e2e\webviewer-ask-ai.spec.js
5. Avoid leaking internal details from the LLM provider. Affected file server/handler.js
Re-write three tests to call the new mocking from __mocks__\webviewer-ask-ai.mock.js on simulating user asking free question within the chatbot panel, simulating user selecting text on the document and asking the chatbot to summarize it, and simulating user hiding and showing the chatbot panel using the toggle button in the header. Affected file __tests__\e2e\webviewer-ask-ai.spec.js. The three tests:
  a. Ask free question
  b. Summarize selected text
  c. Hide/Show chatbot panel
Ensure "Summarize selection" button visibility before clicking it.
DavidEGutierrez
DavidEGutierrez previously approved these changes Apr 3, 2026
Copy link
Copy Markdown
Collaborator

@DavidEGutierrez DavidEGutierrez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested e2e tests and all pass in silent and UI modes.

Copy link
Copy Markdown

@jiaqihuang-233 jiaqihuang-233 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest looks good to me.

Re-engineered the test to not use shared helper function.
This requires unloading askQuestion helper contents in 'Ask free question' test body, then removing the askQuestion helper.

NOTE: the 'Hide/Show chatbot panel' test was using the same shared helper, so I performed unloading askQuestion helper contents into this test also.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 7, 2026

@lbittner-pdftron lbittner-pdftron merged commit d37dfa0 into main Apr 7, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants