This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathcombinedHelpers.unit.spec.jsx
More file actions
947 lines (827 loc) · 30.4 KB
/
combinedHelpers.unit.spec.jsx
File metadata and controls
947 lines (827 loc) · 30.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
import { expect } from 'chai';
import { addMonths, subMonths, addDays } from 'date-fns';
import { getMedicalCenterNameByID } from 'platform/utilities/medical-centers/medical-centers';
import FEATURE_FLAG_NAMES from 'platform/utilities/feature-toggles/featureFlagNames';
import { uniqBy } from 'lodash';
import { render } from '@testing-library/react';
import { createStore, combineReducers } from 'redux';
import React from 'react';
import { Provider } from 'react-redux';
import { BrowserRouter as Router } from 'react-router-dom';
import MockDate from 'mockdate';
import {
APP_TYPES,
ALERT_TYPES,
API_RESPONSES,
selectLoadingFeatureFlags,
currency,
formatTableData,
titleCase,
verifyCurrentBalance,
transform,
setPageFocus,
formatDate,
calcDueDate,
sortStatementsByDate,
combinedPortalAccess,
debtLettersShowLettersVBMS,
showPaymentHistory,
cdpAccessToggle,
showVHAPaymentHistory,
} from '../../utils/helpers';
import OverviewPage from '../../containers/OverviewPage';
describe('Helper Functions', () => {
describe('APP_TYPES', () => {
it('should have correct values', () => {
expect(APP_TYPES.DEBT).to.equal('DEBT');
expect(APP_TYPES.COPAY).to.equal('COPAY');
});
it('should be frozen', () => {
expect(Object.isFrozen(APP_TYPES)).to.be.true;
});
it('should have exactly 2 properties', () => {
expect(Object.keys(APP_TYPES).length).to.equal(2);
});
});
describe('ALERT_TYPES', () => {
it('should have correct values', () => {
expect(ALERT_TYPES.ALL_ERROR).to.equal('ALL_ERROR');
expect(ALERT_TYPES.ALL_ZERO).to.equal('ALL_ZERO');
expect(ALERT_TYPES.ERROR).to.equal('ERROR');
expect(ALERT_TYPES.ZERO).to.equal('ZERO');
});
it('should be frozen', () => {
expect(Object.isFrozen(ALERT_TYPES)).to.be.true;
});
it('should have exactly 4 properties', () => {
expect(Object.keys(ALERT_TYPES).length).to.equal(4);
});
});
describe('API_RESPONSES', () => {
it('should have correct values', () => {
expect(API_RESPONSES.ERROR).to.equal(-1);
});
it('should be frozen', () => {
expect(Object.isFrozen(API_RESPONSES)).to.be.true;
});
});
describe('selectLoadingFeatureFlags', () => {
it('should return loading state of feature flags', () => {
const mockState = { featureToggles: { loading: true } };
expect(selectLoadingFeatureFlags(mockState)).to.be.true;
});
});
describe('currency', () => {
it('should format currency correctly', () => {
expect(currency(1234.56)).to.equal('$1,234.56');
expect(currency('1000')).to.equal('$1,000.00');
});
});
describe('formatTableData', () => {
it('should format table data correctly', () => {
const input = [{ date: '2023-01-15', desc: 'Test', amount: 100 }];
const output = formatTableData(input);
expect(output[0].date).to.equal('2023-01-15');
expect(output[0].desc.type).to.equal('strong');
expect(output[0].desc.props.children).to.equal('Test');
expect(output[0].amount).to.equal('$100.00');
});
it('should handle multiple rows', () => {
const input = [
{ date: '2023-01-15', desc: 'First', amount: 100 },
{ date: '2023-02-15', desc: 'Second', amount: 200.5 },
];
const output = formatTableData(input);
expect(output.length).to.equal(2);
expect(output[1].desc.props.children).to.equal('Second');
expect(output[1].amount).to.equal('$200.50');
});
it('should handle string amounts', () => {
const input = [{ date: '2023-01-15', desc: 'Test', amount: '150.75' }];
const output = formatTableData(input);
expect(output[0].amount).to.equal('$150.75');
});
});
describe('titleCase', () => {
it('should convert string to title case', () => {
expect(titleCase('hello world')).to.equal('Hello World');
});
});
describe('formatDate - expected output example: October 13, 2018', () => {
const expectedResult = 'October 13, 2018';
it("should return correctly formatted date from string that uses '/' delimiter", () => {
const simpleDate = '10/13/2018';
expect(formatDate(simpleDate)).to.equal(expectedResult);
});
it("should return correctly formatted date from string that has '-' delimiter", () => {
const simpleDate = '10-13-2018';
expect(formatDate(simpleDate)).to.equal(expectedResult);
});
it('should return correctly formatted date from string from new date object', () => {
const simpleDate = new Date('10/13/2018');
expect(formatDate(simpleDate)).to.equal(expectedResult);
});
});
describe('verifyCurrentBalance', () => {
beforeEach(() => {
MockDate.set('2025-01-15');
});
afterEach(() => {
MockDate.reset();
});
it('should return true if current date is on or before due date', () => {
const futureDate = addMonths(new Date(), 1);
expect(verifyCurrentBalance(futureDate)).to.be.true;
});
it('should return false if current date is after due date', () => {
const pastDate = subMonths(new Date(), 2);
expect(verifyCurrentBalance(pastDate)).to.be.false;
});
it('should return true for exactly 30 days from now', () => {
const exactDueDate = addMonths(new Date(), 1);
expect(verifyCurrentBalance(exactDueDate)).to.be.true;
});
it('should handle date strings', () => {
const futureDate = addMonths(new Date(), 2).toISOString();
expect(verifyCurrentBalance(futureDate)).to.be.true;
});
});
describe('transform', () => {
it('should transform data correctly', () => {
const input = [
{
station: {
facilitYNum: '123',
city: 'NEW YORK',
},
},
];
const output = transform(input);
expect(output[0].station.facilityName).to.equal(
getMedicalCenterNameByID('123'),
);
expect(output[0].station.city).to.equal('New York');
});
it('should handle mixed case cities', () => {
const input = [
{
station: {
facilitYNum: '456',
city: 'los ANGELES',
},
},
];
const output = transform(input);
expect(output[0].station.city).to.equal('Los Angeles');
});
it('should handle lowercase cities', () => {
const input = [
{
station: {
facilitYNum: '789',
city: 'chicago',
},
},
];
const output = transform(input);
expect(output[0].station.city).to.equal('Chicago');
});
it('should preserve other statement properties', () => {
const input = [
{
id: 'test-id',
date: '2023-01-15',
amount: 100,
station: {
facilitYNum: '123',
city: 'MIAMI',
state: 'FL',
},
},
];
const output = transform(input);
expect(output[0].id).to.equal('test-id');
expect(output[0].date).to.equal('2023-01-15');
expect(output[0].amount).to.equal(100);
expect(output[0].station.state).to.equal('FL');
});
});
describe('setPageFocus', () => {
it('should set focus on the correct element', () => {
document.body.innerHTML = '<div id="main"><h1></h1></div>';
setPageFocus('#main h1');
expect(
document.querySelector('#main h1').getAttribute('tabIndex'),
).to.equal('-1');
});
it('should set focus on main h1 if selector not found', () => {
document.body.innerHTML = '<div id="main"><h1></h1></div>';
setPageFocus('#non-existent');
expect(
document.querySelector('#main h1').getAttribute('tabIndex'),
).to.equal('-1');
});
});
describe('calcDueDate', () => {
it('should calculate due date 30 days from given date', () => {
const startDate = '2023-01-01';
const result = calcDueDate(startDate, 30);
const expectedDate = formatDate(addDays(new Date(startDate), 30));
expect(result).to.equal(expectedDate);
});
it('should handle different number of days', () => {
const startDate = '2023-01-01';
const result = calcDueDate(startDate, 15);
const expectedDate = formatDate(addDays(new Date(startDate), 15));
expect(result).to.equal(expectedDate);
});
it('should handle month boundaries', () => {
const startDate = '2023-01-31';
const result = calcDueDate(startDate, 30);
const expectedDate = formatDate(addDays(new Date(startDate), 30));
expect(result).to.equal(expectedDate);
});
it('should handle zero days', () => {
const startDate = '2023-01-15';
const result = calcDueDate(startDate, 0);
const expectedDate = formatDate(addDays(new Date(startDate), 0));
expect(result).to.equal(expectedDate);
});
it('should handle negative days', () => {
const startDate = '2023-01-15';
const result = calcDueDate(startDate, -5);
const expectedDate = formatDate(addDays(new Date(startDate), -5));
expect(result).to.equal(expectedDate);
});
it('should handle large number of days', () => {
const startDate = '2023-01-01';
const result = calcDueDate(startDate, 365);
const expectedDate = formatDate(addDays(new Date(startDate), 365));
expect(result).to.equal(expectedDate);
});
it('should handle date objects', () => {
const startDate = new Date('2023-06-15');
const result = calcDueDate(startDate, 10);
const expectedDate = formatDate(addDays(startDate, 10));
expect(result).to.equal(expectedDate);
});
});
describe('sortStatementsByDate', () => {
it('should sort statements by date in descending order', () => {
const statements = [
{ pSStatementDateOutput: '2023-01-01' },
{ pSStatementDateOutput: '2023-03-01' },
{ pSStatementDateOutput: '2023-02-01' },
];
const sorted = sortStatementsByDate(statements);
expect(sorted[0].pSStatementDateOutput).to.equal('2023-03-01');
expect(sorted[1].pSStatementDateOutput).to.equal('2023-02-01');
expect(sorted[2].pSStatementDateOutput).to.equal('2023-01-01');
});
it('should handle empty array', () => {
const statements = [];
const sorted = sortStatementsByDate(statements);
expect(sorted).to.deep.equal([]);
});
it('should handle single statement', () => {
const statements = [{ pSStatementDateOutput: '2023-01-01' }];
const sorted = sortStatementsByDate(statements);
expect(sorted.length).to.equal(1);
expect(sorted[0].pSStatementDateOutput).to.equal('2023-01-01');
});
it('should handle identical dates', () => {
const statements = [
{ pSStatementDateOutput: '2023-01-01', id: 1 },
{ pSStatementDateOutput: '2023-01-01', id: 2 },
{ pSStatementDateOutput: '2023-01-01', id: 3 },
];
const sorted = sortStatementsByDate(statements);
expect(sorted.length).to.equal(3);
expect(sorted[0].pSStatementDateOutput).to.equal('2023-01-01');
});
it('should preserve other properties', () => {
const statements = [
{ pSStatementDateOutput: '2023-01-01', amount: 100, type: 'debt' },
{ pSStatementDateOutput: '2023-02-01', amount: 200, type: 'copay' },
];
const sorted = sortStatementsByDate(statements);
expect(sorted[0].amount).to.equal(200);
expect(sorted[0].type).to.equal('copay');
expect(sorted[1].amount).to.equal(100);
expect(sorted[1].type).to.equal('debt');
});
it('should handle date strings with time', () => {
const statements = [
{ pSStatementDateOutput: '2023-01-01T10:00:00' },
{ pSStatementDateOutput: '2023-01-01T15:00:00' },
{ pSStatementDateOutput: '2023-01-01T08:00:00' },
];
const sorted = sortStatementsByDate(statements);
expect(sorted[0].pSStatementDateOutput).to.equal('2023-01-01T15:00:00');
expect(sorted[1].pSStatementDateOutput).to.equal('2023-01-01T10:00:00');
expect(sorted[2].pSStatementDateOutput).to.equal('2023-01-01T08:00:00');
});
});
describe('formatDate edge cases', () => {
it('should return empty string for invalid date', () => {
expect(formatDate('invalid-date')).to.equal('');
expect(formatDate(null)).to.equal('');
expect(formatDate(undefined)).to.equal('');
});
it('should handle date objects', () => {
const date = new Date('2023-05-15');
// The actual formatted date should match what formatDate returns
const result = formatDate(date);
// We're testing that it handles date objects, not the specific output
expect(result).to.be.a('string');
expect(result).to.include('May');
expect(result).to.include('2023');
});
it('should handle ISO date strings', () => {
expect(formatDate('2023-05-15')).to.equal('May 15, 2023');
});
it('should handle VBS compact pSStatementDate (MMddyyyy)', () => {
expect(formatDate('12112025')).to.equal('December 11, 2025');
});
});
describe('currency edge cases', () => {
it('should handle zero', () => {
expect(currency(0)).to.equal('$0.00');
});
it('should handle negative numbers', () => {
expect(currency(-100)).to.equal('-$100.00');
});
it('should handle very large numbers', () => {
expect(currency(1000000)).to.equal('$1,000,000.00');
});
it('should handle string with decimals', () => {
expect(currency('123.456')).to.equal('$123.46');
});
});
describe('titleCase edge cases', () => {
it('should handle empty string', () => {
expect(titleCase('')).to.equal('');
});
it('should handle single word', () => {
expect(titleCase('hello')).to.equal('Hello');
});
it('should handle all caps', () => {
expect(titleCase('HELLO WORLD')).to.equal('Hello World');
});
it('should handle mixed case', () => {
expect(titleCase('hELLo WoRLd')).to.equal('Hello World');
});
it('should handle strings with numbers', () => {
expect(titleCase('hello 123 world')).to.equal('Hello 123 World');
});
});
describe('formatTableData edge cases', () => {
it('should handle empty array', () => {
const result = formatTableData([]);
expect(result).to.deep.equal([]);
});
it('should handle negative amounts', () => {
const input = [{ date: '2023-01-15', desc: 'Credit', amount: -50 }];
const output = formatTableData(input);
expect(output[0].amount).to.equal('-$50.00');
});
it('should handle zero amounts', () => {
const input = [{ date: '2023-01-15', desc: 'Zero', amount: 0 }];
const output = formatTableData(input);
expect(output[0].amount).to.equal('$0.00');
});
});
describe('transform edge cases', () => {
it('should handle empty array', () => {
const output = transform([]);
expect(output).to.deep.equal([]);
});
it('should handle multiple items', () => {
const input = [
{
station: {
facilitYNum: '123',
city: 'NEW YORK',
},
},
{
station: {
facilitYNum: '456',
city: 'los angeles',
},
},
];
const output = transform(input);
expect(output.length).to.equal(2);
expect(output[0].station.city).to.equal('New York');
expect(output[1].station.city).to.equal('Los Angeles');
});
it('should preserve other properties', () => {
const input = [
{
id: 1,
name: 'Test',
station: {
facilitYNum: '123',
city: 'chicago',
state: 'IL',
},
},
];
const output = transform(input);
expect(output[0].id).to.equal(1);
expect(output[0].name).to.equal('Test');
expect(output[0].station.state).to.equal('IL');
});
});
describe('selectLoadingFeatureFlags edge cases', () => {
it('should handle undefined state', () => {
expect(selectLoadingFeatureFlags(undefined)).to.be.undefined;
});
it('should handle null state', () => {
expect(selectLoadingFeatureFlags(null)).to.be.undefined;
});
it('should handle empty state object', () => {
expect(selectLoadingFeatureFlags({})).to.be.undefined;
});
it('should handle false loading state', () => {
const mockState = { featureToggles: { loading: false } };
expect(selectLoadingFeatureFlags(mockState)).to.be.false;
});
});
describe('Feature Toggle Selectors', () => {
it('combinedPortalAccess should return feature flag value true', () => {
const mockState = {
featureToggles: {
[FEATURE_FLAG_NAMES.combinedDebtPortalAccess]: true,
},
};
const result = combinedPortalAccess(mockState);
expect(result).to.be.true;
});
it('combinedPortalAccess should return feature flag value false', () => {
const mockState = {
featureToggles: {
[FEATURE_FLAG_NAMES.combinedDebtPortalAccess]: false,
},
};
const result = combinedPortalAccess(mockState);
expect(result).to.be.false;
});
it('debtLettersShowLettersVBMS should return feature flag value true', () => {
const mockState = {
featureToggles: {
[FEATURE_FLAG_NAMES.debtLettersShowLettersVBMS]: true,
},
};
const result = debtLettersShowLettersVBMS(mockState);
expect(result).to.be.true;
});
it('debtLettersShowLettersVBMS should return feature flag value false', () => {
const mockState = {
featureToggles: {
[FEATURE_FLAG_NAMES.debtLettersShowLettersVBMS]: false,
},
};
const result = debtLettersShowLettersVBMS(mockState);
expect(result).to.be.false;
});
it('showPaymentHistory should return feature flag value true', () => {
const mockState = {
featureToggles: {
[FEATURE_FLAG_NAMES.CdpPaymentHistoryVba]: true,
},
};
const result = showPaymentHistory(mockState);
expect(result).to.be.true;
});
it('showPaymentHistory should return feature flag value false', () => {
const mockState = {
featureToggles: {
[FEATURE_FLAG_NAMES.CdpPaymentHistoryVba]: false,
},
};
const result = showPaymentHistory(mockState);
expect(result).to.be.false;
});
it('cdpAccessToggle should return feature flag value true', () => {
const mockState = {
featureToggles: {
[FEATURE_FLAG_NAMES.combinedDebtPortalAccess]: true,
},
};
const result = cdpAccessToggle(mockState);
expect(result).to.be.true;
});
it('cdpAccessToggle should return feature flag value false', () => {
const mockState = {
featureToggles: {
[FEATURE_FLAG_NAMES.combinedDebtPortalAccess]: false,
},
};
const result = cdpAccessToggle(mockState);
expect(result).to.be.false;
});
});
describe('OverviewPage sortedStatements and statementsByUniqueFacility', () => {
const renderWithStore = (component, initialState) => {
const store = createStore(
combineReducers({
combinedPortal: (state = initialState.combinedPortal || {}) => state,
user: (state = initialState.user || {}) => state,
featureToggles: (
state = initialState.featureToggles || { loading: false },
) => state,
}),
);
return render(
<Provider store={store}>
<Router>{component}</Router>
</Provider>,
);
};
it('should pass mcp.statements.data to Balances when showVHAPaymentHistory is true', () => {
const mockState = {
user: {},
combinedPortal: {
debtLetters: {
isProfileUpdating: false,
isPending: false,
isPendingVBMS: false,
isError: false,
isVBMSError: false,
debts: [],
selectedDebt: {},
debtLinks: [],
errors: [],
hasDependentDebts: false,
},
mcp: {
pending: false,
error: null,
shouldUseLighthouseCopays: true,
statements: {
data: [
{
id: '4-1abZUKu7xIvIw6',
type: 'medicalCopays',
attributes: {
url: null,
facility: 'TEST VAMC',
facilityId: '4-O3d8XK44ejMS',
city: 'LYONS',
externalId: '4-1abZUKu7xIvIw6',
latestBillingRef: '4-6c9ZE23XQm5VawK',
currentBalance: 150.25,
previousBalance: 65.71,
previousUnpaidBalance: 0,
lastUpdatedAt: '2025-08-29T12:00:00Z',
},
},
],
meta: {
total: 10,
page: 1,
perPage: 3,
copaySummary: {
totalCurrentBalance: 150.25,
copayBillCount: 1,
lastUpdatedOn: '2025-08-29T12:00:00Z',
},
},
links: {
self:
'http://127.0.0.1:3000/services/health-care-costs-coverage/v0/r4/Invoice?_count=3&patient=10000003&page=1',
first:
'http://127.0.0.1:3000/services/health-care-costs-coverage/v0/r4/Invoice?_count=3&patient=10000003&page=1',
next:
'http://127.0.0.1:3000/services/health-care-costs-coverage/v0/r4/Invoice?_count=3&patient=10000003&page=2',
last:
'http://127.0.0.1:3000/services/health-care-costs-coverage/v0/r4/Invoice?_count=3&patient=10000003&page=4',
},
},
},
},
featureToggles: {
[FEATURE_FLAG_NAMES.showVHAPaymentHistory]: true,
loading: false,
},
};
const { container } = renderWithStore(<OverviewPage />, mockState);
expect(container).to.exist;
// Verify component rendered - OverviewPage should pass the data to Balances
const balanceCards = container.querySelectorAll('va-card');
expect(balanceCards.length).to.be.greaterThan(0);
expect(balanceCards[0].textContent).to.include('$150.25');
});
it('should pass sorted statements to Balances when showVHAPaymentHistory is false', () => {
const mockState = {
user: {},
combinedPortal: {
debtLetters: {
debts: [],
errors: [],
isPending: false,
isProfileUpdating: false,
},
mcp: {
pending: false,
error: null,
statements: {
data: [
{
id: '1',
pSStatementDateOutput: '2023-01-01',
pSFacilityNum: '789',
pHAmtDue: 100,
},
{
id: '2',
pSStatementDateOutput: '2023-03-01',
pSFacilityNum: '456',
pHAmtDue: 200,
},
],
shouldUseLighthouseCopays: false,
},
},
},
featureToggles: {
[FEATURE_FLAG_NAMES.showVHAPaymentHistory]: false,
loading: false,
},
};
const { container } = renderWithStore(<OverviewPage />, mockState);
expect(container).to.exist;
// Verify component rendered - OverviewPage should pass sorted statements to Balances
const balanceCards = container.querySelectorAll('va-card');
expect(balanceCards.length).to.be.greaterThan(0);
expect(balanceCards[0].textContent).to.include('$300');
});
});
it('showVHAPaymentHistory should return feature flag value true', () => {
const mockState = {
featureToggles: {
[FEATURE_FLAG_NAMES.showVHAPaymentHistory]: true,
},
};
const result = showVHAPaymentHistory(mockState);
expect(result).to.be.true;
});
it('showVHAPaymentHistory should return feature flag value false', () => {
const mockState = {
featureToggles: {
[FEATURE_FLAG_NAMES.showVHAPaymentHistory]: false,
},
};
const result = showVHAPaymentHistory(mockState);
expect(result).to.be.false;
});
describe('sortedStatements logic', () => {
it('should use mcp.statements.data when shouldUseLighthouseCopays is true', () => {
const shouldUseLighthouseCopays = true;
const statements = [
{ pSStatementDateOutput: '2023-01-01' },
{ pSStatementDateOutput: '2023-03-01' },
];
const mcp = {
statements: {
data: [
{ id: '1', attributes: { lastUpdatedAt: '2023-05-01' } },
{ id: '2', attributes: { lastUpdatedAt: '2023-06-01' } },
],
},
};
const sortedStatements = shouldUseLighthouseCopays
? mcp.statements.data ?? []
: sortStatementsByDate(statements || []);
expect(sortedStatements).to.deep.equal(mcp.statements.data);
expect(sortedStatements.length).to.equal(2);
expect(sortedStatements[0].id).to.equal('1');
});
it('should use sortStatementsByDate when shouldUseLighthouseCopays is false', () => {
const shouldUseLighthouseCopays = false;
const statements = [
{ pSStatementDateOutput: '2023-01-01' },
{ pSStatementDateOutput: '2023-03-01' },
{ pSStatementDateOutput: '2023-02-01' },
];
const mcp = {
statements: {
data: [{ id: '1' }, { id: '2' }],
},
};
const sortedStatements = shouldUseLighthouseCopays
? mcp.statements.data ?? []
: sortStatementsByDate(statements || []);
expect(sortedStatements.length).to.equal(3);
expect(sortedStatements[0].pSStatementDateOutput).to.equal('2023-03-01');
expect(sortedStatements[2].pSStatementDateOutput).to.equal('2023-01-01');
});
it('should handle null statements when shouldUseLighthouseCopays is false', () => {
const shouldUseLighthouseCopays = false;
const statements = null;
const mcp = {
statements: {
data: [],
},
};
const sortedStatements = shouldUseLighthouseCopays
? mcp.statements.data ?? []
: sortStatementsByDate(statements || []);
expect(sortedStatements).to.deep.equal([]);
});
it('should use empty array fallback when mcp.statements.data is null and shouldUseLighthouseCopays is true', () => {
const shouldUseLighthouseCopays = true;
const statements = [{ pSStatementDateOutput: '2023-01-01' }];
const mcp = {
statements: {
data: null,
},
};
const sortedStatements = shouldUseLighthouseCopays
? mcp.statements.data ?? []
: sortStatementsByDate(statements || []);
expect(sortedStatements).to.deep.equal([]);
});
});
describe('statementsByUniqueFacility logic', () => {
it('should use attributes.facilityId with uniqBy when shouldUseLighthouseCopays is true', () => {
const shouldUseLighthouseCopays = true;
const mcpStatements = [
{ id: '1', attributes: { facilityId: 'FAC123' }, name: 'First' },
{ id: '2', attributes: { facilityId: 'FAC123' }, name: 'Duplicate' },
{ id: '3', attributes: { facilityId: 'FAC456' }, name: 'Second' },
];
const sortedStatements = [
{ id: '1', pSFacilityNum: '789' },
{ id: '2', pSFacilityNum: '789' },
];
const statementsByUniqueFacility = shouldUseLighthouseCopays
? uniqBy(mcpStatements, 'attributes.facilityId')
: uniqBy(sortedStatements, 'pSFacilityNum');
expect(statementsByUniqueFacility.length).to.equal(2);
expect(statementsByUniqueFacility[0].attributes.facilityId).to.equal(
'FAC123',
);
expect(statementsByUniqueFacility[1].attributes.facilityId).to.equal(
'FAC456',
);
expect(statementsByUniqueFacility[0].name).to.equal('First');
});
it('should use pSFacilityNum with uniqBy when shouldUseLighthouseCopays is false', () => {
const shouldUseLighthouseCopays = false;
const mcpStatements = [
{ id: '1', facilityId: 'FAC123' },
{ id: '2', facilityId: 'FAC456' },
];
const sortedStatements = [
{ id: '1', pSFacilityNum: '789', city: 'New York' },
{ id: '2', pSFacilityNum: '789', city: 'New York' },
{ id: '3', pSFacilityNum: '456', city: 'Boston' },
];
const statementsByUniqueFacility = shouldUseLighthouseCopays
? uniqBy(mcpStatements, 'attributes.facilityId')
: uniqBy(sortedStatements, 'pSFacilityNum');
expect(statementsByUniqueFacility.length).to.equal(2);
expect(statementsByUniqueFacility[0].pSFacilityNum).to.equal('789');
expect(statementsByUniqueFacility[1].pSFacilityNum).to.equal('456');
expect(statementsByUniqueFacility[0].city).to.equal('New York');
});
it('should handle empty arrays', () => {
const shouldUseLighthouseCopays = true;
const mcpStatements = [];
const sortedStatements = [];
const statementsByUniqueFacility = shouldUseLighthouseCopays
? uniqBy(mcpStatements, 'attributes.facilityId')
: uniqBy(sortedStatements, 'pSFacilityNum');
expect(statementsByUniqueFacility).to.deep.equal([]);
});
it('should handle all unique facilities when shouldUseLighthouseCopays is true', () => {
const shouldUseLighthouseCopays = true;
const mcpStatements = [
{ id: '1', attributes: { facilityId: 'FAC111' } },
{ id: '2', attributes: { facilityId: 'FAC222' } },
{ id: '3', attributes: { facilityId: 'FAC333' } },
];
const sortedStatements = [];
const statementsByUniqueFacility = shouldUseLighthouseCopays
? uniqBy(mcpStatements, 'attributes.facilityId')
: uniqBy(sortedStatements, 'pSFacilityNum');
expect(statementsByUniqueFacility.length).to.equal(3);
});
it('should handle all unique facilities when shouldUseLighthouseCopays is false', () => {
const shouldUseLighthouseCopays = false;
const mcpStatements = [];
const sortedStatements = [
{ id: '1', pSFacilityNum: '111' },
{ id: '2', pSFacilityNum: '222' },
{ id: '3', pSFacilityNum: '333' },
];
const statementsByUniqueFacility = shouldUseLighthouseCopays
? uniqBy(mcpStatements, 'attributes.facilityId')
: uniqBy(sortedStatements, 'pSFacilityNum');
expect(statementsByUniqueFacility.length).to.equal(3);
});
});
});