|
1 |
| -import { renderInTestApp } from '@backstage/test-utils'; |
| 1 | +import { configApiRef } from '@backstage/core-plugin-api'; |
| 2 | +import { |
| 3 | + mockApis, |
| 4 | + renderInTestApp, |
| 5 | + TestApiProvider, |
| 6 | +} from '@backstage/test-utils'; |
2 | 7 |
|
3 | 8 | import { userEvent } from '@testing-library/user-event';
|
4 | 9 |
|
5 | 10 | import { InfoCard } from './InfoCard';
|
6 | 11 |
|
7 | 12 | describe('InfoCard', () => {
|
8 | 13 | it('should render essential versions by default', async () => {
|
9 |
| - const renderResult = await renderInTestApp(<InfoCard />); |
| 14 | + const mockConfig = mockApis.config({ |
| 15 | + data: { |
| 16 | + buildInfo: {}, |
| 17 | + }, |
| 18 | + }); |
| 19 | + const renderResult = await renderInTestApp( |
| 20 | + <TestApiProvider apis={[[configApiRef, mockConfig]]}> |
| 21 | + <InfoCard /> |
| 22 | + </TestApiProvider>, |
| 23 | + ); |
10 | 24 | expect(renderResult.getByText(/RHDH Version/)).toBeInTheDocument();
|
11 | 25 | expect(renderResult.getByText(/Backstage Version/)).toBeInTheDocument();
|
12 | 26 | });
|
13 | 27 |
|
14 | 28 | it('should hide the build time by default and show it on click', async () => {
|
15 |
| - const renderResult = await renderInTestApp(<InfoCard />); |
| 29 | + const mockConfig = mockApis.config({ |
| 30 | + data: { |
| 31 | + buildInfo: {}, |
| 32 | + }, |
| 33 | + }); |
| 34 | + const renderResult = await renderInTestApp( |
| 35 | + <TestApiProvider apis={[[configApiRef, mockConfig]]}> |
| 36 | + <InfoCard /> |
| 37 | + </TestApiProvider>, |
| 38 | + ); |
16 | 39 | expect(renderResult.queryByText(/Last Commit/)).toBeNull();
|
17 | 40 | await userEvent.click(renderResult.getByText(/RHDH Version/));
|
18 | 41 | expect(renderResult.getByText(/Last Commit/)).toBeInTheDocument();
|
19 | 42 | });
|
| 43 | + |
| 44 | + it('should render the customized values when build info is configured', async () => { |
| 45 | + const mockConfig = mockApis.config({ |
| 46 | + data: { |
| 47 | + buildInfo: { |
| 48 | + title: 'RHDH Build info', |
| 49 | + card: { |
| 50 | + 'TechDocs builder': 'local', |
| 51 | + 'Authentication provider': 'Github', |
| 52 | + RBAC: 'disabled', |
| 53 | + }, |
| 54 | + }, |
| 55 | + }, |
| 56 | + }); |
| 57 | + const renderResult = await renderInTestApp( |
| 58 | + <TestApiProvider apis={[[configApiRef, mockConfig]]}> |
| 59 | + <InfoCard /> |
| 60 | + </TestApiProvider>, |
| 61 | + ); |
| 62 | + expect(renderResult.queryByText(/TechDocs builder/)).toBeInTheDocument(); |
| 63 | + expect( |
| 64 | + renderResult.queryByText(/Authentication provider/), |
| 65 | + ).toBeInTheDocument(); |
| 66 | + await userEvent.click(renderResult.getByText(/TechDocs builder/)); |
| 67 | + expect(renderResult.getByText(/RBAC/)).toBeInTheDocument(); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should append the customized values along with RHDH versions when build info is configured with `full` set to false', async () => { |
| 71 | + const mockConfig = mockApis.config({ |
| 72 | + data: { |
| 73 | + buildInfo: { |
| 74 | + title: 'RHDH Build info', |
| 75 | + card: { |
| 76 | + 'TechDocs builder': 'local', |
| 77 | + 'Authentication provider': 'Github', |
| 78 | + RBAC: 'disabled', |
| 79 | + }, |
| 80 | + full: false, |
| 81 | + }, |
| 82 | + }, |
| 83 | + }); |
| 84 | + const renderResult = await renderInTestApp( |
| 85 | + <TestApiProvider apis={[[configApiRef, mockConfig]]}> |
| 86 | + <InfoCard /> |
| 87 | + </TestApiProvider>, |
| 88 | + ); |
| 89 | + expect(renderResult.queryByText(/TechDocs builder/)).toBeInTheDocument(); |
| 90 | + expect( |
| 91 | + renderResult.queryByText(/Authentication provider/), |
| 92 | + ).toBeInTheDocument(); |
| 93 | + await userEvent.click(renderResult.getByText(/TechDocs builder/)); |
| 94 | + expect(renderResult.getByText(/RBAC/)).toBeInTheDocument(); |
| 95 | + expect(renderResult.queryByText(/Last Commit/)).toBeInTheDocument(); |
| 96 | + expect(renderResult.queryByText(/RHDH Version/)).toBeInTheDocument(); |
| 97 | + }); |
| 98 | + |
| 99 | + it('should display only the customized values when build info is configured with full set to true, without appending RHDH versions', async () => { |
| 100 | + const mockConfig = mockApis.config({ |
| 101 | + data: { |
| 102 | + buildInfo: { |
| 103 | + title: 'RHDH Build info', |
| 104 | + card: { |
| 105 | + 'TechDocs builder': 'local', |
| 106 | + 'Authentication provider': 'Github', |
| 107 | + RBAC: 'disabled', |
| 108 | + }, |
| 109 | + full: true, |
| 110 | + }, |
| 111 | + }, |
| 112 | + }); |
| 113 | + const renderResult = await renderInTestApp( |
| 114 | + <TestApiProvider apis={[[configApiRef, mockConfig]]}> |
| 115 | + <InfoCard /> |
| 116 | + </TestApiProvider>, |
| 117 | + ); |
| 118 | + expect(renderResult.queryByText(/TechDocs builder/)).toBeInTheDocument(); |
| 119 | + expect( |
| 120 | + renderResult.queryByText(/Authentication provider/), |
| 121 | + ).toBeInTheDocument(); |
| 122 | + await userEvent.click(renderResult.getByText(/TechDocs builder/)); |
| 123 | + expect(renderResult.getByText(/RBAC/)).toBeInTheDocument(); |
| 124 | + expect(renderResult.queryByText(/Last Commit/)).not.toBeInTheDocument(); |
| 125 | + }); |
| 126 | + |
| 127 | + it('should fallback to default json if the customized card value is empty', async () => { |
| 128 | + const mockConfig = mockApis.config({ |
| 129 | + data: { |
| 130 | + buildInfo: { |
| 131 | + title: 'RHDH Build info', |
| 132 | + card: undefined, |
| 133 | + }, |
| 134 | + }, |
| 135 | + }); |
| 136 | + const renderResult = await renderInTestApp( |
| 137 | + <TestApiProvider apis={[[configApiRef, mockConfig]]}> |
| 138 | + <InfoCard /> |
| 139 | + </TestApiProvider>, |
| 140 | + ); |
| 141 | + expect( |
| 142 | + renderResult.queryByText(/TechDocs builder/), |
| 143 | + ).not.toBeInTheDocument(); |
| 144 | + expect(renderResult.getByText(/RHDH Version/)).toBeInTheDocument(); |
| 145 | + expect(renderResult.getByText(/Backstage Version/)).toBeInTheDocument(); |
| 146 | + }); |
20 | 147 | });
|
0 commit comments