-
Notifications
You must be signed in to change notification settings - Fork 165
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
feat(user-settings): allow overriding build info in the user settings page #2564
Open
debsmita1
wants to merge
2
commits into
redhat-developer:main
Choose a base branch
from
debsmita1:build-info
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.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 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
34 changes: 34 additions & 0 deletions
34
e2e-tests/playwright/e2e/plugins/user-settings-info-card.spec.ts
This file contains 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,34 @@ | ||
import { test } from "@playwright/test"; | ||
import { Common } from "../../utils/common"; | ||
import { UIhelper } from "../../utils/ui-helper"; | ||
import { UI_HELPER_ELEMENTS } from "../../support/pageObjects/global-obj"; | ||
|
||
test.describe("Test user settings info card", () => { | ||
let uiHelper: UIhelper; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
const common = new Common(page); | ||
await common.loginAsGuest(); | ||
|
||
uiHelper = new UIhelper(page); | ||
}); | ||
|
||
test("Check if customized build info is rendered", async ({ page }) => { | ||
await uiHelper.openSidebar("Home"); | ||
page.getByText("Guest").click(); | ||
await page.getByRole("menuitem", { name: "Settings" }).click(); | ||
await uiHelper.verifyTextInSelector( | ||
UI_HELPER_ELEMENTS.MuiCardHeader, | ||
"RHDH Build info", | ||
); | ||
await uiHelper.verifyTextInSelector( | ||
UI_HELPER_ELEMENTS.MuiCard("RHDH Build info"), | ||
"TechDocs builder: local\nAuthentication provider: Github", | ||
); | ||
await page.getByTitle("Show more").click(); | ||
await uiHelper.verifyTextInSelector( | ||
UI_HELPER_ELEMENTS.MuiCard("RHDH Build info"), | ||
"TechDocs builder: local\nAuthentication provider: Github\nRBAC: disabled", | ||
); | ||
}); | ||
}); |
This file contains 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 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,8 +1,8 @@ | ||
{ | ||
"title": "RHDH Metadata", | ||
"card": [ | ||
"RHDH Version: 1.6.0", | ||
"Backstage Version: 1.36.1", | ||
"Last Commit: repo @ 2025-03-17T17:01:16Z" | ||
] | ||
"card": { | ||
"RHDH Version": "1.6.0", | ||
"Backstage Version": "1.36.1", | ||
"Last Commit": "repo @ 2025-03-17T17:01:16Z" | ||
} | ||
} |
134 changes: 131 additions & 3 deletions
134
packages/app/src/components/UserSettings/InfoCard.test.tsx
This file contains 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,20 +1,148 @@ | ||
import { renderInTestApp } from '@backstage/test-utils'; | ||
import { configApiRef } from '@backstage/core-plugin-api'; | ||
import { | ||
mockApis, | ||
renderInTestApp, | ||
TestApiProvider, | ||
} from '@backstage/test-utils'; | ||
|
||
import { userEvent } from '@testing-library/user-event'; | ||
|
||
import { InfoCard } from './InfoCard'; | ||
|
||
describe('InfoCard', () => { | ||
it('should render essential versions by default', async () => { | ||
const renderResult = await renderInTestApp(<InfoCard />); | ||
const mockConfig = mockApis.config({ | ||
data: { | ||
buildInfo: {}, | ||
}, | ||
}); | ||
const renderResult = await renderInTestApp( | ||
<TestApiProvider apis={[[configApiRef, mockConfig]]}> | ||
<InfoCard /> | ||
</TestApiProvider>, | ||
); | ||
expect(renderResult.getByText(/RHDH Version/)).toBeInTheDocument(); | ||
expect(renderResult.getByText(/Backstage Version/)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should hide the build time by default and show it on click', async () => { | ||
const renderResult = await renderInTestApp(<InfoCard />); | ||
const mockConfig = mockApis.config({ | ||
data: { | ||
buildInfo: {}, | ||
}, | ||
}); | ||
const renderResult = await renderInTestApp( | ||
<TestApiProvider apis={[[configApiRef, mockConfig]]}> | ||
<InfoCard /> | ||
</TestApiProvider>, | ||
); | ||
expect(renderResult.queryByText(/Last Commit/)).toBeNull(); | ||
await userEvent.click(renderResult.getByText(/RHDH Version/)); | ||
expect(renderResult.getByText(/Last Commit/)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the customized values when build info is configured', async () => { | ||
const mockConfig = mockApis.config({ | ||
data: { | ||
buildInfo: { | ||
title: 'RHDH Build info', | ||
card: { | ||
'TechDocs builder': 'local', | ||
'Authentication provider': 'Github', | ||
RBAC: 'disabled', | ||
}, | ||
}, | ||
}, | ||
}); | ||
const renderResult = await renderInTestApp( | ||
<TestApiProvider apis={[[configApiRef, mockConfig]]}> | ||
<InfoCard /> | ||
</TestApiProvider>, | ||
); | ||
expect(renderResult.queryByText(/TechDocs builder/)).toBeInTheDocument(); | ||
expect( | ||
renderResult.queryByText(/Authentication provider/), | ||
).toBeInTheDocument(); | ||
await userEvent.click(renderResult.getByText(/TechDocs builder/)); | ||
expect(renderResult.getByText(/RBAC/)).toBeInTheDocument(); | ||
expect(renderResult.queryByText(/Last Commit/)).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should append the customized values along with RHDH versions when build info is configured with `full` set to false', async () => { | ||
const mockConfig = mockApis.config({ | ||
data: { | ||
buildInfo: { | ||
title: 'RHDH Build info', | ||
card: { | ||
'TechDocs builder': 'local', | ||
'Authentication provider': 'Github', | ||
RBAC: 'disabled', | ||
}, | ||
full: false, | ||
}, | ||
}, | ||
}); | ||
const renderResult = await renderInTestApp( | ||
<TestApiProvider apis={[[configApiRef, mockConfig]]}> | ||
<InfoCard /> | ||
</TestApiProvider>, | ||
); | ||
expect(renderResult.queryByText(/TechDocs builder/)).toBeInTheDocument(); | ||
expect( | ||
renderResult.queryByText(/Authentication provider/), | ||
).toBeInTheDocument(); | ||
await userEvent.click(renderResult.getByText(/TechDocs builder/)); | ||
expect(renderResult.getByText(/RBAC/)).toBeInTheDocument(); | ||
expect(renderResult.queryByText(/Last Commit/)).toBeInTheDocument(); | ||
expect(renderResult.queryByText(/RHDH Version/)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should display only the customized values when build info is configured with full set to true, without appending RHDH versions', async () => { | ||
const mockConfig = mockApis.config({ | ||
data: { | ||
buildInfo: { | ||
title: 'RHDH Build info', | ||
card: { | ||
'TechDocs builder': 'local', | ||
'Authentication provider': 'Github', | ||
RBAC: 'disabled', | ||
}, | ||
full: true, | ||
}, | ||
}, | ||
}); | ||
const renderResult = await renderInTestApp( | ||
<TestApiProvider apis={[[configApiRef, mockConfig]]}> | ||
<InfoCard /> | ||
</TestApiProvider>, | ||
); | ||
expect(renderResult.queryByText(/TechDocs builder/)).toBeInTheDocument(); | ||
expect( | ||
renderResult.queryByText(/Authentication provider/), | ||
).toBeInTheDocument(); | ||
await userEvent.click(renderResult.getByText(/TechDocs builder/)); | ||
expect(renderResult.getByText(/RBAC/)).toBeInTheDocument(); | ||
expect(renderResult.queryByText(/Last Commit/)).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should fallback to default json if the customized card value is empty', async () => { | ||
const mockConfig = mockApis.config({ | ||
data: { | ||
buildInfo: { | ||
title: 'RHDH Build info', | ||
card: undefined, | ||
}, | ||
}, | ||
}); | ||
const renderResult = await renderInTestApp( | ||
<TestApiProvider apis={[[configApiRef, mockConfig]]}> | ||
<InfoCard /> | ||
</TestApiProvider>, | ||
); | ||
expect( | ||
renderResult.queryByText(/TechDocs builder/), | ||
).not.toBeInTheDocument(); | ||
expect(renderResult.getByText(/RHDH Version/)).toBeInTheDocument(); | ||
expect(renderResult.getByText(/Backstage Version/)).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this file is generated in the build process. Maybe also in the midstream repo on GitLab.
I recommend to check this with @nickboldt, or maybe you can support an object and an array to support the old format (and revert this)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a comment from @nickboldt here about revamping the file
I was under the impression that this file is somehow manually built
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's generated in this repo, then I apply a
sed
transformation downstream to spiff it up and add more build information (the up and midstream repo commits, and the build time).-- https://gitlab.cee.redhat.com/rhidp/rhdh/-/blob/rhdh-1-rhel-9/build/ci/sync-midstream.sh#L605-607
If you change the file format, just let me know so I can adjust the downstream sed changes. Or even better, throw me a PR to update the script above to properly adopt your changes! :D