Skip to content

Commit 1ec8894

Browse files
Copilotfpbraultlouis-bompartdeveloper-experience-bot[bot]github-code-quality[bot]
authored
refactor: migrate atomic-no-results from Stencil to Lit (#6322)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: fpbrault <[email protected]> Co-authored-by: Felix Perron-Brault <[email protected]> Co-authored-by: Louis Bompart <[email protected]> Co-authored-by: developer-experience-bot[bot] <91079284+developer-experience-bot[bot]@users.noreply.github.com> Co-authored-by: louis-bompart <[email protected]> Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
1 parent eae59d3 commit 1ec8894

File tree

19 files changed

+782
-293
lines changed

19 files changed

+782
-293
lines changed

packages/atomic-react/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ node_modules/
22
dist
33

44
# Stencil generated files
5-
stencil-generated/
5+
stencil-generated/

packages/atomic-react/src/components/search/components.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
AtomicInsightInterface as LitAtomicInsightInterface,
1111
AtomicLayoutSection as LitAtomicLayoutSection,
1212
AtomicLoadMoreResults as LitAtomicLoadMoreResults,
13+
AtomicNoResults as LitAtomicNoResults,
1314
AtomicNumericRange as LitAtomicNumericRange,
1415
AtomicPager as LitAtomicPager,
1516
AtomicQueryError as LitAtomicQueryError,
@@ -108,6 +109,12 @@ export const AtomicLoadMoreResults = createComponent({
108109
elementClass: LitAtomicLoadMoreResults,
109110
});
110111

112+
export const AtomicNoResults = createComponent({
113+
tagName: 'atomic-no-results',
114+
react: React,
115+
elementClass: LitAtomicNoResults,
116+
});
117+
111118
export const AtomicNumericRange = createComponent({
112119
tagName: 'atomic-numeric-range',
113120
react: React,

packages/atomic/cypress/e2e/no-results-selectors.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/atomic/cypress/e2e/no-results.cypress.ts

Lines changed: 0 additions & 109 deletions
This file was deleted.

packages/atomic/src/components.d.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,15 +1094,6 @@ export namespace Components {
10941094
}
10951095
interface AtomicIpxTabs {
10961096
}
1097-
/**
1098-
* The `atomic-no-results` component displays search tips and a "Cancel last action" button when there are no results. Any additional content slotted inside of its element will be displayed as well.
1099-
*/
1100-
interface AtomicNoResults {
1101-
/**
1102-
* Whether to display a button which cancels the last available action.
1103-
*/
1104-
"enableCancelLastAction": boolean;
1105-
}
11061097
/**
11071098
* The `atomic-notifications` component is responsible for displaying notifications generated by the Coveo Search API (see [Trigger](https://docs.coveo.com/en/1458)).
11081099
*/
@@ -2697,15 +2688,6 @@ declare global {
26972688
prototype: HTMLAtomicIpxTabsElement;
26982689
new (): HTMLAtomicIpxTabsElement;
26992690
};
2700-
/**
2701-
* The `atomic-no-results` component displays search tips and a "Cancel last action" button when there are no results. Any additional content slotted inside of its element will be displayed as well.
2702-
*/
2703-
interface HTMLAtomicNoResultsElement extends Components.AtomicNoResults, HTMLStencilElement {
2704-
}
2705-
var HTMLAtomicNoResultsElement: {
2706-
prototype: HTMLAtomicNoResultsElement;
2707-
new (): HTMLAtomicNoResultsElement;
2708-
};
27092691
/**
27102692
* The `atomic-notifications` component is responsible for displaying notifications generated by the Coveo Search API (see [Trigger](https://docs.coveo.com/en/1458)).
27112693
*/
@@ -3328,7 +3310,6 @@ declare global {
33283310
"atomic-ipx-result-link": HTMLAtomicIpxResultLinkElement;
33293311
"atomic-ipx-tab": HTMLAtomicIpxTabElement;
33303312
"atomic-ipx-tabs": HTMLAtomicIpxTabsElement;
3331-
"atomic-no-results": HTMLAtomicNoResultsElement;
33323313
"atomic-notifications": HTMLAtomicNotificationsElement;
33333314
"atomic-numeric-facet": HTMLAtomicNumericFacetElement;
33343315
"atomic-popover": HTMLAtomicPopoverElement;
@@ -4407,15 +4388,6 @@ declare namespace LocalJSX {
44074388
}
44084389
interface AtomicIpxTabs {
44094390
}
4410-
/**
4411-
* The `atomic-no-results` component displays search tips and a "Cancel last action" button when there are no results. Any additional content slotted inside of its element will be displayed as well.
4412-
*/
4413-
interface AtomicNoResults {
4414-
/**
4415-
* Whether to display a button which cancels the last available action.
4416-
*/
4417-
"enableCancelLastAction"?: boolean;
4418-
}
44194391
/**
44204392
* The `atomic-notifications` component is responsible for displaying notifications generated by the Coveo Search API (see [Trigger](https://docs.coveo.com/en/1458)).
44214393
*/
@@ -5458,7 +5430,6 @@ declare namespace LocalJSX {
54585430
"atomic-ipx-result-link": AtomicIpxResultLink;
54595431
"atomic-ipx-tab": AtomicIpxTab;
54605432
"atomic-ipx-tabs": AtomicIpxTabs;
5461-
"atomic-no-results": AtomicNoResults;
54625433
"atomic-notifications": AtomicNotifications;
54635434
"atomic-numeric-facet": AtomicNumericFacet;
54645435
"atomic-popover": AtomicPopover;
@@ -5659,10 +5630,6 @@ declare module "@stencil/core" {
56595630
"atomic-ipx-result-link": LocalJSX.AtomicIpxResultLink & JSXBase.HTMLAttributes<HTMLAtomicIpxResultLinkElement>;
56605631
"atomic-ipx-tab": LocalJSX.AtomicIpxTab & JSXBase.HTMLAttributes<HTMLAtomicIpxTabElement>;
56615632
"atomic-ipx-tabs": LocalJSX.AtomicIpxTabs & JSXBase.HTMLAttributes<HTMLAtomicIpxTabsElement>;
5662-
/**
5663-
* The `atomic-no-results` component displays search tips and a "Cancel last action" button when there are no results. Any additional content slotted inside of its element will be displayed as well.
5664-
*/
5665-
"atomic-no-results": LocalJSX.AtomicNoResults & JSXBase.HTMLAttributes<HTMLAtomicNoResultsElement>;
56665633
/**
56675634
* The `atomic-notifications` component is responsible for displaying notifications generated by the Coveo Search API (see [Trigger](https://docs.coveo.com/en/1458)).
56685635
*/
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import type {i18n} from 'i18next';
2+
import {html} from 'lit';
3+
import {beforeAll, describe, expect, it, vi} from 'vitest';
4+
import {renderFunctionFixture} from '@/vitest-utils/testing-helpers/fixture';
5+
import {createTestI18n} from '@/vitest-utils/testing-helpers/i18n-utils';
6+
import {type CancelProps, renderCancel} from './cancel';
7+
8+
describe('#renderCancel', () => {
9+
let i18n: i18n;
10+
11+
beforeAll(async () => {
12+
i18n = await createTestI18n();
13+
});
14+
15+
const locators = (element: Element) => ({
16+
get button() {
17+
return element.querySelector('button[part="cancel-button"]');
18+
},
19+
});
20+
21+
const renderComponent = async (props: Partial<CancelProps> = {}) => {
22+
return await renderFunctionFixture(
23+
html`${renderCancel({
24+
props: {
25+
i18n,
26+
onClick: vi.fn(),
27+
...props,
28+
},
29+
})}`
30+
);
31+
};
32+
33+
it('should render with valid props', async () => {
34+
const element = await renderComponent();
35+
expect(element).toBeDefined();
36+
});
37+
38+
it('should render button with the correct part', async () => {
39+
const element = await renderComponent();
40+
const button = locators(element).button;
41+
42+
expect(button).not.toBeNull();
43+
expect(button?.tagName).toBe('BUTTON');
44+
expect(button?.part).toContain('cancel-button');
45+
});
46+
47+
it('should render button with correct text', async () => {
48+
const element = await renderComponent();
49+
const button = locators(element).button;
50+
51+
expect(button).toHaveTextContent('Cancel last action');
52+
});
53+
54+
it('should render button with primary style', async () => {
55+
const element = await renderComponent();
56+
const button = locators(element).button;
57+
58+
expect(button?.classList).toContain('btn-primary');
59+
});
60+
61+
it('should render button with correct classes', async () => {
62+
const element = await renderComponent();
63+
const button = locators(element).button;
64+
65+
expect(button).toHaveClass('my-3', 'px-2.5', 'py-3', 'font-bold');
66+
});
67+
68+
it('should call onClick when button is clicked', async () => {
69+
const handleClick = vi.fn();
70+
const element = await renderComponent({onClick: handleClick});
71+
const button = locators(element).button as HTMLButtonElement;
72+
73+
button.click();
74+
75+
expect(handleClick).toHaveBeenCalledOnce();
76+
});
77+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type {i18n} from 'i18next';
2+
import {nothing} from 'lit';
3+
import {renderButton} from '@/src/components/common/button.js';
4+
import type {FunctionalComponent} from '@/src/utils/functional-component-utils';
5+
6+
export interface CancelProps {
7+
i18n: i18n;
8+
onClick: () => void;
9+
}
10+
11+
export const renderCancel: FunctionalComponent<CancelProps> = ({props}) =>
12+
renderButton({
13+
props: {
14+
style: 'primary',
15+
part: 'cancel-button',
16+
text: props.i18n.t('cancel-last-action'),
17+
onClick: props.onClick,
18+
class: 'my-3 px-2.5 py-3 font-bold',
19+
},
20+
})(nothing);

packages/atomic/src/components/common/no-items/cancel.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Meta } from '@storybook/addon-docs/blocks';
2+
import * as AtomicNoResultsStories from './atomic-no-results.new.stories';
3+
import { AtomicDocTemplate } from '../../../../storybook-utils/documentation/atomic-doc-template';
4+
5+
6+
<Meta of={AtomicNoResultsStories} />
7+
8+
<AtomicDocTemplate
9+
stories={AtomicNoResultsStories}
10+
githubPath="search/atomic-no-results/atomic-no-results.ts"
11+
tagName="atomic-no-results"
12+
className="AtomicNoResults"
13+
>
14+
15+
The `atomic-no-results` component displays search tips and a "Cancel last action" button when there are no results. Any additional content slotted inside of its element will be displayed as well.
16+
17+
This component is typically placed within the results section of the search interface layout.
18+
```html
19+
<atomic-search-interface>
20+
...
21+
<atomic-search-layout>
22+
...
23+
<atomic-layout-section section="main">
24+
...
25+
<atomic-layout-section section="results">
26+
27+
<atomic-no-results></atomic-no-results>
28+
29+
</atomic-layout-section>
30+
</atomic-layout-section>
31+
</atomic-search-layout>
32+
</atomic-search-interface>
33+
```
34+
35+
</AtomicDocTemplate>

0 commit comments

Comments
 (0)