@@ -5,10 +5,12 @@ import EntitlementSelector from "./index";
55import App from "../App" ;
66import { render , fireEvent } from "../../test/utils/react-test" ;
77import userEvent from "@testing-library/user-event" ;
8+ import { filterAndFormatEntitlements , defaultLicenseUnavailableMsg } from "./index" ;
89
910describe ( "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} ) ;
0 commit comments