Skip to content

WEBUI-1990: exclude non-unit-testable files from sonar coverage metrics : [LTS-2023]#3158

Merged
swarnadipa-dev merged 3 commits into
maintenance-3.1.xfrom
fix-WEBUI-1990-exclude-non-unit-tests-from-sonar
May 18, 2026
Merged

WEBUI-1990: exclude non-unit-testable files from sonar coverage metrics : [LTS-2023]#3158
swarnadipa-dev merged 3 commits into
maintenance-3.1.xfrom
fix-WEBUI-1990-exclude-non-unit-tests-from-sonar

Conversation

@swarnadipa-dev

Copy link
Copy Markdown
Contributor

Copilot AI review requested due to automatic review settings May 18, 2026 06:29
@swarnadipa-dev swarnadipa-dev requested a review from a team as a code owner May 18, 2026 06:29
@swarnadipa-dev swarnadipa-dev requested review from AnilKumarVanga and vaibhavagarwal4-lab and removed request for a team May 18, 2026 06:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates SonarCloud coverage configuration to exclude files considered impractical for Karma unit-test coverage, aligning Sonar metrics with the current frontend test setup.

Changes:

  • Expands sonar.coverage.exclusions across assets, bootstrap files, selected addon areas, themes, and CI config.
  • Adds explanatory comments documenting the exclusion categories.

Comment thread sonar-project.properties Outdated
Comment thread sonar-project.properties Outdated
Comment thread sonar-project.properties Outdated
Comment thread sonar-project.properties Outdated
@swarnadipa-dev swarnadipa-dev changed the title added files that are realistically not testable in sonar exclusions WEBUI-1990: exclude non-unit-testable files from sonar coverage metrics May 18, 2026
@swarnadipa-dev swarnadipa-dev changed the title WEBUI-1990: exclude non-unit-testable files from sonar coverage metrics WEBUI-1990: exclude non-unit-testable files from sonar coverage metrics : [LTS-2023] May 18, 2026
@sonarqubecloud

Copy link
Copy Markdown

@swarnadipa-dev swarnadipa-dev merged commit 7ebe4f4 into maintenance-3.1.x May 18, 2026
14 of 15 checks passed
@swarnadipa-dev swarnadipa-dev deleted the fix-WEBUI-1990-exclude-non-unit-tests-from-sonar branch May 18, 2026 09:23
swarnadipa-dev added a commit that referenced this pull request May 20, 2026
…cs : [LTS-2023] (#3158)

* added files that are realistically not testable in sonar exclusions

* WEBUI-1990: refine coverage exclusions — include testable spreadsheet/S3 modules

* addressed copilot review comments
swarnadipa-dev added a commit that referenced this pull request May 28, 2026
…cs : [LTS-2023] (#3158)

* added files that are realistically not testable in sonar exclusions

* WEBUI-1990: refine coverage exclusions — include testable spreadsheet/S3 modules

* addressed copilot review comments
swarnadipa-dev added a commit that referenced this pull request Jun 2, 2026
…cs : [LTS-2023] (#3158)

* added files that are realistically not testable in sonar exclusions

* WEBUI-1990: refine coverage exclusions — include testable spreadsheet/S3 modules

* addressed copilot review comments
swarnadipa-dev added a commit that referenced this pull request Jun 3, 2026
…cs : [LTS-2023] (#3158)

* added files that are realistically not testable in sonar exclusions

* WEBUI-1990: refine coverage exclusions — include testable spreadsheet/S3 modules

* addressed copilot review comments
swarnadipa-dev added a commit that referenced this pull request Jun 3, 2026
* WEBUI-1916 drive actions buttons should handle error properly when drive not installed on user machine

* show error toast for edit with drive when drive not installed

* fixed Copilot review comments. added unit tests

* fixed blur logic. added unit tests

* addressed copilot review comments

* removed app.js changes

* removed app.js changes

* fix i18n key ordering: sort drive keys alphabetically

Agent-Logs-Url: https://github.com/nuxeo/nuxeo-web-ui/sessions/cae1105b-e38f-4389-8f71-dee2a5578314

Co-authored-by: swarnadipa-dev <67375320+swarnadipa-dev@users.noreply.github.com>

* show install dialog when Drive is not installed across Chrome/Edge/Safari/Firefox

* refactored code and updated unit tests

* removed unwanted merge markers.

* removed duplicate code. fixed lint

* addressed sonar quality issues

* addressed sonar quality issues

* addressed sonar quality issues

* addressed sonar quality issues

* addressed sonar quality issues

* fixed lint issue

* WEBUI-2002 : Upgrade ESLint and @eslint/js to v10 (#3111)

* WEBUI-1990: added sonar configurations [LTS-2023] (#3102)

* WEBUI-1990: added sonar configurations [LTS-2023]

* added quality gates config

* added/updated sonar configuration

* added/updated sonar configuration

* removed overall coverage check

* WEBUI-1990: fix sonar branch detection and add push trigger [LTS-2023] (#3125)

* WEBUI-1990: fix sonar branch detection and add push trigger on base branch

* fix: use single quotes in node -p to avoid shell quote nesting issue

* fix(sonar): use PR decoration params on pull_request events instead of branch analysis (#3127)

* fix(sonar): include addon test directories in sonar.tests and sonar.test.inclusions (#3131)

* fix(sonar): include addon test directories in sonar.tests and sonar.test.inclusions

Addon unit tests (addons/*/test/**/*.test.js) were not registered with
SonarCloud because sonar.tests only pointed to the root test/ directory.
This caused coverage for addon source files to show as N/A instead of
being measured, allowing the Quality Gate coverage condition to be skipped.

Add all addon test directories with test files to sonar.tests and
expand sonar.test.inclusions to match addons/*/test/**/*.test.js.

* fix(sonar): format sonar.tests as multi-line for readability

* fix(sonar): exclude addons/**/test/** from sonar.sources to prevent double-indexing

Addon test directories are now listed in both sonar.sources (via the
addons/ root) and sonar.tests. This causes them to be analyzed as both
source and test code. Adding addons/**/test/** to sonar.exclusions ensures
they are only processed as test code, not source.

* WEBUI-1990: declare addon test dirs as test code in sonar-project.properties [LTS-2023] (#3135)

* WEBUI-1990: removed addon test from exclusions

* WEBUI-1990: removed addon test from exclusions

* WEBUI-1990: removed addona from exclusions

* WEBUI-1990: fix sonar.tests source/test overlap (#3142)

sonar.sources includes 'addons' and sonar.tests listed entire addon
directories (e.g. addons/nuxeo-csv), causing a source/test overlap
that made the scanner fail with exit code 3.

Revert sonar.tests to list only the test/ subdirectories and
sonar.test.inclusions to addons/*/test/**/*.test.js.

* WEBUI-2015 : lock JavaScript dependency versions with npm ci [LTS-2023] (#3136)

* WEBUI-2015 : lock JavaScript dependency versions with npm ci

* WEBUI-2015 : sync lockfiles after package.json modifications in CI

* WEBUI-2015 : remove dual-branch-pr prompt file

* WEBUI-2015 : address PR review comments

- Bump catalog.yaml Node version from 14 to 18 (lockfileVersion 3 compat)
- Add --no-package-lock to RC install steps in test, sonar, a11y workflows
- Add --no-package-lock to nuxeo-elements installs in preview workflow
- Change preinstall script to use npm ci instead of npm install

* Suprressing sonar issues for yaml files

* Fixes

* Additional fixes

* Additional fixes

* WEBUI-2017 WEBUI-2018 : define permissions at job level in workflow files (#3155)

* WEBUI-1990: exclude non-unit-testable files from sonar coverage metrics : [LTS-2023] (#3158)

* added files that are realistically not testable in sonar exclusions

* WEBUI-1990: refine coverage exclusions — include testable spreadsheet/S3 modules

* addressed copilot review comments

* fix: prevent dialog toggle loop with no-cancel-on-outside-click and on-click

* fix(lint): remove unused uaStub variable in nuxeo-drive-protocol-handler.test.js

Agent-Logs-Url: https://github.com/nuxeo/nuxeo-web-ui/sessions/664057c6-0a03-49b6-9668-cee488342c04

Co-authored-by: swarnadipa-dev <67375320+swarnadipa-dev@users.noreply.github.com>

* fix: format long line in Safari test setup to respect Prettier printWidth

* WEBUI-1916: Drive action buttons handle failure gracefully

- Use window blur event to detect Drive app launch (no timeouts)
- Show failure message only when Drive doesn't open (no blur fired)
- Show download links only on explicit user click
- Redesign dialog with Teams-style centered layout
- Add nuxeo-drive-desktop-packages component for platform downloads
- Refactor protocol handler with Safari-specific object element approach

* removed nuxeo-protocol-handler file

* WEBUI-1916: Drive dialog UI improvements and persistent failure message

- Left-align title and description, matching standard Nuxeo dialog layout
- Move Open with Nuxeo Drive button to footer (Close left, Open right)
- Style Close button with outline border matching Cancel in other dialogs
- Reduce dialog padding for compact layout
- Use red color for failure message text
- Add _failureVisible flag so error message persists after blur events
- Align desktop packages table headers with content
- Improve text contrast for a11y compliance

* added window.location.href

* fix: use hidden object for Safari and anchor click for other browsers in _navigateTo

* fix: use timeout-based protocol handler detection for _failureVisible

* test: add _launchDrive and _navigateTo unit tests for Drive buttons

* fix: Firefox _navigateTo via window.open, focus-return on non-macOS, inline-block install link

* refactor: simplify Drive buttons - remove protocol detection, always show install option

- Remove all blur/focus/timeout detection logic and browser/OS sniffing
- Use simple window.location.href for nxdrive:// protocol
- Always show install link; auto-expand when no Drive token found
- Show hint text after Open click with download packages
- Disable Open button after click; reset on dialog reopen
- Remove driveButton.dialog.couldNotOpen i18n key
- Add driveButton.dialog.install.hint i18n key

* test(WEBUI-1916): add unit tests for drive action buttons to reach 90% coverage

- Add addGoErrorSuites: token-found branch (_hasToken=true, _installExpanded stays false)
- Add addOpenDriveSuite: covers _openDrive (_opened, _installExpanded, window.location.href)
- Add addToggleInstallSuite: covers _toggleInstall (_installExpanded, preventDefault)
- Wire new shared suites into edit, upload and download button test files
- Add driveEditURL construction tests (valid URL shape, filename encoding)
- Add _download token-found and catch branch tests for download button"

* chore: restore files unchanged from maintenance-3.1.x

* fix: correct unit test assertions for drive action buttons

- Replace _showInstall with _installExpanded (correct property name)
- Token-fetch failure tests check _installExpanded instead of toast
  (catch branch sets _installExpanded, not showError)
- Remove addLaunchDriveSuite from edit/upload/download buttons
  (those elements have no _navigateTo / _launchDrive methods)
- Guard window.location.href in addOpenDriveSuite setup to prevent
  nxdrive:// assignments triggering Karma page reload
- Fix inline _openDrive suite in download-button test accordingly

* fix: extract _navigate() to prevent Karma page reload in tests

Each drive button's _openDrive() now delegates window.location.href
assignment to a dedicated _navigate(url) method. This makes the
navigation stubbable in unit tests, eliminating the Karma
'full page reload' CI failure caused by Chrome 148 handling
nxdrive:// URLs as real navigation.

Updated addOpenDriveSuite in test helpers and the download-button
inline _openDrive suite to stub _navigate and assert the correct URL
is passed.

* test: improve coverage to >90% on drive action button new code

- Add _navigate() test suite inside addOpenDriveSuite that exercises
  the real window.location.href assignment path via a property getter spy
- Add _compressFromOriginalUrl server-too-long error path test in
  download-button (crafted 300-char server segment triggers the throw)
- Replace stub-based server-too-long test in upload-button with one that
  stubs TextEncoder.prototype.encode to force the > 255 guard,
  ensuring lines 242-244 of nuxeo-drive-upload-button.js are hit
- Exclude addons/*/test/**/*.js from sonar coverage (test helpers are
  not production code; previously nuxeo-drive-test-helpers.js dragged
  coverage on new code down to 34.4%)

* refactor: rename nuxeo-drive-test-helpers.js to nuxeo-drive-test-helpers.test.js

The .test.js suffix matches sonar.coverage.exclusions (**/*.test.js)
so Sonar no longer counts the helper file as uncovered production code,
fixing the 34.4% coverage on new code reported in the PR.

Also remove redundant /* global */ comment — the test environment
already provides sinon, suite, setup, teardown, test and expect as
built-in globals; the comment caused no-redeclare ESLint errors
when the .test.js eslint config applied its test environment.

* chore: revert sonar coverage exclusion for addon test helpers

The nuxeo-drive-test-helpers.js file was renamed to
nuxeo-drive-test-helpers.test.js, so it now matches the existing
**/*.test.js exclusion pattern. The explicit addons/*/test/**/*.js
rule added in the previous commit is no longer needed.

* refactor(drive): extract shared token-fetch and base64 utils to reduce duplication

Create nuxeo-drive-utils.js with:
- fetchTokenAndToggleDialog(): replaces the identical 18-line token-fetch +
  dialog.toggle() block duplicated across edit, download and upload buttons
- base64UrlSafeEncode(): replaces the identical _base64UrlSafeEncode() method
  duplicated across download and upload buttons

Update all three element files to import from the shared utils module.
Update nuxeo-drive-upload-button.test.js to call base64UrlSafeEncode()
directly instead of via element._base64UrlSafeEncode() (method removed).

All 1965 tests continue to pass.

* fix(drive): resolve Sonar maintainability issues

* fix(drive): resolve Sonar issues in nuxeo-drive-utils.js

- Optional chain: tokens && tokens.length -> tokens?.length (L41)
- String.fromCodePoint over String.fromCharCode (L62)
- replaceAll over regex replace for + and / substitutions (L64, x2)

* fix(drive): remove regex from base64UrlSafeEncode to resolve Sonar S5852

Replace /=+$/ regex with indexOf + slice to strip Base64 padding,
eliminating the security hotspot without changing behaviour.

* fix(drive): address Copilot review comments on i18n ordering and isProxy guard

* WEBUI-1916: refactor Drive action buttons to navigate-first pattern

- Replace unreliable protocol detection with immediate nxdrive:// navigation
- Show lightweight fallback dialog with expandable install links
- Remove token fetch, sessionStorage suppression, and detection hacks
- Simplify all three buttons (edit, upload, download) to consistent UX
- Add i18n keys for new dialog heading and hint text

* WEBUI-1916: clarify install hint link text in Drive dialog

* test: update Drive button unit tests for navigate-first pattern

Rewrite test files to match the refactored Drive action buttons:
- Remove references to removed APIs ($.token, _hasToken, _opened, _navigate, _openDrive)
- Replace old suite factories with addGoSuite, addShowErrorSuite, addToggleInstallSuite
- Keep URL compression, guard condition, and availability tests

* fix: use anchor click instead of location.href for nxdrive:// navigation

Replace globalThis.location.href with anchor element click in
navigateAndShowFallback to prevent full page reloads in browsers
that don't recognize the nxdrive:// custom protocol. Anchor clicks
with unknown schemes are silently ignored by the browser.

Move the HTMLAnchorElement.prototype.click stub into test helpers
so all drive test files benefit from it.

* test: increase Drive button test coverage to >90%

Add tests for uncovered branches:
- edit button: _isAvailable returning true, blob without appLinks property
- upload button: _isAvailable with null/undefined doc, _go catch branch
- download button: _download catch branch with/without userMessage

* fix(i18n): remove dead driveButton keys, add missing driveUpload.serverUrlTooLong

* fix: improve addGoSuite test isolation by conditionally stubbing _navigate

- Add defensive check for element._navigate existence before stubbing
- Prevents flaky tests caused by shared globalThis.location state
- Ensures test isolation: each element instance has its own navigation stub
- Gracefully handles elements without _navigate method
- Addresses Copilot review comment about test order dependency

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Madhur Kulshrestha <157124712+madhurkulshrestha-hyland@users.noreply.github.com>
swarnadipa-dev added a commit that referenced this pull request Jun 3, 2026
…t has spaces in its name [LTS-2023] (#3201)

* WEBUI-1916 drive actions buttons should handle error properly when drive not installed on user machine

* show error toast for edit with drive when drive not installed

* fixed Copilot review comments. added unit tests

* fixed blur logic. added unit tests

* addressed copilot review comments

* removed app.js changes

* removed app.js changes

* fix i18n key ordering: sort drive keys alphabetically

Agent-Logs-Url: https://github.com/nuxeo/nuxeo-web-ui/sessions/cae1105b-e38f-4389-8f71-dee2a5578314

Co-authored-by: swarnadipa-dev <67375320+swarnadipa-dev@users.noreply.github.com>

* show install dialog when Drive is not installed across Chrome/Edge/Safari/Firefox

* refactored code and updated unit tests

* removed unwanted merge markers.

* removed duplicate code. fixed lint

* addressed sonar quality issues

* addressed sonar quality issues

* addressed sonar quality issues

* addressed sonar quality issues

* addressed sonar quality issues

* fixed lint issue

* WEBUI-2002 : Upgrade ESLint and @eslint/js to v10 (#3111)

* WEBUI-1990: added sonar configurations [LTS-2023] (#3102)

* WEBUI-1990: added sonar configurations [LTS-2023]

* added quality gates config

* added/updated sonar configuration

* added/updated sonar configuration

* removed overall coverage check

* WEBUI-1990: fix sonar branch detection and add push trigger [LTS-2023] (#3125)

* WEBUI-1990: fix sonar branch detection and add push trigger on base branch

* fix: use single quotes in node -p to avoid shell quote nesting issue

* fix(sonar): use PR decoration params on pull_request events instead of branch analysis (#3127)

* fix(sonar): include addon test directories in sonar.tests and sonar.test.inclusions (#3131)

* fix(sonar): include addon test directories in sonar.tests and sonar.test.inclusions

Addon unit tests (addons/*/test/**/*.test.js) were not registered with
SonarCloud because sonar.tests only pointed to the root test/ directory.
This caused coverage for addon source files to show as N/A instead of
being measured, allowing the Quality Gate coverage condition to be skipped.

Add all addon test directories with test files to sonar.tests and
expand sonar.test.inclusions to match addons/*/test/**/*.test.js.

* fix(sonar): format sonar.tests as multi-line for readability

* fix(sonar): exclude addons/**/test/** from sonar.sources to prevent double-indexing

Addon test directories are now listed in both sonar.sources (via the
addons/ root) and sonar.tests. This causes them to be analyzed as both
source and test code. Adding addons/**/test/** to sonar.exclusions ensures
they are only processed as test code, not source.

* WEBUI-1990: declare addon test dirs as test code in sonar-project.properties [LTS-2023] (#3135)

* WEBUI-1990: removed addon test from exclusions

* WEBUI-1990: removed addon test from exclusions

* WEBUI-1990: removed addona from exclusions

* WEBUI-1990: fix sonar.tests source/test overlap (#3142)

sonar.sources includes 'addons' and sonar.tests listed entire addon
directories (e.g. addons/nuxeo-csv), causing a source/test overlap
that made the scanner fail with exit code 3.

Revert sonar.tests to list only the test/ subdirectories and
sonar.test.inclusions to addons/*/test/**/*.test.js.

* WEBUI-2015 : lock JavaScript dependency versions with npm ci [LTS-2023] (#3136)

* WEBUI-2015 : lock JavaScript dependency versions with npm ci

* WEBUI-2015 : sync lockfiles after package.json modifications in CI

* WEBUI-2015 : remove dual-branch-pr prompt file

* WEBUI-2015 : address PR review comments

- Bump catalog.yaml Node version from 14 to 18 (lockfileVersion 3 compat)
- Add --no-package-lock to RC install steps in test, sonar, a11y workflows
- Add --no-package-lock to nuxeo-elements installs in preview workflow
- Change preinstall script to use npm ci instead of npm install

* Suprressing sonar issues for yaml files

* Fixes

* Additional fixes

* Additional fixes

* WEBUI-2017 WEBUI-2018 : define permissions at job level in workflow files (#3155)

* WEBUI-1990: exclude non-unit-testable files from sonar coverage metrics : [LTS-2023] (#3158)

* added files that are realistically not testable in sonar exclusions

* WEBUI-1990: refine coverage exclusions — include testable spreadsheet/S3 modules

* addressed copilot review comments

* fix: prevent dialog toggle loop with no-cancel-on-outside-click and on-click

* fix(lint): remove unused uaStub variable in nuxeo-drive-protocol-handler.test.js

Agent-Logs-Url: https://github.com/nuxeo/nuxeo-web-ui/sessions/664057c6-0a03-49b6-9668-cee488342c04

Co-authored-by: swarnadipa-dev <67375320+swarnadipa-dev@users.noreply.github.com>

* fix: format long line in Safari test setup to respect Prettier printWidth

* WEBUI-1916: Drive action buttons handle failure gracefully

- Use window blur event to detect Drive app launch (no timeouts)
- Show failure message only when Drive doesn't open (no blur fired)
- Show download links only on explicit user click
- Redesign dialog with Teams-style centered layout
- Add nuxeo-drive-desktop-packages component for platform downloads
- Refactor protocol handler with Safari-specific object element approach

* removed nuxeo-protocol-handler file

* WEBUI-1916: Drive dialog UI improvements and persistent failure message

- Left-align title and description, matching standard Nuxeo dialog layout
- Move Open with Nuxeo Drive button to footer (Close left, Open right)
- Style Close button with outline border matching Cancel in other dialogs
- Reduce dialog padding for compact layout
- Use red color for failure message text
- Add _failureVisible flag so error message persists after blur events
- Align desktop packages table headers with content
- Improve text contrast for a11y compliance

* added window.location.href

* fix: use hidden object for Safari and anchor click for other browsers in _navigateTo

* fix: use timeout-based protocol handler detection for _failureVisible

* test: add _launchDrive and _navigateTo unit tests for Drive buttons

* fix: Firefox _navigateTo via window.open, focus-return on non-macOS, inline-block install link

* refactor: simplify Drive buttons - remove protocol detection, always show install option

- Remove all blur/focus/timeout detection logic and browser/OS sniffing
- Use simple window.location.href for nxdrive:// protocol
- Always show install link; auto-expand when no Drive token found
- Show hint text after Open click with download packages
- Disable Open button after click; reset on dialog reopen
- Remove driveButton.dialog.couldNotOpen i18n key
- Add driveButton.dialog.install.hint i18n key

* test(WEBUI-1916): add unit tests for drive action buttons to reach 90% coverage

- Add addGoErrorSuites: token-found branch (_hasToken=true, _installExpanded stays false)
- Add addOpenDriveSuite: covers _openDrive (_opened, _installExpanded, window.location.href)
- Add addToggleInstallSuite: covers _toggleInstall (_installExpanded, preventDefault)
- Wire new shared suites into edit, upload and download button test files
- Add driveEditURL construction tests (valid URL shape, filename encoding)
- Add _download token-found and catch branch tests for download button"

* chore: restore files unchanged from maintenance-3.1.x

* fix: correct unit test assertions for drive action buttons

- Replace _showInstall with _installExpanded (correct property name)
- Token-fetch failure tests check _installExpanded instead of toast
  (catch branch sets _installExpanded, not showError)
- Remove addLaunchDriveSuite from edit/upload/download buttons
  (those elements have no _navigateTo / _launchDrive methods)
- Guard window.location.href in addOpenDriveSuite setup to prevent
  nxdrive:// assignments triggering Karma page reload
- Fix inline _openDrive suite in download-button test accordingly

* fix: extract _navigate() to prevent Karma page reload in tests

Each drive button's _openDrive() now delegates window.location.href
assignment to a dedicated _navigate(url) method. This makes the
navigation stubbable in unit tests, eliminating the Karma
'full page reload' CI failure caused by Chrome 148 handling
nxdrive:// URLs as real navigation.

Updated addOpenDriveSuite in test helpers and the download-button
inline _openDrive suite to stub _navigate and assert the correct URL
is passed.

* test: improve coverage to >90% on drive action button new code

- Add _navigate() test suite inside addOpenDriveSuite that exercises
  the real window.location.href assignment path via a property getter spy
- Add _compressFromOriginalUrl server-too-long error path test in
  download-button (crafted 300-char server segment triggers the throw)
- Replace stub-based server-too-long test in upload-button with one that
  stubs TextEncoder.prototype.encode to force the > 255 guard,
  ensuring lines 242-244 of nuxeo-drive-upload-button.js are hit
- Exclude addons/*/test/**/*.js from sonar coverage (test helpers are
  not production code; previously nuxeo-drive-test-helpers.js dragged
  coverage on new code down to 34.4%)

* refactor: rename nuxeo-drive-test-helpers.js to nuxeo-drive-test-helpers.test.js

The .test.js suffix matches sonar.coverage.exclusions (**/*.test.js)
so Sonar no longer counts the helper file as uncovered production code,
fixing the 34.4% coverage on new code reported in the PR.

Also remove redundant /* global */ comment — the test environment
already provides sinon, suite, setup, teardown, test and expect as
built-in globals; the comment caused no-redeclare ESLint errors
when the .test.js eslint config applied its test environment.

* chore: revert sonar coverage exclusion for addon test helpers

The nuxeo-drive-test-helpers.js file was renamed to
nuxeo-drive-test-helpers.test.js, so it now matches the existing
**/*.test.js exclusion pattern. The explicit addons/*/test/**/*.js
rule added in the previous commit is no longer needed.

* refactor(drive): extract shared token-fetch and base64 utils to reduce duplication

Create nuxeo-drive-utils.js with:
- fetchTokenAndToggleDialog(): replaces the identical 18-line token-fetch +
  dialog.toggle() block duplicated across edit, download and upload buttons
- base64UrlSafeEncode(): replaces the identical _base64UrlSafeEncode() method
  duplicated across download and upload buttons

Update all three element files to import from the shared utils module.
Update nuxeo-drive-upload-button.test.js to call base64UrlSafeEncode()
directly instead of via element._base64UrlSafeEncode() (method removed).

All 1965 tests continue to pass.

* fix(drive): resolve Sonar maintainability issues

* fix(drive): resolve Sonar issues in nuxeo-drive-utils.js

- Optional chain: tokens && tokens.length -> tokens?.length (L41)
- String.fromCodePoint over String.fromCharCode (L62)
- replaceAll over regex replace for + and / substitutions (L64, x2)

* fix(drive): remove regex from base64UrlSafeEncode to resolve Sonar S5852

Replace /=+$/ regex with indexOf + slice to strip Base64 padding,
eliminating the security hotspot without changing behaviour.

* fix(drive): address Copilot review comments on i18n ordering and isProxy guard

* WEBUI-1916: refactor Drive action buttons to navigate-first pattern

- Replace unreliable protocol detection with immediate nxdrive:// navigation
- Show lightweight fallback dialog with expandable install links
- Remove token fetch, sessionStorage suppression, and detection hacks
- Simplify all three buttons (edit, upload, download) to consistent UX
- Add i18n keys for new dialog heading and hint text

* WEBUI-1916: clarify install hint link text in Drive dialog

* test: update Drive button unit tests for navigate-first pattern

Rewrite test files to match the refactored Drive action buttons:
- Remove references to removed APIs ($.token, _hasToken, _opened, _navigate, _openDrive)
- Replace old suite factories with addGoSuite, addShowErrorSuite, addToggleInstallSuite
- Keep URL compression, guard condition, and availability tests

* fix: use anchor click instead of location.href for nxdrive:// navigation

Replace globalThis.location.href with anchor element click in
navigateAndShowFallback to prevent full page reloads in browsers
that don't recognize the nxdrive:// custom protocol. Anchor clicks
with unknown schemes are silently ignored by the browser.

Move the HTMLAnchorElement.prototype.click stub into test helpers
so all drive test files benefit from it.

* test: increase Drive button test coverage to >90%

Add tests for uncovered branches:
- edit button: _isAvailable returning true, blob without appLinks property
- upload button: _isAvailable with null/undefined doc, _go catch branch
- download button: _download catch branch with/without userMessage

* fix(i18n): remove dead driveButton keys, add missing driveUpload.serverUrlTooLong

* fix: improve addGoSuite test isolation by conditionally stubbing _navigate

- Add defensive check for element._navigate existence before stubbing
- Prevents flaky tests caused by shared globalThis.location state
- Ensures test isolation: each element instance has its own navigation stub
- Gracefully handles elements without _navigate method
- Addresses Copilot review comment about test order dependency

* WEBUI-2020: Update Nuxeo Drive upload button with compatible compression logic

- Implement URL compression logic compatible with Drive team decoding
- Compress only server info (scheme + server bytes), exclude path from payload
- Add comprehensive unit tests for compression methods
- Update error handling to properly propagate exceptions
- Fixes direct transfer URLs containing spaces

All tests passing. Ready for PR to maintenance-3.1.x.

* WEBUI-2020: Apply Copilot review fixes for Drive buttons

Apply fixes to address code review feedback:

1. Gesture event consistency: Change on-click to on-tap in upload, download, and edit buttons for consistency with Polymer patterns and codebase conventions

2. Byte overflow guard: Add validation when encoding server URL (max 255 bytes) to prevent invalid nxdrive:// URLs in upload button

3. Error message fallback: Improve error handling to use userMessage property with fallback to generic i18n message when error details are unavailable

4. Test isolation: Remove global prototype override from module load and add scoped sinon stub to addGoSuite to prevent test pollution

5. Test logic correction: Clarify that different document paths must produce different compressed URLs (path is encoded in payload)

* fix(drive): use on-click instead of on-tap in download button template

* fix(tests): fix unit test failures caused by anchor click triggering page reload in Chrome 148+

In Chrome 148+, `HTMLAnchorElement.prototype.click` is not an own property
(it inherits from `HTMLElement.prototype`), so `sinon.stub()` on it has no
effect and the nxdrive:// anchor click reaches the browser, causing Karma
to report "Some of your tests did a full page reload!".

Fix by assigning a no-op directly as an own property on
`HTMLAnchorElement.prototype` in setup and deleting it in teardown, which
correctly shadows the inherited native implementation.

Also fix `_buildOriginalUrl` regex in upload button test: the `[^/]+`
host pattern was too strict for Karma's multi-segment test URL
(127.0.0.1:9876/context.html); relaxed to `.+`."

* fix(drive): address SonarCloud issues in _base64UrlSafeEncode

- Use String.fromCodePoint() over String.fromCharCode()
- Use String#replaceAll() over String#replace() with regex for + and /
- Replace unbounded /=+$/ regex with bounded /={1,2}$/ to avoid
  potential ReDoS (javascript:S5852 security hotspot)

* fix(drive): use shared base64UrlSafeEncode from nuxeo-drive-utils in upload button

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Madhur Kulshrestha <157124712+madhurkulshrestha-hyland@users.noreply.github.com>
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.

4 participants