Skip to content

Conversation

Copy link

Copilot AI commented Dec 10, 2025

Summary

Fixes two test failures in the Jasmine test suite for both jQuery and Prototype versions:

Scroll Position Test
The test "should switch from drop-up to drop-down when scrolling down" was scrolling in the wrong direction (decreasing scroll position instead of increasing). Changed to scroll down by 300px to move the element up on screen and verify the correct dropup state is achieved. Applied to both jQuery (spec/jquery/scroll-position.spec.coffee) and Prototype (spec/proto/scroll-position.spec.coffee) test suites.

Normalized Text Highlighting
When using normalize_search_text (e.g., for accent removal), the highlighting algorithm only highlighted query-length characters instead of the full matched portion. Searching "test" against "Testé" would produce <em>Test</em>é instead of <em>Testé</em>.

# Before: Always used query.length for highlighting
match_length = query.length

# After: Use full matched length when normalization changes text
if normalized_text != text
  matched_length_in_normalized = search_match[0].length
  matched_length_in_normalized -= 1 if search_match[1]
  # Find corresponding length in original text...
else
  match_length = query.length  # Preserve original behavior when no normalization

The fix in coffee/lib/abstract-chosen.coffee:

  • Uses full regex match length when text normalization is active
  • Finds the corresponding substring in the original text that normalizes to the matched portion
  • Preserves the original behavior (highlighting only query length) when no normalization occurs

Prototype-Specific Updates

  • Rebuilt dist/js/chosen.proto.js and docs/chosen.proto.js with the highlighting algorithm fix
  • Updated Prototype scroll position tests to use dynamic positioning based on window height
  • Fixed instance access pattern to capture return value of new Chosen()
  • Updated event triggering to use container_mousedown() with mock events

Please double-check that:

  • All changes were made in CoffeeScript files, not JavaScript files.
  • You used Grunt to build the JavaScript files and tested them locally.
  • You've updated both the jQuery and Prototype versions.
  • You haven't manually updated the version number in package.json.
  • If necessary, you've updated the documentation.

References

Related to CI test failures mentioned in issue discussions.

Original prompt

This section details on the original issue you should resolve

<issue_title>Fix remaining 2 Jasmine failures</issue_title>
<issue_description>```
Running "jasmine:jquery" (jasmine) task
Puppeteer old Headless deprecation warning:
In the near feature headless: true will default to the new Headless mode
for Chrome instead of the old Headless implementation. For more
information, please see https://developer.chrome.com/articles/new-headless/.
Consider opting in early by passing `headless: "new"` to `puppeteer.launch()`
If you encounter any bugs, please report them to https://github.com/puppeteer/puppeteer/issues/new/choose.

Testing specs with Jasmine/latest via Chrome/142.0.7444.175
Width handling
min-width for short values
- should allow wider content to expand naturally......✓
- should apply min-width to single select containers......✓
- should display 4-digit years without truncation......✓
- should display short values without truncation......✓
Scroll Position Adjustment

  • should switch from drop-down to drop-up when scrolling up......✓
  • should clean up scroll handler when widget is destroyed......✓
  • should properly register and unregister scroll handler......✓
  • should switch from drop-up to drop-down when scrolling down......X
    Expected true not to be true. (1)

Expected true not to be true. at
at UserContext. (file:///home/runner/work/chosen/chosen/spec/public/jquery_specs.js:266:55)
at

  • should only update position when results are showing......✓
    Basic setup
  • should create very basic chosen......✓
  • should add chosen to jQuery object......✓
  • it should not render hidden optgroups......✓
  • it should not render hidden options......✓
    data-placeholder
    • should render with special characters......✓
    • should handle already-escaped entities in options......✓
    • should handle ampersand in options......✓
    • should render......✓
    • should render with ampersand......✓
      disabled fieldset
    • should render as disabled......✓
      Bugfixes
  • XSS Bug when using the include_group_label_in_selected option harvesthq/chosen#2996 - XSS Vulnerability with include_group_label_in_selected: true......✓
    Events
  • chosen should fire the right events......✓
    search
  • should display only matching items when entering a search term......✓
  • should only show max_shown_results items in results......✓
    Searching
  • should support normalize_search_text callback for searching with accented characters......✓
  • matches in non-ascii languages like Chinese when selecting a single item......✓
  • should properly highlight normalized matches......X
    Expected 'Testé' to contain 'Testé'. (1)

Expected 'Testé' to contain 'Testé'. at
at UserContext. (file:///home/runner/work/chosen/chosen/spec/public/jquery_specs.js:808:34)
at

  • clears search text and highlights first suggestion without ctrl/cmd and selecting multiple items without hide_results_on_select......✓
  • should work with normalize_search_text and search_contains......✓
  • does not clear search text or highlight first suggestion when holding ctrl/cmd and selecting multiple items......✓
  • should not match the actual text of HTML entities......✓
  • renders no results message correctly when it contains characters that require HTML encoding......✓
  • renders optgroups correctly when they contain characters that require HTML encoding when searching......✓
  • renders optgroups correctly when they contain html encoded tags......✓
    respects word boundaries when not using search_contains
    • correctly finds words that start after a(n) angledleftquote......✓
    • correctly finds words that start after a(n) leftsinglequote......✓
    • correctly finds words that start after a(n) guillemet......✓
    • correctly finds words that start after a(n) angledleftsinglequote......✓
    • correctly finds words that start after a(n) leftquote......✓
    • correctly finds words that start after a(n) dash......✓
    • correctly finds words that start after a(n) lparen......✓
    • correctly finds words that start after a(n) period......✓
    • correctly finds words that start after a(n) upsidedownqmark......✓
    • correctly finds words that start after a(n) upsidedownbang......✓
    • correctly finds words that start after a(n) lcurly......✓
    • correctly finds words that start after a(n) lbrace......✓
    • correctly finds words that start after a(n) langle......✓
  • highlights results correctly when multiple words are present......✓
  • renders options correctly when they contain characters that require HTML encoding......✓
  • matches in non-ascii languages like Chinese when selecting multiple items with search_contains......✓
  • matches in non-ascii languages like Chinese when select...

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Dec 10, 2025
Copilot AI changed the title [WIP] Fix remaining 2 Jasmine failures Fix 2 failing Jasmine tests: scroll position and normalized text highlighting Dec 10, 2025
Copilot AI requested a review from JJJ December 10, 2025 08:11
@JJJ JJJ marked this pull request as ready for review December 10, 2025 08:12
Copilot AI review requested due to automatic review settings December 10, 2025 08:12
Copy link

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

This PR attempts to fix two failing Jasmine tests in the jQuery test suite: one related to scroll position adjustment for dropup/dropdown switching, and another related to highlighting normalized search matches. While the fixes to the CoffeeScript source code and jQuery compiled output are correct, the Prototype version was not properly updated, leaving it with the same bugs.

Key Issues:

  • The normalized text highlighting fix in coffee/lib/abstract-chosen.coffee was correctly implemented but only compiled to the jQuery version
  • The scroll position test fix was only applied to the jQuery test spec, not the Prototype test spec
  • The Prototype compiled JavaScript files (docs/chosen.proto.js and dist/js/chosen.proto.js) were not regenerated with the bug fixes

Changes Made:

  • Fixed scroll position test to scroll in the correct direction (down instead of up)
  • Corrected highlighting algorithm to highlight the full matched portion when text normalization is used
  • Added comprehensive comments explaining the O(n²) algorithm complexity

Reviewed changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
spec/jquery/scroll-position.spec.coffee Fixed scroll direction and improved assertions, but Prototype equivalent not updated
coffee/lib/abstract-chosen.coffee Corrected highlighting algorithm to use full match length with text normalization
docs/chosen.jquery.js jQuery compiled output correctly includes the highlighting fix
dist/js/chosen.jquery.js jQuery distribution file correctly includes the highlighting fix
docs/chosen.proto.js Only header comment removed; highlighting fix not compiled into this file
docs/chosen.css.map Source map regenerated with updated relative path

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

Comment on lines 1 to 3
(function() {
var AbstractChosen, SelectParser;

Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

The Prototype version in docs/ was not properly rebuilt with the normalized text highlighting fix. Only the header comment was removed, but the actual bug fix from coffee/lib/abstract-chosen.coffee (lines 240-267) was not applied.

The file needs to be completely regenerated by running npx grunt build to compile the CoffeeScript changes into this JavaScript file. The current version still contains the old buggy highlighting algorithm that doesn't correctly highlight the full matched portion when using normalize_search_text.

Copilot uses AI. Check for mistakes.
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Author

Choose a reason for hiding this comment

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

Fixed in commit 08aded7. The Prototype version has been properly rebuilt with the normalized text highlighting fix from abstract-chosen.coffee. All highlighting logic changes are now applied to both jQuery and Prototype compiled JavaScript files.

Comment on lines +48 to +49
# Scroll down (increase scroll position) to move element up and create more space below
window.scrollTo(0, scrollToMakeDropup + 300)
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

The scroll position test fix was only applied to the jQuery version. The equivalent Prototype test in spec/proto/scroll-position.spec.coffee at line 33 has the same bug (scrolling from 2000 to 1500, which is scrolling UP, not down).

According to the PR checklist, both jQuery and Prototype versions should be updated. The Prototype test should also be fixed to scroll in the correct direction.

Copilot uses AI. Check for mistakes.
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Author

Choose a reason for hiding this comment

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

Fixed in commit 08aded7. The Prototype scroll position test now:

  • Scrolls DOWN (increases scroll position from scrollToMakeDropup to scrollToMakeDropup + 300) to move element up on screen
  • Uses dynamic positioning based on window height (matching jQuery approach)
  • Properly accesses the chosen instance by capturing the return value of new Chosen()
  • Uses container_mousedown() with mock events instead of container.fire()

Both "should switch from drop-up to drop-down when scrolling down" and "should switch from drop-down to drop-up when scrolling up" tests now pass.

Copy link
Author

Copilot AI commented Dec 10, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • accounts.google.com
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome --allow-pre-commit-input --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=Translate,BackForwardCache,AcceptCHFrame,MediaRouter,OptimizationHints --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --disable-sync --enable-automation (dns block)
  • clients2.google.com
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome --allow-pre-commit-input --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=Translate,BackForwardCache,AcceptCHFrame,MediaRouter,OptimizationHints --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --disable-sync --enable-automation (dns block)
  • redirector.gvt1.com
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome --allow-pre-commit-input --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=Translate,BackForwardCache,AcceptCHFrame,MediaRouter,OptimizationHints --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --disable-sync --enable-automation (dns block)
  • safebrowsingohttpgateway.googleapis.com
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome --allow-pre-commit-input --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=Translate,BackForwardCache,AcceptCHFrame,MediaRouter,OptimizationHints --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --disable-sync --enable-automation (dns block)
  • www.google.com
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome --allow-pre-commit-input --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=Translate,BackForwardCache,AcceptCHFrame,MediaRouter,OptimizationHints --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --disable-sync --enable-automation (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@JJJ JJJ merged commit f750c20 into master Dec 10, 2025
1 check failed
@JJJ JJJ deleted the copilot/fix-jasmine-test-failures branch December 10, 2025 08:36
Copilot AI requested a review from JJJ December 10, 2025 08:36
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.

Fix remaining 2 Jasmine failures

2 participants