@memori.ai/memori-react 2.6.3 → 2.6.4
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/CHANGELOG.md +12 -0
- package/dist/components/Header/Header.css +2 -2
- package/dist/components/PoweredBy/PoweredBy.css +1 -1
- package/dist/components/layouts/chat.css +2 -3
- package/dist/components/ui/Select.css +1 -1
- package/dist/helpers/error.test.d.ts +1 -0
- package/dist/helpers/error.test.js +26 -0
- package/dist/helpers/error.test.js.map +1 -0
- package/dist/helpers/media.js +3 -2
- package/dist/helpers/media.js.map +1 -1
- package/dist/helpers/media.test.d.ts +1 -0
- package/dist/helpers/media.test.js +87 -0
- package/dist/helpers/media.test.js.map +1 -0
- package/dist/helpers/statistics.test.d.ts +3 -0
- package/dist/helpers/statistics.test.js +200 -0
- package/dist/helpers/statistics.test.js.map +1 -0
- package/dist/helpers/utils.test.d.ts +1 -0
- package/dist/helpers/utils.test.js +30 -0
- package/dist/helpers/utils.test.js.map +1 -0
- package/dist/styles.css +1 -1
- package/esm/components/Header/Header.css +2 -2
- package/esm/components/PoweredBy/PoweredBy.css +1 -1
- package/esm/components/layouts/chat.css +2 -3
- package/esm/components/ui/Select.css +1 -1
- package/esm/helpers/error.test.d.ts +1 -0
- package/esm/helpers/error.test.js +24 -0
- package/esm/helpers/error.test.js.map +1 -0
- package/esm/helpers/media.js +3 -2
- package/esm/helpers/media.js.map +1 -1
- package/esm/helpers/media.test.d.ts +1 -0
- package/esm/helpers/media.test.js +85 -0
- package/esm/helpers/media.test.js.map +1 -0
- package/esm/helpers/statistics.test.d.ts +3 -0
- package/esm/helpers/statistics.test.js +197 -0
- package/esm/helpers/statistics.test.js.map +1 -0
- package/esm/helpers/utils.test.d.ts +1 -0
- package/esm/helpers/utils.test.js +28 -0
- package/esm/helpers/utils.test.js.map +1 -0
- package/esm/styles.css +1 -1
- package/package.json +1 -1
- package/src/components/Header/Header.css +2 -2
- package/src/components/PoweredBy/PoweredBy.css +1 -1
- package/src/components/layouts/chat.css +2 -3
- package/src/components/ui/Select.css +1 -1
- package/src/helpers/error.test.ts +29 -0
- package/src/helpers/media.test.ts +133 -0
- package/src/helpers/media.ts +5 -2
- package/src/helpers/statistics.test.ts +213 -0
- package/src/helpers/utils.test.ts +31 -0
- package/src/styles.css +1 -1
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { EventLog, Stats } from '@memori.ai/memori-api-client/dist/types';
|
|
2
|
+
import {
|
|
3
|
+
getBadge,
|
|
4
|
+
getNextBadge,
|
|
5
|
+
getPointsForBadge,
|
|
6
|
+
getPointsFromStats,
|
|
7
|
+
getGamificationLevel,
|
|
8
|
+
eventLogGroupUsersByDate,
|
|
9
|
+
getGamificationLevelByStats,
|
|
10
|
+
} from './statistics';
|
|
11
|
+
|
|
12
|
+
export const stats: Stats = {
|
|
13
|
+
totalReceivers: 2,
|
|
14
|
+
receiversWithMemories: 1,
|
|
15
|
+
totalMemories: 50,
|
|
16
|
+
publicMemories: 30,
|
|
17
|
+
memoriesWithMedia: 25,
|
|
18
|
+
totalQuestions: 35,
|
|
19
|
+
publicQuestions: 30,
|
|
20
|
+
questionsWithMoreThanOneAnswer: 20,
|
|
21
|
+
totalStories: 15,
|
|
22
|
+
publicStories: 10,
|
|
23
|
+
storiesWithDate: 5,
|
|
24
|
+
storiesWithPlace: 3,
|
|
25
|
+
storiesWithDateAndPlace: 2,
|
|
26
|
+
unansweredQuestions: 10,
|
|
27
|
+
successfulCorrelations: 5,
|
|
28
|
+
failedCorrelations: 1,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const eventLogs: EventLog[] = [
|
|
32
|
+
{
|
|
33
|
+
eventLogID: '28c9f4c8-d7d5-44c4-9f79-418944b03e82',
|
|
34
|
+
eventType: 'MemoriOpened',
|
|
35
|
+
ipAddress: '::ffff:10.11.12.14',
|
|
36
|
+
memoriID: '1afe57c6-1b69-4a61-96ea-52bf7b8d158e',
|
|
37
|
+
timestamp: '2022-04-15T15:00:27.534191',
|
|
38
|
+
userAgent: 'RestSharp/106.13.0.0',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
eventLogID: '28c9f4c8-d7d5-44c4-9f79-418944b03e83',
|
|
42
|
+
eventType: 'MemoriOpened',
|
|
43
|
+
ipAddress: '::ffff:10.11.12.13',
|
|
44
|
+
memoriID: '1afe57c6-1b69-4a61-96ea-52bf7b8d158e',
|
|
45
|
+
timestamp: '2022-04-15T15:00:27.534191',
|
|
46
|
+
userAgent: 'RestSharp/106.13.0.0',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
eventLogID: '28c9f4c8-d7d5-44c4-9f79-418944b03e84',
|
|
50
|
+
eventType: 'MemoriClosed',
|
|
51
|
+
ipAddress: '::ffff:10.11.12.13',
|
|
52
|
+
memoriID: '1afe57c6-1b69-4a61-96ea-52bf7b8d158e',
|
|
53
|
+
timestamp: '2022-04-15T15:10:27.534191',
|
|
54
|
+
userAgent: 'RestSharp/106.13.0.0',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
eventLogID: '28c9f4c8-d7d5-44c4-9f79-418944b03e85',
|
|
58
|
+
eventType: 'MemoriOpened',
|
|
59
|
+
ipAddress: '::ffff:10.11.12.13',
|
|
60
|
+
memoriID: '1afe57c6-1b69-4a61-96ea-52bf7b8d158e',
|
|
61
|
+
timestamp: '2022-04-15T15:15:27.534191',
|
|
62
|
+
userAgent: 'RestSharp/106.13.0.0',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
eventLogID: '28c9f4c8-d7d5-44c4-9f79-418944b03e86',
|
|
66
|
+
eventType: 'MemoriClosed',
|
|
67
|
+
ipAddress: '::ffff:10.11.12.13',
|
|
68
|
+
memoriID: '1afe57c6-1b69-4a61-96ea-52bf7b8d158e',
|
|
69
|
+
timestamp: '2022-04-15T15:20:27.534191',
|
|
70
|
+
userAgent: 'RestSharp/106.13.0.0',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
eventLogID: '28c9f4c8-d7d5-44c4-9f79-418944b03e88',
|
|
74
|
+
eventType: 'MemoriClosed',
|
|
75
|
+
ipAddress: undefined,
|
|
76
|
+
memoriID: '1afe57c6-1b69-4a61-96ea-52bf7b8d158e',
|
|
77
|
+
timestamp: '2022-04-15T15:28:27.534191',
|
|
78
|
+
userAgent: 'RestSharp/106.13.0.0',
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
describe('getBadge', () => {
|
|
83
|
+
it('should return 🆕 badge for 0 points', () => {
|
|
84
|
+
expect(getBadge(0)).toBe('🆕');
|
|
85
|
+
});
|
|
86
|
+
it('should return 🐹 for 10 points', () => {
|
|
87
|
+
expect(getBadge(10)).toBe('🐹');
|
|
88
|
+
});
|
|
89
|
+
it('should return 🥇 for 99 points', () => {
|
|
90
|
+
expect(getBadge(99)).toBe('🥇');
|
|
91
|
+
});
|
|
92
|
+
it('should return 🥇 for 99.9 points with round', () => {
|
|
93
|
+
expect(getBadge(99.9)).toBe('🥇');
|
|
94
|
+
});
|
|
95
|
+
it('should return 🔥 for 100 points', () => {
|
|
96
|
+
expect(getBadge(100)).toBe('🔥');
|
|
97
|
+
});
|
|
98
|
+
it('should return 🔥 for 101 points', () => {
|
|
99
|
+
expect(getBadge(101)).toBe('🔥');
|
|
100
|
+
});
|
|
101
|
+
it('should return 🌎 for 150 points', () => {
|
|
102
|
+
expect(getBadge(150)).toBe('🌍');
|
|
103
|
+
});
|
|
104
|
+
it('should return 🧠 for 1000 points', () => {
|
|
105
|
+
expect(getBadge(1000)).toBe('🧠');
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('getNextBadge', () => {
|
|
110
|
+
it('should return { points: 10, badge: "🐹" } for 🆕 badge', () => {
|
|
111
|
+
expect(getNextBadge('🆕')).toEqual({ points: 10, badge: '🐹' });
|
|
112
|
+
});
|
|
113
|
+
it('should return { points: 150, badge: "🌍" } for 👾', () => {
|
|
114
|
+
expect(getNextBadge('👾')).toEqual({ points: 150, badge: '🌍' });
|
|
115
|
+
});
|
|
116
|
+
it('should return { points: 600, badge: "🧠" } for ❤', () => {
|
|
117
|
+
expect(getNextBadge('❤️')).toEqual({ points: 600, badge: '🧠' });
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe('getPointsForBadge', () => {
|
|
122
|
+
it('should return 0 for "new" badge', () => {
|
|
123
|
+
expect(getPointsForBadge('🆕')).toBe(0);
|
|
124
|
+
});
|
|
125
|
+
it('should return 10 for 🐹', () => {
|
|
126
|
+
expect(getPointsForBadge('🐹')).toBe(10);
|
|
127
|
+
});
|
|
128
|
+
it('should return 150 for 🌎', () => {
|
|
129
|
+
expect(getPointsForBadge('🌍')).toBe(150);
|
|
130
|
+
});
|
|
131
|
+
it('should return 600 for 🧠', () => {
|
|
132
|
+
expect(getPointsForBadge('🧠')).toBe(600);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('getPointsFromStats', () => {
|
|
137
|
+
it('should return 0 for no stats', () => {
|
|
138
|
+
expect(getPointsFromStats({} as Stats)).toBe(0);
|
|
139
|
+
});
|
|
140
|
+
it('should return x for stats', () => {
|
|
141
|
+
expect(getPointsFromStats(stats)).toBe(68);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe('getGamificationLevel', () => {
|
|
146
|
+
it('should return correct level for 0 points', () => {
|
|
147
|
+
expect(getGamificationLevel(0)).toEqual({
|
|
148
|
+
points: 0,
|
|
149
|
+
badge: '🆕',
|
|
150
|
+
pointsForCurrentBadge: 0,
|
|
151
|
+
nextBadge: { points: 10, badge: '🐹' },
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
it('should return correct level with 68 points', () => {
|
|
155
|
+
expect(getGamificationLevel(68.34)).toEqual({
|
|
156
|
+
points: 68,
|
|
157
|
+
badge: '🏅',
|
|
158
|
+
pointsForCurrentBadge: 60,
|
|
159
|
+
nextBadge: { points: 70, badge: '🥉' },
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
it('should return correct level with 100 points', () => {
|
|
163
|
+
expect(getGamificationLevel(100)).toEqual({
|
|
164
|
+
points: 100,
|
|
165
|
+
badge: '🔥',
|
|
166
|
+
pointsForCurrentBadge: 100,
|
|
167
|
+
nextBadge: { points: 110, badge: '🎓' },
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
it('should return correct level with 68 points and correct float round', () => {
|
|
171
|
+
expect(getGamificationLevel(67.84)).toEqual({
|
|
172
|
+
points: 68,
|
|
173
|
+
badge: '🏅',
|
|
174
|
+
pointsForCurrentBadge: 60,
|
|
175
|
+
nextBadge: { points: 70, badge: '🥉' },
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
it('should return correct level with 99.9 points', () => {
|
|
179
|
+
expect(getGamificationLevel(99.9)).toEqual({
|
|
180
|
+
points: 100,
|
|
181
|
+
badge: '🔥',
|
|
182
|
+
pointsForCurrentBadge: 100,
|
|
183
|
+
nextBadge: { points: 110, badge: '🎓' },
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
it('should return correct level with overflow 9999 points', () => {
|
|
187
|
+
expect(getGamificationLevel(9999)).toEqual({
|
|
188
|
+
points: 9999,
|
|
189
|
+
badge: '🧠',
|
|
190
|
+
pointsForCurrentBadge: 600,
|
|
191
|
+
nextBadge: undefined,
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe('getGamificationLevelByStats', () => {
|
|
197
|
+
it('should return correct level for no stats', () => {
|
|
198
|
+
expect(getGamificationLevelByStats({} as Stats)).toEqual({
|
|
199
|
+
points: 0,
|
|
200
|
+
badge: '🆕',
|
|
201
|
+
pointsForCurrentBadge: 0,
|
|
202
|
+
nextBadge: { points: 10, badge: '🐹' },
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
it('should return correct level for stats', () => {
|
|
206
|
+
expect(getGamificationLevelByStats(stats)).toEqual({
|
|
207
|
+
points: 68,
|
|
208
|
+
badge: '🏅',
|
|
209
|
+
pointsForCurrentBadge: 60,
|
|
210
|
+
nextBadge: { points: 70, badge: '🥉' },
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { difference } from './utils';
|
|
2
|
+
|
|
3
|
+
describe('Utils/difference', () => {
|
|
4
|
+
it('should return the difference between two objects with numeric values', () => {
|
|
5
|
+
const obj1 = { a: 1, b: 2, c: 3 };
|
|
6
|
+
const obj2 = { a: 1, b: 2, c: 4 };
|
|
7
|
+
const result = difference(obj1, obj2);
|
|
8
|
+
expect(result).toEqual({ c: 4 });
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should return the difference between two objects with new properties and strings', () => {
|
|
12
|
+
const obj1 = { a: 1, c: '' };
|
|
13
|
+
const obj2 = { a: 1, b: '', c: 'ciao' };
|
|
14
|
+
const result = difference(obj1, obj2);
|
|
15
|
+
expect(result).toEqual({ b: '', c: 'ciao' });
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should return the difference between two objects from null or undefined', () => {
|
|
19
|
+
const obj1 = { a: 1, c: null };
|
|
20
|
+
const obj2 = { a: 1, b: '', c: 'ciao' };
|
|
21
|
+
const result = difference(obj1, obj2);
|
|
22
|
+
expect(result).toEqual({ b: '', c: 'ciao' });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should return the difference between two objects with lists', () => {
|
|
26
|
+
const obj1 = { a: [], b: 'thesame' };
|
|
27
|
+
const obj2 = { a: ['alpha', 'beta', 'gamma'], b: 'thesame' };
|
|
28
|
+
const result = difference(obj1, obj2);
|
|
29
|
+
expect(result).toEqual({ a: ['alpha', 'beta', 'gamma'] });
|
|
30
|
+
});
|
|
31
|
+
});
|
package/src/styles.css
CHANGED