-
Notifications
You must be signed in to change notification settings - Fork 432
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
fix(core): boolean value in search shows actual value #7623
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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
110 changes: 110 additions & 0 deletions
110
...src/core/studio/components/navbar/search/components/common/__tests__/FilterLabel.test.tsx
This file contains 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,110 @@ | ||
import {render, screen} from '@testing-library/react' | ||
import {type SanityClient} from 'sanity' | ||
import {describe, expect, test} from 'vitest' | ||
|
||
import {createMockSanityClient} from '../../../../../../../../../test/mocks/mockSanityClient' | ||
import {createTestProvider} from '../../../../../../../../../test/testUtils/TestProvider' | ||
import {SearchProvider} from '../../../contexts/search/SearchProvider' | ||
import {type SearchFilter} from '../../../types' | ||
import {FilterLabel} from '../FilterLabel' | ||
|
||
describe('FilterLabel', () => { | ||
const mockFilter: SearchFilter = { | ||
fieldId: 'boolean-title-boolean-test', | ||
filterName: 'boolean', | ||
operatorType: 'booleanEqual', | ||
value: true, | ||
} | ||
|
||
const schema = { | ||
types: [ | ||
{ | ||
name: 'test', | ||
type: 'document', | ||
fields: [ | ||
{ | ||
name: 'title', | ||
type: 'boolean', | ||
}, | ||
], | ||
}, | ||
], | ||
} | ||
|
||
const client = createMockSanityClient() as unknown as SanityClient | ||
|
||
test('renders the filter label with field, operator, and value', async () => { | ||
const TestProvider = await createTestProvider({ | ||
client, | ||
config: { | ||
name: 'default', | ||
projectId: 'test', | ||
dataset: 'test', | ||
schema, | ||
}, | ||
}) | ||
render( | ||
<TestProvider> | ||
<SearchProvider> | ||
<FilterLabel filter={mockFilter} /> | ||
</SearchProvider> | ||
</TestProvider>, | ||
) | ||
|
||
expect(screen.getByText('Title')).toBeInTheDocument() | ||
expect(screen.getByText('is')).toBeInTheDocument() | ||
expect(screen.getByText('True')).toBeInTheDocument() | ||
}) | ||
|
||
test('renders only the field when showContent is false', async () => { | ||
const TestProvider = await createTestProvider({ | ||
client, | ||
config: { | ||
name: 'default', | ||
projectId: 'test', | ||
dataset: 'test', | ||
schema, | ||
}, | ||
}) | ||
render( | ||
<TestProvider> | ||
<SearchProvider> | ||
<FilterLabel filter={mockFilter} showContent={false} /> | ||
</SearchProvider> | ||
</TestProvider>, | ||
) | ||
|
||
expect(screen.getByText('Title')).toBeInTheDocument() | ||
expect(screen.queryByText('is')).not.toBeInTheDocument() | ||
expect(screen.queryByText('True')).not.toBeInTheDocument() | ||
}) | ||
|
||
test('handles missing operator descriptionKey', async () => { | ||
const filterWithoutDescription: SearchFilter = { | ||
...mockFilter, | ||
operatorType: 'unknown', | ||
} | ||
|
||
const TestProvider = await createTestProvider({ | ||
client, | ||
config: { | ||
name: 'default', | ||
projectId: 'test', | ||
dataset: 'test', | ||
schema, | ||
}, | ||
}) | ||
|
||
render( | ||
<TestProvider> | ||
<SearchProvider> | ||
<FilterLabel filter={filterWithoutDescription} /> | ||
</SearchProvider> | ||
</TestProvider>, | ||
) | ||
|
||
expect(screen.getByText('Title')).toBeInTheDocument() | ||
expect(screen.queryByText('is')).not.toBeInTheDocument() | ||
expect(screen.queryByText('True')).not.toBeInTheDocument() | ||
}) | ||
}) |
This file contains 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 |
---|---|---|
|
@@ -6,16 +6,16 @@ import {AddonDatasetContext} from 'sanity/_singletons' | |
|
||
import { | ||
CopyPasteProvider, | ||
LocaleProviderBase, | ||
type LocaleResourceBundle, | ||
ResourceCacheProvider, | ||
type SingleWorkspace, | ||
SourceProvider, | ||
usEnglishLocale, | ||
WorkspaceProvider, | ||
} from '../../src/core' | ||
import {studioDefaultLocaleResources} from '../../src/core/i18n/bundles/studio' | ||
import {LocaleProviderBase} from '../../src/core/i18n/components/LocaleProvider' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason the test was failing without this change. I think this probably has to do with some circular dependency somewhere and it's better to avoid barrel imports |
||
import {prepareI18n} from '../../src/core/i18n/i18nConfig' | ||
import {usEnglishLocale} from '../../src/core/i18n/locales' | ||
import {route, RouterProvider} from '../../src/router' | ||
import {getMockWorkspace} from './getMockWorkspaceFromConfig' | ||
|
||
|
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.
Added a watch command, let me know if y'all are not a fan