-
Notifications
You must be signed in to change notification settings - Fork 40
refactor(atomic): migrate atomic-result-icon to Lit #6672
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
Open
Copilot
wants to merge
9
commits into
main
Choose a base branch
from
copilot/migrate-atomic-result-icon
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+389
β158
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b87be51
Initial plan
Copilot defb581
feat(atomic): migrate atomic-result-icon from Stencil to Lit
Copilot 000d722
refactor(atomic): move atomic-result-icon out of result-template-compβ¦
Copilot 8346ad2
Merge branch 'main' into copilot/migrate-atomic-result-icon
alexprudhomme 190a3b3
done
alexprudhomme e4972ab
e2e
alexprudhomme 7bb5c93
Apply suggestion from @Copilot
louis-bompart 9542b42
fix tests
alexprudhomme 326ce78
comments
alexprudhomme 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,4 +45,4 @@ dist-storybook/ | |
| /dev/headless/ | ||
|
|
||
| # Generated Tailwind CSS files | ||
| *.tw.css.ts | ||
| *.tw.css.ts | ||
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
49 changes: 24 additions & 25 deletions
49
...t-icon/atomic-result-icon.new.stories.tsx β ...t-icon/atomic-result-icon.new.stories.tsx
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 |
|---|---|---|
| @@ -1,59 +1,58 @@ | ||
| import type {Meta, StoryObj as Story} from '@storybook/web-components-vite'; | ||
| import {getStorybookHelpers} from '@wc-toolkit/storybook-helpers'; | ||
| import {html} from 'lit'; | ||
| import {MockSearchApi} from '@/storybook-utils/api/search/mock'; | ||
| import {parameters} from '@/storybook-utils/common/common-meta-parameters'; | ||
| import {wrapInResultList} from '@/storybook-utils/search/result-list-wrapper'; | ||
| import {wrapInResultTemplate} from '@/storybook-utils/search/result-template-wrapper'; | ||
| import {wrapInSearchInterface} from '@/storybook-utils/search/search-interface-wrapper'; | ||
|
|
||
| const {events, args, argTypes, template} = getStorybookHelpers( | ||
| 'atomic-result-icon', | ||
| {excludeCategories: ['methods']} | ||
| ); | ||
| const searchApiHarness = new MockSearchApi(); | ||
|
|
||
| searchApiHarness.searchEndpoint.mock((response) => ({ | ||
| name: 'atomic-result-icon', | ||
| ...response, | ||
| results: response.results.slice(0, 1), | ||
| totalCount: 1, | ||
| totalCountFiltered: 1, | ||
| })); | ||
|
|
||
| const {decorator: searchInterfaceDecorator, play} = wrapInSearchInterface({ | ||
| config: { | ||
| preprocessRequest: (request) => { | ||
| const parsed = JSON.parse(request.body as string); | ||
| console.log(parsed); | ||
| parsed.numberOfResults = 1; | ||
| request.body = JSON.stringify(parsed); | ||
| return request; | ||
| }, | ||
| }, | ||
| includeCodeRoot: false, | ||
| }); | ||
| const {decorator: resultListDecorator} = wrapInResultList('list', false); | ||
| const {decorator: resultTemplateDecorator} = wrapInResultTemplate(); | ||
|
|
||
| const {decorator: resultListDecorator} = wrapInResultList('list'); | ||
| const {decorator: resultTemplateDecorator} = wrapInResultTemplate(false); | ||
| const {events, args, argTypes, template} = getStorybookHelpers( | ||
| 'atomic-result-icon', | ||
| {excludeCategories: ['methods']} | ||
| ); | ||
|
|
||
| const meta: Meta = { | ||
| component: 'atomic-result-icon', | ||
| title: 'Search/ResultList/ResultIcon', | ||
| title: 'Search/Result Icon', | ||
| id: 'atomic-result-icon', | ||
|
|
||
| render: (args) => template(args), | ||
| decorators: [ | ||
| (story) => html` | ||
| <atomic-result-section-visual id="code-root"> | ||
| ${story()} | ||
| </atomic-result-section-visual> | ||
| `, | ||
| resultTemplateDecorator, | ||
| resultListDecorator, | ||
| searchInterfaceDecorator, | ||
| ], | ||
| parameters: { | ||
| ...parameters, | ||
| msw: { | ||
| handlers: [...searchApiHarness.handlers], | ||
| }, | ||
| actions: { | ||
| handles: events, | ||
| }, | ||
| }, | ||
| args, | ||
| argTypes, | ||
|
|
||
| play, | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| export const Default: Story = { | ||
| name: 'atomic-result-icon', | ||
| }; | ||
| export const Default: Story = {}; | ||
198 changes: 198 additions & 0 deletions
198
packages/atomic/src/components/search/atomic-result-icon/atomic-result-icon.spec.ts
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,198 @@ | ||
| import type {Result} from '@coveo/headless'; | ||
| import {html} from 'lit'; | ||
| import {beforeEach, describe, expect, it, vi} from 'vitest'; | ||
| import {page} from 'vitest/browser'; | ||
| import {renderInAtomicResult} from '@/vitest-utils/testing-helpers/fixtures/atomic/search/atomic-result-fixture'; | ||
| import {buildFakeResult} from '@/vitest-utils/testing-helpers/fixtures/headless/search/result'; | ||
| import {AtomicResultIcon} from './atomic-result-icon'; | ||
| import './atomic-result-icon'; | ||
|
|
||
| vi.mock('@coveo/headless', {spy: true}); | ||
|
|
||
| describe('atomic-result-icon', () => { | ||
| let mockResult: Result; | ||
|
|
||
| const renderComponent = async (options: {result?: Result} = {}) => { | ||
| const resultToUse = options.result ?? mockResult; | ||
| const {element, atomicResult, atomicInterface} = | ||
| await renderInAtomicResult<AtomicResultIcon>({ | ||
| template: html`<atomic-result-icon></atomic-result-icon>`, | ||
| selector: 'atomic-result-icon', | ||
| result: resultToUse, | ||
| bindings: (bindings) => { | ||
| bindings.engine.logger = {warn: vi.fn()} as never; | ||
| bindings.store = { | ||
| ...bindings.store, | ||
| onChange: vi.fn(), | ||
| state: { | ||
| ...bindings.store?.state, | ||
| loadingFlags: [], | ||
| iconAssetsPath: '', | ||
| }, | ||
| }; | ||
| return bindings; | ||
| }, | ||
| }); | ||
|
|
||
| await atomicInterface.updateComplete; | ||
| await atomicResult.updateComplete; | ||
| await element?.updateComplete; | ||
|
|
||
| return { | ||
| element, | ||
| getAtomicIcon: () => element?.shadowRoot?.querySelector('atomic-icon'), | ||
| getSlot: () => element?.shadowRoot?.querySelector('slot'), | ||
| }; | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| mockResult = buildFakeResult({ | ||
| raw: { | ||
| filetype: 'pdf', | ||
| objecttype: undefined, | ||
| urihash: '', | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('should be defined', () => { | ||
| const el = document.createElement('atomic-result-icon'); | ||
| expect(el).toBeInstanceOf(AtomicResultIcon); | ||
| }); | ||
|
|
||
| describe('when the rendered result has a known filetype', () => { | ||
| beforeEach(() => { | ||
| mockResult = buildFakeResult({ | ||
| raw: { | ||
| filetype: 'pdf', | ||
| objecttype: undefined, | ||
| urihash: '', | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('should render the icon of the filetype', async () => { | ||
| const {getAtomicIcon} = await renderComponent(); | ||
| const icon = getAtomicIcon(); | ||
|
|
||
| expect(icon).toBeDefined(); | ||
| expect(icon?.getAttribute('icon')).toBe('assets://pdf'); | ||
| expect(icon?.getAttribute('title')).toBe('pdf'); | ||
| }); | ||
|
|
||
| it('should not render a slot', async () => { | ||
| const {getSlot} = await renderComponent(); | ||
| expect(getSlot()).toBeNull(); | ||
| }); | ||
|
|
||
| it('should be accessible', async () => { | ||
| await renderComponent(); | ||
| await expect.element(page.getByTitle('pdf')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when the rendered result has a known objecttype', () => { | ||
| beforeEach(() => { | ||
| mockResult = buildFakeResult({ | ||
| raw: { | ||
| filetype: undefined, | ||
| objecttype: 'account', | ||
| urihash: '', | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('should render the icon of the objecttype', async () => { | ||
| const {getAtomicIcon} = await renderComponent(); | ||
| const icon = getAtomicIcon(); | ||
|
|
||
| expect(icon).toBeDefined(); | ||
| expect(icon?.getAttribute('icon')).toBe('assets://account'); | ||
| expect(icon?.getAttribute('title')).toBe('account'); | ||
| }); | ||
|
|
||
| it('should not render a slot', async () => { | ||
| const {getSlot} = await renderComponent(); | ||
| expect(getSlot()).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when the rendered result has both known filetype and objecttype', () => { | ||
| beforeEach(() => { | ||
| mockResult = buildFakeResult({ | ||
| raw: { | ||
| filetype: 'pdf', | ||
| objecttype: 'account', | ||
| urihash: '', | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('should render the objecttype icon (objecttype takes precedence)', async () => { | ||
| const {getAtomicIcon} = await renderComponent(); | ||
| const icon = getAtomicIcon(); | ||
|
|
||
| expect(icon).toBeDefined(); | ||
| expect(icon?.getAttribute('icon')).toBe('assets://account'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when the rendered result has no known filetype or objecttype', () => { | ||
| beforeEach(() => { | ||
| mockResult = buildFakeResult({ | ||
| raw: { | ||
| filetype: 'unknowntype', | ||
| objecttype: 'anotherunknown', | ||
| urihash: '', | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('should render a slot with a generic document icon', async () => { | ||
| const {getSlot, getAtomicIcon} = await renderComponent(); | ||
|
|
||
| // Should have a slot for fallback content | ||
| expect(getSlot()).toBeDefined(); | ||
|
|
||
| // The icon should still render with the default 'document' icon | ||
| const icon = getAtomicIcon(); | ||
| expect(icon).toBeDefined(); | ||
| expect(icon?.getAttribute('icon')).toBe('assets://document'); | ||
| expect(icon?.getAttribute('title')).toBe('document'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when the rendered result has undefined filetype and objecttype', () => { | ||
| beforeEach(() => { | ||
| mockResult = buildFakeResult({ | ||
| raw: { | ||
| filetype: undefined, | ||
| objecttype: undefined, | ||
| urihash: '', | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('should render a slot with a generic document icon', async () => { | ||
| const {getSlot, getAtomicIcon} = await renderComponent(); | ||
|
|
||
| // Should have a slot for fallback content | ||
| expect(getSlot()).toBeDefined(); | ||
|
|
||
| // The icon should still render with the default 'document' icon | ||
| const icon = getAtomicIcon(); | ||
| expect(icon).toBeDefined(); | ||
| expect(icon?.getAttribute('icon')).toBe('assets://document'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('license property', () => { | ||
| it('should have a license property', async () => { | ||
| const {element} = await renderComponent(); | ||
|
|
||
| expect(element?.license).toBeDefined(); | ||
| expect(element?.license).toContain('Salesforce'); | ||
| expect(element?.license).toContain('Creative Commons'); | ||
| }); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.