@@ -5,10 +5,12 @@ import EntitlementSelector from "./index";
5
5
import App from "../App" ;
6
6
import { render , fireEvent } from "../../test/utils/react-test" ;
7
7
import userEvent from "@testing-library/user-event" ;
8
+ import { filterAndFormatEntitlements , defaultLicenseUnavailableMsg } from "./index" ;
8
9
9
10
describe ( "EntitlementSelector Component" , ( ) => {
10
11
let initialState ;
11
12
13
+
12
14
beforeEach ( ( ) => {
13
15
initialState = {
14
16
triggerPosition : { x : 539 , y : 0 } ,
@@ -47,9 +49,13 @@ describe("EntitlementSelector Component", () => {
47
49
} ) ;
48
50
49
51
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" } ,
53
59
] ;
54
60
55
61
function setup ( jsx ) {
@@ -67,18 +73,18 @@ describe("EntitlementSelector Component", () => {
67
73
const { getByRole } = render ( < EntitlementSelector options = { options } /> ) ;
68
74
69
75
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 ) ;
73
79
} ) ;
74
80
75
81
it ( "should select correct value on change" , async ( ) => {
76
82
const { user, getByRole } = setup (
77
83
< EntitlementSelector options = { options } />
78
84
) ;
79
85
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 " ) ;
82
88
} ) ;
83
89
84
90
it ( "should fire onClick Event for submit button without crashing" , ( ) => {
@@ -101,4 +107,18 @@ describe("EntitlementSelector Component", () => {
101
107
container . querySelector ( "#entitlement-selection" )
102
108
) . not . toBeInTheDocument ( ) ;
103
109
} ) ;
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
+
104
124
} ) ;
0 commit comments