Refactor unit tests for extracted getAllowedTabs() function#4311
Merged
Refactor unit tests for extracted getAllowedTabs() function#4311
Conversation
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
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
approved these changes
Mar 14, 2026
Contributor
There was a problem hiding this comment.
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
useCasesExcludedand introducegetAllowedTabs()to generate the allowed tab definitions based onstate+self. - Update
TermTypeSearch.init()to usegetAllowedTabs()and then load handlers for the resulting tabs. - Refactor
TermTypeSearch.unit.spec.tsto unit-testgetAllowedTabs()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.
client/termdb/TermTypeSearch.ts
Outdated
| termTypeGroup: string // required for comparing | ||
| termType: string | ||
| contentHolder?: any // added by Tabs | ||
| callback: (any) => void |
xzhou82
approved these changes
Mar 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Refactored unit tests to test the newly exported
getAllowedTabs(state, self)pure function instead of theTermTypeSearch.addTabsAllowed(state)instance method.Changes
getAllowedTabsfunction instead ofTermTypeSearchclass andd3-selectiongetMockSelf()creates minimal mock with only required properties (types,app.vocabApi.termdbConfig,useCasesExcluded,setTermTypeGroup)usecaseat top level to matchgetState()output (wastree.usecasein appState)getAllowedTabs(state, self)returning tabs arrayImpact
Checklist
🔒 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.