Skip to content

Commit f9dfa0e

Browse files
authored
docs(cypress-commands): show deprecation notice in docs (#7396)
1 parent 8175280 commit f9dfa0e

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

.storybook/components/CommandsAndQueries.tsx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Heading, Markdown } from '@storybook/blocks';
2+
import { Tag as WCRTag } from '@ui5/webcomponents-react';
23
import dedent from 'dedent';
34
import { Fragment } from 'react';
45

@@ -116,6 +117,7 @@ interface FunctionMetadata {
116117
members: Members;
117118
path: Path[];
118119
namespace: string;
120+
deprecated: Record<string, any>;
119121
}
120122

121123
function generateMdCodeBlock(codeStr: string) {
@@ -196,13 +198,37 @@ function generateDescription(description: RootNode) {
196198
}, '');
197199
}
198200

201+
function formatHtmlFromNode(node: any): string {
202+
if (!node) return '';
203+
204+
switch (node.type) {
205+
case 'root':
206+
return node.children.map(formatHtmlFromNode).join('');
207+
case 'paragraph':
208+
return `<p>${node.children.map(formatHtmlFromNode).join('')}</p>`;
209+
case 'text':
210+
return node.value;
211+
case 'inlineCode':
212+
return `<code>${node.value}</code>`;
213+
default:
214+
return '';
215+
}
216+
}
217+
199218
export const CommandsAndQueries = ({ api }: { api: FunctionMetadata[] }) => {
200219
return api
201220
.sort((a, b) => a.name.localeCompare(b.name))
202221
.map((item) => {
203222
return (
204223
<Fragment key={item.name}>
205-
<Heading>{item.name}</Heading>
224+
<Heading>
225+
{item.name}
226+
{!!item.deprecated && (
227+
<WCRTag style={{ marginInlineStart: '1rem' }} design="Critical">
228+
deprecated
229+
</WCRTag>
230+
)}
231+
</Heading>
206232
<code>
207233
{item.name}(
208234
{item.params
@@ -215,6 +241,12 @@ export const CommandsAndQueries = ({ api }: { api: FunctionMetadata[] }) => {
215241
return generateGenericType(type);
216242
})}
217243
</code>
244+
{!!item.deprecated && (
245+
<>
246+
<br />
247+
{<b dangerouslySetInnerHTML={{ __html: formatHtmlFromNode(item.deprecated) }} />}
248+
</>
249+
)}
218250
<Markdown>{generateDescription(item.description)}</Markdown>
219251
{generateExample(item.tags)}
220252
{!!item.params.length && (

packages/cypress-commands/src/commands.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ declare global {
8484
* @param text text of the ui5-option that should be clicked
8585
* @param options ClickOptions
8686
*
87+
* @deprecated This command is deprecated. Please use `clickDropdownMenuItemByText` instead.
8788
*
8889
* @example cy.get('[ui5-select]').clickUi5SelectOptionByText('Option2');
8990
*/
@@ -94,7 +95,7 @@ declare global {
9495
*
9596
* __Note:__ The select popover must be visible, otherwise it can lead to unwanted side effects.
9697
*
97-
* @deprecated: This command is deprecated. Please use `clickDropdownMenuItem` instead.
98+
* @deprecated This command is deprecated. Please use `clickDropdownMenuItem` instead.
9899
*
99100
* @example cy.get('[ui5-option]').clickUi5SelectOption();
100101
*/
@@ -208,6 +209,14 @@ Cypress.Commands.add('clickUi5ListItemByText', { prevSubject: 'optional' }, (sub
208209
});
209210

210211
Cypress.Commands.add('clickUi5SelectOptionByText', { prevSubject: 'element' }, (subject, text, options = {}) => {
212+
Cypress.log({
213+
name: 'Deprecation',
214+
message: ['`clickUi5SelectOptionByText` is deprecated! Please use `clickDropdownMenuItemByText` instead.'],
215+
consoleProps: () => ({
216+
deprecated: 'clickUi5SelectOptionByText',
217+
replacement: 'clickDropdownMenuItemByText',
218+
}),
219+
});
211220
cy.wrap(subject)
212221
.contains(text)
213222
.then(($option) => {
@@ -217,6 +226,14 @@ Cypress.Commands.add('clickUi5SelectOptionByText', { prevSubject: 'element' }, (
217226
});
218227

219228
Cypress.Commands.add('clickUi5SelectOption', { prevSubject: 'element' }, (subject, options = {}) => {
229+
Cypress.log({
230+
name: 'Deprecation',
231+
message: ['`clickUi5SelectOption` is deprecated! Please use `clickDropdownMenuItem` instead.'],
232+
consoleProps: () => ({
233+
deprecated: 'clickUi5SelectOption',
234+
replacement: 'clickDropdownMenuItem',
235+
}),
236+
});
220237
cy.wrap(subject).then(($option) => {
221238
// @ts-expect-error: cannot set $option to use OptionDomRef
222239
const domRef = $option.get(0).getDomRef();

0 commit comments

Comments
 (0)