@@ -98,3 +98,52 @@ describe('buildNRMetaNode', () => {
9898 expect ( metadata . correctedTimestamp ) . toEqual ( expected )
9999 } )
100100} )
101+
102+ describe ( 'customMasker' , ( ) => {
103+ test ( 'should return input text as masked when the element is a non-password field and not decorated with unmask option' , async ( ) => {
104+ const text = 'foobar'
105+ const element = { type : 'string' }
106+
107+ expect ( sessionReplaySharedUtils . customMasker ( text , element ) ) . toEqual ( '******' )
108+ } )
109+
110+ // NR-739491 - fixes issue where whitespace was masked, pushing layout/styling out-of-place
111+ test ( 'should return input text as-is when the input text is whitespace and the element is a non-password field and not decorated with unmask option' , async ( ) => {
112+ const text = ' \n '
113+ const element = { type : 'string' }
114+
115+ expect ( sessionReplaySharedUtils . customMasker ( text , element ) ) . toEqual ( ' \n ' )
116+ } )
117+
118+ test ( 'should return input text as masked when the element is a password field' , async ( ) => {
119+ const text = 'foobar'
120+ const element = { type : 'password' }
121+
122+ expect ( sessionReplaySharedUtils . customMasker ( text , element ) ) . toEqual ( '******' )
123+ } )
124+
125+ test ( 'should return input text as masked when the input text is whitespace and the element is a password field' , async ( ) => {
126+ const text = ' \n '
127+ const element = { type : 'password' }
128+
129+ expect ( sessionReplaySharedUtils . customMasker ( text , element ) ) . toEqual ( '*******' )
130+ } )
131+
132+ test ( 'should return input text as-is when the element is a non-password field decorated with unmask option' , async ( ) => {
133+ const text = 'foobar'
134+ const element = { type : 'string' , dataset : { nrUnmask : true } }
135+ expect ( sessionReplaySharedUtils . customMasker ( text , element ) ) . toEqual ( 'foobar' )
136+
137+ const element2 = { type : 'string' , classList : { contains : ( ) => true } }
138+ expect ( sessionReplaySharedUtils . customMasker ( text , element2 ) ) . toEqual ( 'foobar' )
139+ } )
140+
141+ test ( 'should return input text as-is when input text is whitespace and the element is a non-password field decorated with unmask option' , async ( ) => {
142+ const text = ' \n '
143+ const element = { type : 'string' , dataset : { nrUnmask : true } }
144+ expect ( sessionReplaySharedUtils . customMasker ( text , element ) ) . toEqual ( ' \n ' )
145+
146+ const element2 = { type : 'string' , classList : { contains : ( ) => true } }
147+ expect ( sessionReplaySharedUtils . customMasker ( text , element2 ) ) . toEqual ( ' \n ' )
148+ } )
149+ } )
0 commit comments