+
+ ,
+ )
+ .withApis([
+ [scmIntegrationsApiRef, { byUrl }],
+ [entityPresentationApiRef, entityPresentationApiMock],
+ ])
+ .renderWithEffects();
(shadowRoot as ShadowRoot & Pick
+
+
+
-
-
+
-
- ,
- )
- .withApis([
- [scmIntegrationsApiRef, { byUrl }],
- [entityPresentationApiRef, entityPresentationApiMock],
- ])
- .renderWithEffects();
+
+
+ ,
+ )
+ .withApis([
+ [scmIntegrationsApiRef, { byUrl }],
+ [entityPresentationApiRef, entityPresentationApiMock],
+ ])
+ .renderWithEffects();
(shadowRoot as ShadowRoot & Pick
).getSelection =
() => selection;
await waitFor(() => {
- expect(getByText('Edit page')).toBeInTheDocument();
+ expect(screen.getByShadowText('Edit page')).toBeInTheDocument();
});
fireSelectionChangeEvent(window);
await waitFor(() => {
- expect(queryByTestId('report-issue-addon')).toBeInTheDocument();
+ expect(
+ screen.getByShadowTestId('report-issue-addon'),
+ ).toBeInTheDocument();
- const link = getByText('Open new Gitlab issue');
+ const link = screen.getByShadowText('Open new Gitlab issue');
expect(link).toHaveAttribute(
'href',
'https://gitlab.com/backstage/backstage/issues/new?issue[title]=Documentation%20feedback%3A%20his%20&issue[description]=%23%23%20Documentation%20Feedback%20%F0%9F%93%9D%0A%0A%20%23%23%23%23%20The%20highlighted%20text%3A%20%0A%0A%20%3E%20his%0A%0A%20%23%23%23%23%20The%20comment%20on%20the%20text%3A%20%0A%20_%3Ereplace%20this%20line%20with%20your%20comment%3C_%0A%0A%20___%0ABackstage%20URL%3A%20%3Chttp%3A%2F%2Flocalhost%2F%3E%20%0AMarkdown%20URL%3A%20%3Chttps%3A%2F%2Fgitlab.com%2Fbackstage%2Fbackstage%2F-%2Fblob%2Fmaster%2Fdocs%2FREADME.md%3E',
@@ -197,60 +198,61 @@ describe('ReportIssue', () => {
body: options.selection.toString().trim(),
});
- const { shadowRoot, getByText, queryByTestId } =
- await TechDocsAddonTester.buildAddonsInTechDocs([
- ,
- ])
- .withDom(
-
-
-
-
-
-
-
+ const { shadowRoot } = await TechDocsAddonTester.buildAddonsInTechDocs([
+
,
+ ])
+ .withDom(
+
+
+
+
+
+
+
-
-
+
-
- ,
- )
- .withApis([
- [scmIntegrationsApiRef, { byUrl }],
- [entityPresentationApiRef, entityPresentationApiMock],
- ])
- .renderWithEffects();
+
+
+ ,
+ )
+ .withApis([
+ [scmIntegrationsApiRef, { byUrl }],
+ [entityPresentationApiRef, entityPresentationApiMock],
+ ])
+ .renderWithEffects();
(shadowRoot as ShadowRoot & Pick
).getSelection =
() => selection;
await waitFor(() => {
- expect(getByText('Edit page')).toBeInTheDocument();
+ expect(screen.getByShadowText('Edit page')).toBeInTheDocument();
});
fireSelectionChangeEvent(window);
await waitFor(() => {
- expect(queryByTestId('report-issue-addon')).toBeInTheDocument();
+ expect(
+ screen.getByShadowTestId('report-issue-addon'),
+ ).toBeInTheDocument();
- const link = getByText('Open new Gitlab issue');
+ const link = screen.getByShadowText('Open new Gitlab issue');
expect(link).toHaveAttribute(
'href',
'https://gitlab.com/backstage/backstage/issues/new?issue[title]=Custom&issue[description]=his',
@@ -261,45 +263,46 @@ describe('ReportIssue', () => {
it('does not render report issue link for unsupported repository type', async () => {
byUrl.mockReturnValue({ type: 'gerrit', resource: 'gerrit.example.com' });
- const { shadowRoot, getByText, queryByTestId } =
- await TechDocsAddonTester.buildAddonsInTechDocs([
- ,
- ])
- .withDom(
-
-
-
-
-
-
+ const { shadowRoot } = await TechDocsAddonTester.buildAddonsInTechDocs([
+
,
+ ])
+ .withDom(
+
+
+
+
+
-
- ,
- )
- .withApis([[scmIntegrationsApiRef, { byUrl }]])
- .renderWithEffects();
+
+
+ ,
+ )
+ .withApis([[scmIntegrationsApiRef, { byUrl }]])
+ .renderWithEffects();
(shadowRoot as ShadowRoot & Pick
).getSelection =
() => selection;
await waitFor(() => {
- expect(getByText('Edit page')).toBeInTheDocument();
+ expect(screen.getByShadowText('Edit page')).toBeInTheDocument();
});
fireSelectionChangeEvent(window);
await waitFor(() => {
- expect(queryByTestId('report-issue-addon')).not.toBeInTheDocument();
+ expect(
+ screen.queryByShadowTestId('report-issue-addon'),
+ ).not.toBeInTheDocument();
});
});
});
diff --git a/plugins/techdocs-module-addons-contrib/src/TextSize/TextSize.test.tsx b/plugins/techdocs-module-addons-contrib/src/TextSize/TextSize.test.tsx
index 92cab255a7..03571c1cd1 100644
--- a/plugins/techdocs-module-addons-contrib/src/TextSize/TextSize.test.tsx
+++ b/plugins/techdocs-module-addons-contrib/src/TextSize/TextSize.test.tsx
@@ -16,6 +16,7 @@
import { TechDocsAddonTester } from '@backstage/plugin-techdocs-addons-test-utils';
import { act, fireEvent, waitFor } from '@testing-library/react';
+import { screen } from 'shadow-dom-testing-library';
import { TextSize } from '../plugin';
import { useShadowRootElements } from '@backstage/plugin-techdocs-react';
import { entityPresentationApiRef } from '@backstage/plugin-catalog-react';
@@ -42,33 +43,30 @@ describe('TextSize', () => {
});
it('renders without exploding', async () => {
- const { getByText } = await TechDocsAddonTester.buildAddonsInTechDocs([
- ,
- ])
+ await TechDocsAddonTester.buildAddonsInTechDocs([])
.withDom(TEST_CONTENT)
.withApis([[entityPresentationApiRef, entityPresentationApiMock]])
.renderWithEffects();
- expect(getByText('TEST_CONTENT')).toBeInTheDocument();
+ expect(screen.getByShadowText('TEST_CONTENT')).toBeInTheDocument();
});
it('changes content text size using slider', async () => {
- const { getByTitle, getByText, getByRole, getByDisplayValue } =
- await TechDocsAddonTester.buildAddonsInTechDocs([])
- .withDom(TEST_CONTENT)
- .withApis([[entityPresentationApiRef, entityPresentationApiMock]])
- .renderWithEffects();
+ await TechDocsAddonTester.buildAddonsInTechDocs([])
+ .withDom(TEST_CONTENT)
+ .withApis([[entityPresentationApiRef, entityPresentationApiMock]])
+ .renderWithEffects();
- const content = getByText('TEST_CONTENT');
+ const content = screen.getByShadowText('TEST_CONTENT');
useShadowRootElementsMock.mockReturnValue([content]);
- fireEvent.click(getByTitle('Settings'));
+ fireEvent.click(screen.getByShadowTitle('Settings'));
await waitFor(() => {
- expect(getByText('Text size')).toBeInTheDocument();
+ expect(screen.getByShadowText('Text size')).toBeInTheDocument();
});
- const slider = getByRole('slider');
+ const slider = screen.getByShadowRole('slider');
act(() => {
slider.focus();
@@ -79,12 +77,12 @@ describe('TextSize', () => {
});
await waitFor(() => {
- expect(getByDisplayValue('115')).toBeInTheDocument();
+ expect(screen.getByShadowDisplayValue('115')).toBeInTheDocument();
});
expect(slider).toHaveTextContent('115%');
- let style = window.getComputedStyle(getByText('TEST_CONTENT'));
+ let style = window.getComputedStyle(screen.getByShadowText('TEST_CONTENT'));
await waitFor(() => {
expect(style.getPropertyValue('--md-typeset-font-size')).toBe('18.4px');
@@ -95,60 +93,54 @@ describe('TextSize', () => {
});
await waitFor(() => {
- expect(getByDisplayValue('100')).toBeInTheDocument();
+ expect(screen.getByShadowDisplayValue('100')).toBeInTheDocument();
});
expect(slider).toHaveTextContent('100%');
- style = window.getComputedStyle(getByText('TEST_CONTENT'));
+ style = window.getComputedStyle(screen.getByShadowText('TEST_CONTENT'));
expect(style.getPropertyValue('--md-typeset-font-size')).toBe('16px');
});
it('changes content text size using buttons', async () => {
- const {
- getByTitle,
- getByText,
- getByRole,
- getByLabelText,
- getByDisplayValue,
- } = await TechDocsAddonTester.buildAddonsInTechDocs([])
+ await TechDocsAddonTester.buildAddonsInTechDocs([])
.withDom(TEST_CONTENT)
.withApis([[entityPresentationApiRef, entityPresentationApiMock]])
.renderWithEffects();
- const content = getByText('TEST_CONTENT');
+ const content = screen.getByShadowText('TEST_CONTENT');
useShadowRootElementsMock.mockReturnValue([content]);
- fireEvent.click(getByTitle('Settings'));
+ fireEvent.click(screen.getByShadowTitle('Settings'));
await waitFor(() => {
- expect(getByText('Text size')).toBeInTheDocument();
+ expect(screen.getByShadowText('Text size')).toBeInTheDocument();
});
- fireEvent.click(getByLabelText('Increase text size'));
+ fireEvent.click(screen.getByShadowLabelText('Increase text size'));
await waitFor(() => {
- expect(getByDisplayValue('115')).toBeInTheDocument();
+ expect(screen.getByShadowDisplayValue('115')).toBeInTheDocument();
});
- const slider = getByRole('slider');
+ const slider = screen.getByShadowRole('slider');
expect(slider).toHaveTextContent('115%');
- let style = window.getComputedStyle(getByText('TEST_CONTENT'));
+ let style = window.getComputedStyle(screen.getByShadowText('TEST_CONTENT'));
expect(style.getPropertyValue('--md-typeset-font-size')).toBe('18.4px');
- fireEvent.click(getByLabelText('Decrease text size'));
+ fireEvent.click(screen.getByShadowLabelText('Decrease text size'));
await waitFor(() => {
- expect(getByDisplayValue('100')).toBeInTheDocument();
+ expect(screen.getByShadowDisplayValue('100')).toBeInTheDocument();
});
expect(slider).toHaveTextContent('100%');
- style = window.getComputedStyle(getByText('TEST_CONTENT'));
+ style = window.getComputedStyle(screen.getByShadowText('TEST_CONTENT'));
expect(style.getPropertyValue('--md-typeset-font-size')).toBe('16px');
});
diff --git a/yarn.lock b/yarn.lock
index 3502df3388..604f87054a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -7362,7 +7362,7 @@ __metadata:
react: "npm:^18.0.2"
react-dom: "npm:^18.0.2"
react-router-dom: "npm:^6.3.0"
- testing-library__dom: "npm:^7.29.4-beta.1"
+ shadow-dom-testing-library: "npm:^1.13.1"
peerDependencies:
"@testing-library/react": ^16.0.0
"@types/react": ^17.0.0 || ^18.0.0
@@ -7437,6 +7437,7 @@ __metadata:
react: "npm:^18.0.2"
react-dom: "npm:^18.0.2"
react-router-dom: "npm:^6.3.0"
+ shadow-dom-testing-library: "npm:^1.13.1"
peerDependencies:
"@types/react": ^17.0.0 || ^18.0.0
react: ^17.0.0 || ^18.0.0
@@ -45240,6 +45241,15 @@ __metadata:
languageName: node
linkType: hard
+"shadow-dom-testing-library@npm:^1.13.1":
+ version: 1.13.1
+ resolution: "shadow-dom-testing-library@npm:1.13.1"
+ peerDependencies:
+ "@testing-library/dom": ">= 8"
+ checksum: 10/a10f3466592691368f260c15230d9e830cc5122d20002ad9b6c2918fa245089219d1f45c026153fa6ccf8848b546da6f985c0e461458c8c1e09786a1de626287
+ languageName: node
+ linkType: hard
+
"shallow-clone@npm:^3.0.0":
version: 3.0.1
resolution: "shallow-clone@npm:3.0.1"
@@ -47166,13 +47176,6 @@ __metadata:
languageName: node
linkType: hard
-"testing-library__dom@npm:^7.29.4-beta.1":
- version: 7.29.4-beta.1
- resolution: "testing-library__dom@npm:7.29.4-beta.1"
- checksum: 10/d912418803b77df672c0894d053327a4b366cf7e5312dfb73bd2089d36272e2b38bccc1bd7284d9ed2f9f6530797778d0f72e94b8a44fe5d0327d11e7f757f2b
- languageName: node
- linkType: hard
-
"text-decoder@npm:^1.1.0":
version: 1.2.3
resolution: "text-decoder@npm:1.2.3"