-
Notifications
You must be signed in to change notification settings - Fork 0
[WIP] Address critical gaps in test coverage and performance #439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ef63cb3
Initial plan
Copilot 5cb638f
feat: integrate i18n into @object-ui/react and add sideEffects declar…
Copilot 6f89ff1
Add tests for useExpression and useCondition hooks
Copilot b6d0c82
Add tests for useDiscovery hook
Copilot 1a636c1
Add tests for useActionRunner hook
Copilot dc56bd9
Add ActionContext tests for ActionProvider, useAction, and useHasActi…
Copilot 7454ba7
Add provider.test.tsx for @object-ui/i18n React integration
Copilot 9e964d1
Add test coverage for LazyPluginLoader: preloadPlugin, errorFallback,…
Copilot eb91925
Add test file for timeline renderer component (packages/plugin-timeli…
Copilot a4ae6dc
Add SortUI component test suite
Copilot 5ad981c
Add FilterUI component tests covering rendering, values, layout, and …
Copilot 508bcc2
Add comprehensive VirtualGrid test suite in __tests__/VirtualGrid.tes…
Copilot 3ffdb40
chore: raise coverage thresholds after adding comprehensive tests
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import { describe, it, expect, vi } from 'vitest'; | ||
| import { renderHook, waitFor, act } from '@testing-library/react'; | ||
| import React from 'react'; | ||
| import { I18nProvider, useObjectTranslation, useI18nContext } from '../provider'; | ||
| import { createI18n } from '../i18n'; | ||
|
|
||
| describe('I18nProvider', () => { | ||
| it('creates i18n instance from config', () => { | ||
| const wrapper = ({ children }: { children: React.ReactNode }) => | ||
| React.createElement(I18nProvider, { config: { defaultLanguage: 'en', detectBrowserLanguage: false } }, children); | ||
|
|
||
| const { result } = renderHook(() => useObjectTranslation(), { wrapper }); | ||
|
|
||
| expect(result.current.i18n).toBeDefined(); | ||
| expect(result.current.language).toBe('en'); | ||
| }); | ||
|
|
||
| it('accepts pre-created instance', () => { | ||
| const instance = createI18n({ defaultLanguage: 'fr', detectBrowserLanguage: false }); | ||
|
|
||
| const wrapper = ({ children }: { children: React.ReactNode }) => | ||
| React.createElement(I18nProvider, { instance }, children); | ||
|
|
||
| const { result } = renderHook(() => useObjectTranslation(), { wrapper }); | ||
|
|
||
| expect(result.current.i18n).toBeDefined(); | ||
| expect(result.current.language).toBe('fr'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('useObjectTranslation', () => { | ||
| const wrapper = ({ children }: { children: React.ReactNode }) => | ||
| React.createElement(I18nProvider, { config: { defaultLanguage: 'en', detectBrowserLanguage: false } }, children); | ||
|
|
||
| it('returns t, language, changeLanguage, direction, i18n', () => { | ||
| const { result } = renderHook(() => useObjectTranslation(), { wrapper }); | ||
|
|
||
| expect(result.current.t).toBeTypeOf('function'); | ||
| expect(result.current.language).toBeTypeOf('string'); | ||
| expect(result.current.changeLanguage).toBeTypeOf('function'); | ||
| expect(result.current.direction).toBeTypeOf('string'); | ||
| expect(result.current.i18n).toBeDefined(); | ||
| }); | ||
|
|
||
| it('translates keys correctly', () => { | ||
| const { result } = renderHook(() => useObjectTranslation(), { wrapper }); | ||
|
|
||
| expect(result.current.t('common.save')).toBe('Save'); | ||
| expect(result.current.t('common.cancel')).toBe('Cancel'); | ||
| expect(result.current.t('common.delete')).toBe('Delete'); | ||
| }); | ||
|
|
||
| it('returns en as default language', () => { | ||
| const { result } = renderHook(() => useObjectTranslation(), { wrapper }); | ||
|
|
||
| expect(result.current.language).toBe('en'); | ||
| }); | ||
|
|
||
| it('works with Chinese language', () => { | ||
| const zhWrapper = ({ children }: { children: React.ReactNode }) => | ||
| React.createElement(I18nProvider, { config: { defaultLanguage: 'zh', detectBrowserLanguage: false } }, children); | ||
|
|
||
| const { result } = renderHook(() => useObjectTranslation(), { wrapper: zhWrapper }); | ||
|
|
||
| expect(result.current.language).toBe('zh'); | ||
| expect(result.current.t('common.save')).toBe('保存'); | ||
| expect(result.current.t('common.cancel')).toBe('取消'); | ||
| }); | ||
|
|
||
| it('changeLanguage updates language', async () => { | ||
| const { result } = renderHook(() => useObjectTranslation(), { wrapper }); | ||
|
|
||
| expect(result.current.language).toBe('en'); | ||
|
|
||
| await act(async () => { | ||
| await result.current.changeLanguage('zh'); | ||
| }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(result.current.language).toBe('zh'); | ||
| }); | ||
| }); | ||
|
|
||
| it('returns RTL direction for Arabic', () => { | ||
| const arWrapper = ({ children }: { children: React.ReactNode }) => | ||
| React.createElement(I18nProvider, { config: { defaultLanguage: 'ar', detectBrowserLanguage: false } }, children); | ||
|
|
||
| const { result } = renderHook(() => useObjectTranslation(), { wrapper: arWrapper }); | ||
|
|
||
| expect(result.current.direction).toBe('rtl'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('useI18nContext', () => { | ||
| it('throws when used outside provider', () => { | ||
| // Suppress console.error from React for the expected error | ||
| const spy = vi.spyOn(console, 'error').mockImplementation(() => {}); | ||
|
|
||
| expect(() => { | ||
| renderHook(() => useI18nContext()); | ||
| }).toThrow('useI18nContext must be used within an I18nProvider'); | ||
|
|
||
| spy.mockRestore(); | ||
| }); | ||
|
|
||
| it('returns context inside provider', () => { | ||
| const wrapper = ({ children }: { children: React.ReactNode }) => | ||
| React.createElement(I18nProvider, { config: { defaultLanguage: 'en', detectBrowserLanguage: false } }, children); | ||
|
|
||
| const { result } = renderHook(() => useI18nContext(), { wrapper }); | ||
|
|
||
| expect(result.current.language).toBe('en'); | ||
| expect(result.current.changeLanguage).toBeTypeOf('function'); | ||
| expect(result.current.direction).toBe('ltr'); | ||
| expect(result.current.i18n).toBeDefined(); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting
sideEffects: falseis incorrect for this package. The entry pointsrc/index.tshas module-level side effects (callsregisterLayout()at lines 53-57 to register components in ComponentRegistry). If bundlers tree-shake this module due tosideEffects: false, the layout components will not be registered and will fail at runtime. Either remove this field or set it totrue, or move the registration call out of the module-level scope.