Skip to content

Refactor unit tests for extracted getAllowedTabs() function#4311

Merged
xzhou82 merged 7 commits intomasterfrom
copilot/add-unit-test-for-addtabsallowed
Mar 14, 2026
Merged

Refactor unit tests for extracted getAllowedTabs() function#4311
xzhou82 merged 7 commits intomasterfrom
copilot/add-unit-test-for-addtabsallowed

Conversation

Copy link
Contributor

Copilot AI commented Mar 13, 2026

Description

Refactored unit tests to test the newly exported getAllowedTabs(state, self) pure function instead of the TermTypeSearch.addTabsAllowed(state) instance method.

Changes

  • Import: getAllowedTabs function instead of TermTypeSearch class and d3-selection
  • Test helper: getMockSelf() creates minimal mock with only required properties (types, app.vocabApi.termdbConfig, useCasesExcluded, setTermTypeGroup)
  • State structure: usecase at top level to match getState() output (was tree.usecase in appState)
  • Test pattern: Synchronous calls to getAllowedTabs(state, self) returning tabs array
  • Removed: DOM manipulation, async/await, class instantiation, cleanup code

Impact

  • 116 lines removed (18% reduction)
  • Tests are now true unit tests: pure function with explicit inputs/outputs
  • No DOM overhead, no async complexity, no shared state between tests
  • All 18 test cases preserved with identical assertions

Checklist

  • Tests: Added and/or passed unit and integration tests, or N/A
  • Todos: Commented or documented, or N/A
  • Notable Changes: updated release.txt, prefixed a commit message with "fix:" or "feat:", added to an internal tracking document, or N/A
  • Rust: Checked to see whether Rust needs to be re-compiled because of this PR, or N/A

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: xzhou82 <1619109+xzhou82@users.noreply.github.com>
Copilot AI changed the title [WIP] Add unit test for addTabsAllowed method Add unit tests for TermTypeSearch.addTabsAllowed() Mar 13, 2026
Copilot AI requested a review from xzhou82 March 13, 2026 20:09
Copilot AI changed the title Add unit tests for TermTypeSearch.addTabsAllowed() Add unit tests for TermTypeSearch.addTabsAllowed() method Mar 13, 2026
Co-authored-by: xzhou82 <1619109+xzhou82@users.noreply.github.com>
Copilot AI changed the title Add unit tests for TermTypeSearch.addTabsAllowed() method Refactor unit tests for extracted getAllowedTabs() function Mar 13, 2026
@xzhou82 xzhou82 marked this pull request as ready for review March 14, 2026 02:29
Copilot AI review requested due to automatic review settings March 14, 2026 02:29
Copy link
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

This PR refactors TermTypeSearch to extract tab-selection logic into an exported pure function (getAllowedTabs(state, self)) and updates the unit tests to directly exercise that function, removing DOM- and class-instantiation dependencies.

Changes:

  • Export useCasesExcluded and introduce getAllowedTabs() to generate the allowed tab definitions based on state + self.
  • Update TermTypeSearch.init() to use getAllowedTabs() and then load handlers for the resulting tabs.
  • Refactor TermTypeSearch.unit.spec.ts to unit-test getAllowedTabs() with minimal mocks and synchronous assertions.

Reviewed changes

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

File Description
client/termdb/test/TermTypeSearch.unit.spec.ts Rewrites tests to target getAllowedTabs() directly with minimal mocked self and updated state shape.
client/termdb/TermTypeSearch.ts Exports useCasesExcluded, adds Tab type + getAllowedTabs(), and updates initialization to build tabs via the extracted function.

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

termTypeGroup: string // required for comparing
termType: string
contentHolder?: any // added by Tabs
callback: (any) => void
@xzhou82 xzhou82 merged commit 4591e25 into master Mar 14, 2026
3 checks passed
@xzhou82 xzhou82 deleted the copilot/add-unit-test-for-addtabsallowed branch March 14, 2026 03:01
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.

3 participants