Skip to content

Commit 7dee429

Browse files
krisctlPrabhakar Kumar
authored and
Prabhakar Kumar
committed
Adds a description to the license numbers displayed in license selection dropdown screens.
1 parent 7c0d881 commit 7dee429

File tree

3 files changed

+45
-17
lines changed

3 files changed

+45
-17
lines changed

gui/src/components/App/index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,14 @@ function App() {
168168
// TODO Inline confirmation component build
169169
overlayContent = dialog;
170170
}
171-
// Give precendence to token auth over licensing info ie. once after token auth is done, show licensing if not provided.
171+
// Give precedence to token auth over licensing info ie. once after token auth is done, show licensing if not provided.
172172
else if((!licensingProvided) && hasFetchedServerStatus && (!authEnabled || isAuthenticated)) {
173173
overlayContent = <LicensingGatherer role="licensing" aria-describedby="license-window" />;
174174
}
175175
// Show license selector if the user has entitlements and is not currently entitled
176176
else if (hasEntitlements && !isEntitled) {
177-
const options = licensingInfo.entitlements.map((entitlement) => ({
178-
label: entitlement.license_number,
179-
value: entitlement.id,
180-
}));
181-
overlayContent = <EntitlementSelector options={options} />;
182-
}
177+
overlayContent = <EntitlementSelector options={licensingInfo.entitlements} />;
178+
}
183179
// in all other cases, we will either ask for the token,
184180
else if (!dialog) {
185181
overlayContent = (

gui/src/components/EntitlementSelector/EntitlementSelector.spec.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import EntitlementSelector from "./index";
55
import App from "../App";
66
import { render, fireEvent } from "../../test/utils/react-test";
77
import userEvent from "@testing-library/user-event";
8+
import { filterAndFormatEntitlements, defaultLicenseUnavailableMsg } from "./index";
89

910
describe("EntitlementSelector Component", () => {
1011
let initialState;
1112

13+
1214
beforeEach(() => {
1315
initialState = {
1416
triggerPosition: { x: 539, y: 0 },
@@ -47,9 +49,13 @@ describe("EntitlementSelector Component", () => {
4749
});
4850

4951
const options = [
50-
{ value: "license1", label: "Entitlement1" },
51-
{ value: "license2", label: "Entitlement2" },
52-
{ value: "license3", label: "Entitlement3" },
52+
{ id: "entitlement1", label: "label1", license_number: "license1" },
53+
{ id: "entitlement2", label: "label2", license_number: "license2" },
54+
{ id: "entitlement3", label: "label3", license_number: "license3" },
55+
{ id: "entitlement4", label: "label4", license_number: null },
56+
{ id: "entitlement5", label: "label5", license_number: "" },
57+
{ id: "entitlement6", label: null, license_number: "license6" },
58+
{ id: "entitlement7", label: "", license_number: "license7" },
5359
];
5460

5561
function setup(jsx) {
@@ -67,18 +73,18 @@ describe("EntitlementSelector Component", () => {
6773
const { getByRole } = render(<EntitlementSelector options={options} />);
6874

6975
let comboBox = getByRole("combobox");
70-
expect(comboBox.length).toBe(3);
71-
expect(comboBox).toHaveValue("license1");
72-
expect(getByRole("option", { name: "Entitlement1" }).selected).toBe(true);
76+
expect(comboBox.length).toBeGreaterThanOrEqual(3);
77+
expect(comboBox).toHaveValue("entitlement1");
78+
expect(getByRole("option", { name: "license1 - label1" }).selected).toBe(true);
7379
});
7480

7581
it("should select correct value on change", async () => {
7682
const { user, getByRole } = setup(
7783
<EntitlementSelector options={options} />
7884
);
7985
let comboBox = getByRole("combobox");
80-
await user.selectOptions(comboBox, "license2");
81-
expect(comboBox).toHaveValue("license2");
86+
await user.selectOptions(comboBox, "entitlement2");
87+
expect(comboBox).toHaveValue("entitlement2");
8288
});
8389

8490
it("should fire onClick Event for submit button without crashing", () => {
@@ -101,4 +107,18 @@ describe("EntitlementSelector Component", () => {
101107
container.querySelector("#entitlement-selection")
102108
).not.toBeInTheDocument();
103109
});
110+
111+
it("should filter and format entitlements correctly", async () => {
112+
const formattedEntitlements = filterAndFormatEntitlements(options);
113+
114+
expect(formattedEntitlements).toEqual([
115+
{ label: "license1 - label1", value: "entitlement1" },
116+
{ label: "license2 - label2", value: "entitlement2" },
117+
{ label: "license3 - label3", value: "entitlement3" },
118+
{ label: `license6 - ${defaultLicenseUnavailableMsg}`, value: "entitlement6" },
119+
{ label: `license7 - ${defaultLicenseUnavailableMsg}`, value: "entitlement7" },
120+
]);
121+
122+
});
123+
104124
});

gui/src/components/EntitlementSelector/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,21 @@ import { useState } from "react";
44
import { useDispatch } from "react-redux";
55
import { fetchUpdateLicensing } from "../../actionCreators";
66

7+
export const defaultLicenseUnavailableMsg = "License description unavailable";
8+
9+
export function filterAndFormatEntitlements(entitlements) {
10+
return entitlements
11+
.filter(entitlement => entitlement.license_number && entitlement.license_number.trim() !== "")
12+
.map(entitlement => ({
13+
label: `${entitlement.license_number} - ${entitlement.label || defaultLicenseUnavailableMsg}`,
14+
value: entitlement.id,
15+
}));
16+
};
17+
718
function EntitlementSelector({ options }) {
819
const dispatch = useDispatch();
9-
const [selectedEntitlement, setSelected] = useState(options[0].value);
20+
const filteredOptions = filterAndFormatEntitlements(options);
21+
const [selectedEntitlement, setSelected] = useState(filteredOptions[0].value);
1022

1123
function updateEntitlement(event) {
1224
event.preventDefault();
@@ -38,7 +50,7 @@ function EntitlementSelector({ options }) {
3850
value={selectedEntitlement}
3951
onChange={(e) => setSelected(e.target.value)}
4052
>
41-
{options.map((entitlement) => (
53+
{filteredOptions.map((entitlement) => (
4254
<option value={entitlement.value} key={entitlement.label}>
4355
{entitlement.label}
4456
</option>

0 commit comments

Comments
 (0)