dce-reactkit 3.5.2 → 3.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dce-reactkit",
3
- "version": "3.5.2",
3
+ "version": "3.5.3",
4
4
  "description": "Shared components for Harvard DCE apps",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -99,4 +99,49 @@ describe('compareArraysByProp', () => {
99
99
  const result = compareArraysByProp(a, b, 'id');
100
100
  expect(result).toEqual(false);
101
101
  });
102
+
103
+ it('should return true for two arrays with the same objects with multiple properties and multiple props', () => {
104
+ const a = [
105
+ { id: 1, name: 'Alice', age: 25 },
106
+ { id: 2, name: 'Bob', age: 30 },
107
+ { id: 3, name: 'Charlie', age: 35 },
108
+ ];
109
+ const b = [
110
+ { id: 1, name: 'Alice', age: 25 },
111
+ { id: 2, name: 'Bob', age: 30 },
112
+ { id: 3, name: 'Charlie', age: 35 },
113
+ ];
114
+ const result = compareArraysByProp(a, b, ['id', 'name']);
115
+ expect(result).toEqual(true);
116
+ });
117
+
118
+ it('should return true for two arrays with the same objects with multiple properties and multiple props in a different order', () => {
119
+ const a = [
120
+ { id: 1, name: 'Alice', age: 25 },
121
+ { id: 2, name: 'Bob', age: 30 },
122
+ { id: 3, name: 'Charlie', age: 35 },
123
+ ];
124
+ const b = [
125
+ { id: 3, name: 'Charlie', age: 35 },
126
+ { id: 1, name: 'Alice', age: 25 },
127
+ { id: 2, name: 'Bob', age: 30 },
128
+ ];
129
+ const result = compareArraysByProp(a, b, ['id', 'name']);
130
+ expect(result).toEqual(true);
131
+ });
132
+
133
+ it('should return false for two arrays with different objects with multiple properties and multiple props', () => {
134
+ const a = [
135
+ { id: 1, name: 'Alice', age: 25 },
136
+ { id: 2, name: 'Bob', age: 30 },
137
+ { id: 3, name: 'Charlie', age: 35 },
138
+ ];
139
+ const b = [
140
+ { id: 1, name: 'Bob', age: 40 },
141
+ { id: 2, name: 'Alice', age: 45 },
142
+ { id: 3, name: 'Charlie', age: 50 },
143
+ ];
144
+ const result = compareArraysByProp(a, b, ['id', 'name']);
145
+ expect(result).toEqual(false);
146
+ });
102
147
  });
@@ -1,6 +1,3 @@
1
- // Import shared helpers
2
- import extractProp from './extractProp';
3
-
4
1
  /**
5
2
  * Compare two arrays of objects by only comparing the values in a specific
6
3
  * property (e.g. compare user arrays by comparing their user.id values)
@@ -34,8 +31,8 @@ const compareArraysByProp = (
34
31
  const matchingIndex = bCloned.findIndex((bItem) => {
35
32
  // Compare based on all props
36
33
  return props.every((propToCompareBy) => {
37
- const aVal = extractProp(a[i], propToCompareBy);
38
- const bVal = extractProp(bItem, propToCompareBy);
34
+ const aVal = (a[i] ?? {})[propToCompareBy];
35
+ const bVal = (bItem ?? {})[propToCompareBy];
39
36
  return aVal === bVal;
40
37
  });
41
38
  });
@@ -38,7 +38,7 @@ describe('getTimeInfoInET', () => {
38
38
  const expectedHour = 19;
39
39
  const expectedHour12 = 7;
40
40
  const expectedMinute = 0;
41
- const expectedIsPM = false;
41
+ const expectedIsPM = true;
42
42
  expect(result.timestamp).toEqual(expectedTimestamp);
43
43
  expect(result.year).toEqual(expectedYear);
44
44
  expect(result.month).toEqual(expectedMonth);
@@ -59,7 +59,7 @@ describe('getTimeInfoInET', () => {
59
59
  const expectedHour = 19;
60
60
  const expectedHour12 = 7;
61
61
  const expectedMinute = 0;
62
- const expectedIsPM = false;
62
+ const expectedIsPM = true;
63
63
  expect(result.timestamp).toEqual(expectedTimestamp);
64
64
  expect(result.year).toEqual(expectedYear);
65
65
  expect(result.month).toEqual(expectedMonth);
@@ -167,8 +167,6 @@ test(
167
167
  errorMessage: `${INVALID_STRING_ERRORS.MESSAGE_INTRO}${genCommaList(triple.error)}.`,
168
168
  };
169
169
 
170
- console.log(invalidResponse.errorMessage);
171
-
172
170
  expect(validateString(triple.input, triple.reqs)).toStrictEqual(invalidResponse);
173
171
  });
174
172
  },