@memori.ai/memori-react 2.6.2 → 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 +19 -0
- package/dist/components/AvatarView/index.js +1 -1
- package/dist/components/AvatarView/index.js.map +1 -1
- 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.d.ts +1 -1
- package/dist/helpers/utils.js +3 -3
- package/dist/helpers/utils.js.map +1 -1
- 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/AvatarView/index.js +2 -2
- package/esm/components/AvatarView/index.js.map +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.d.ts +1 -1
- package/esm/helpers/utils.js +1 -1
- package/esm/helpers/utils.js.map +1 -1
- 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/AvatarView/index.tsx +2 -2
- 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/helpers/utils.ts +1 -1
- package/src/styles.css +1 -1
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { getResourceUrl } from './media';
|
|
2
|
+
|
|
3
|
+
const tenantID = 'app.memorytwin.com';
|
|
4
|
+
const sessionID = 'e995ac6f-8014-4ac0-9992-60fe87ae8b44';
|
|
5
|
+
const mediumID = 'a196b513-d745-4121-8913-8f457b999add';
|
|
6
|
+
|
|
7
|
+
describe('Media URL helper', () => {
|
|
8
|
+
it('Get default avatar URL with no url', async () => {
|
|
9
|
+
expect(
|
|
10
|
+
getResourceUrl({
|
|
11
|
+
type: 'avatar',
|
|
12
|
+
baseURL: 'https://twin.memori.ai',
|
|
13
|
+
apiURL: 'https://backend.memori.ai/api/v2',
|
|
14
|
+
})
|
|
15
|
+
).toBe('https://twin.memori.ai/images/memoriAvatar.png');
|
|
16
|
+
});
|
|
17
|
+
it('Get default cover URL with no url', async () => {
|
|
18
|
+
expect(
|
|
19
|
+
getResourceUrl({
|
|
20
|
+
type: 'cover',
|
|
21
|
+
apiURL: 'https://backend.memori.ai/api/v2',
|
|
22
|
+
baseURL: 'https://twin.memori.ai',
|
|
23
|
+
})
|
|
24
|
+
).toBe('https://twin.memori.ai/images/memoriCover.png');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('Get correct URL for media', async () => {
|
|
28
|
+
expect(
|
|
29
|
+
getResourceUrl({
|
|
30
|
+
resourceURI:
|
|
31
|
+
'https://assets.memori.ai/api/v2/asset/0eed819c-b496-4419-a9a3-aacbe949bb7c.jpeg/',
|
|
32
|
+
sessionID: sessionID,
|
|
33
|
+
apiURL: 'https://backend.memori.ai/api/v2',
|
|
34
|
+
})
|
|
35
|
+
).toBe(
|
|
36
|
+
`https://assets.memori.ai/api/v2/asset/0eed819c-b496-4419-a9a3-aacbe949bb7c.jpeg/${sessionID}`
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('Get correct URL for external media', async () => {
|
|
41
|
+
expect(
|
|
42
|
+
getResourceUrl({
|
|
43
|
+
resourceURI:
|
|
44
|
+
'https://api.lorem.space/image/game?w=150&h=220&hash=8B7BCDC2',
|
|
45
|
+
apiURL: 'https://backend.memori.ai/api/v2',
|
|
46
|
+
})
|
|
47
|
+
).toBe('https://api.lorem.space/image/game?w=150&h=220&hash=8B7BCDC2');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('Get correct URL for old memoriai/memory media', async () => {
|
|
51
|
+
expect(
|
|
52
|
+
getResourceUrl({
|
|
53
|
+
resourceURI:
|
|
54
|
+
'https://backend.memori.ai/api/v1/memoriai/memory/2d434f42-3e95-46ad-9bd5-a10b65977407/media/cloud/studio.memori.ai/2f7b56d1-06a2-4908-9dd3-ef30359b5d05.jpeg',
|
|
55
|
+
apiURL: 'https://backend.memori.ai/api/v2',
|
|
56
|
+
sessionID: sessionID,
|
|
57
|
+
})
|
|
58
|
+
).toBe(
|
|
59
|
+
`https://backend.memori.ai/api/v1/memoriai/memory/2d434f42-3e95-46ad-9bd5-a10b65977407/media/cloud/studio.memori.ai/2f7b56d1-06a2-4908-9dd3-ef30359b5d05.jpeg?memori-ai-session-id=${sessionID}`
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('Get correct URL for old cloud://tenantID media', async () => {
|
|
64
|
+
expect(
|
|
65
|
+
getResourceUrl({
|
|
66
|
+
// cloud://twin.memori.ai/5fc7cd8b-7c8f-4d92-83ad-f48d04b6aafe.jpeg
|
|
67
|
+
resourceURI: `cloud://${tenantID}/${mediumID}`,
|
|
68
|
+
apiURL: 'https://backend.memori.ai/api/v2',
|
|
69
|
+
sessionID: sessionID,
|
|
70
|
+
tenantID: tenantID,
|
|
71
|
+
})
|
|
72
|
+
).toBe(
|
|
73
|
+
`https://backend.memori.ai/api/v1/CloudAsset/${tenantID}/${mediumID}`
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('Get correct URL for old cloud://tenantID media', async () => {
|
|
78
|
+
expect(
|
|
79
|
+
getResourceUrl({
|
|
80
|
+
// cloud://twin.memori.ai/5fc7cd8b-7c8f-4d92-83ad-f48d04b6aafe.jpeg
|
|
81
|
+
resourceURI: `cloud://twin.memori.ai/5fc7cd8b-7c8f-4d92-83ad-f48d04b6aafe.jpeg
|
|
82
|
+
`,
|
|
83
|
+
apiURL: 'https://backend.memori.ai/api/v2',
|
|
84
|
+
sessionID: sessionID,
|
|
85
|
+
tenantID: 'twin.memori.ai',
|
|
86
|
+
})
|
|
87
|
+
).toBe(
|
|
88
|
+
`https://backend.memori.ai/api/v1/CloudAsset/twin.memori.ai/5fc7cd8b-7c8f-4d92-83ad-f48d04b6aafe.jpeg
|
|
89
|
+
`
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('Get correct URL for old cloud://tenantID media', async () => {
|
|
94
|
+
expect(
|
|
95
|
+
getResourceUrl({
|
|
96
|
+
resourceURI:
|
|
97
|
+
'cloud://twin.memori.ai/6c30043c-9de1-4d13-87e4-c53adb3f9885.jpg',
|
|
98
|
+
apiURL: 'https://backend.memori.ai/api/v2',
|
|
99
|
+
sessionID: sessionID,
|
|
100
|
+
tenantID: 'twin.memori.ai',
|
|
101
|
+
})
|
|
102
|
+
).toBe(
|
|
103
|
+
`https://backend.memori.ai/api/v1/CloudAsset/twin.memori.ai/6c30043c-9de1-4d13-87e4-c53adb3f9885.jpg`
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('Get correct URL for old cloud://tenantID media with old non-existent tenant', async () => {
|
|
108
|
+
expect(
|
|
109
|
+
getResourceUrl({
|
|
110
|
+
// cloud://twin.memori.ai/5fc7cd8b-7c8f-4d92-83ad-f48d04b6aafe.jpeg
|
|
111
|
+
resourceURI: `cloud://twin.memori.ai/5fc7cd8b-7c8f-4d92-83ad-f48d04b6aafe.jpeg
|
|
112
|
+
`,
|
|
113
|
+
apiURL: 'https://backend.memori.ai/api/v2',
|
|
114
|
+
sessionID: sessionID,
|
|
115
|
+
tenantID: 'app.memorytwin.com',
|
|
116
|
+
})
|
|
117
|
+
).toBe(
|
|
118
|
+
`https://backend.memori.ai/api/v1/CloudAsset/twin.memori.ai/5fc7cd8b-7c8f-4d92-83ad-f48d04b6aafe.jpeg
|
|
119
|
+
`
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('Get correct URL for old guid://tenant media', async () => {
|
|
124
|
+
expect(
|
|
125
|
+
getResourceUrl({
|
|
126
|
+
resourceURI: `guid://${mediumID}`,
|
|
127
|
+
apiURL: 'https://backend.memori.ai/api/v2',
|
|
128
|
+
sessionID: sessionID,
|
|
129
|
+
tenantID: tenantID,
|
|
130
|
+
})
|
|
131
|
+
).toBe(`https://backend.memori.ai/api/v1/GuidAsset/${mediumID}`);
|
|
132
|
+
});
|
|
133
|
+
});
|
package/src/helpers/media.ts
CHANGED
|
@@ -30,9 +30,12 @@ export const getResourceUrl = ({
|
|
|
30
30
|
} else if (
|
|
31
31
|
(resourceURI.startsWith('https://') ||
|
|
32
32
|
resourceURI.startsWith('http://')) &&
|
|
33
|
-
new URL(resourceURI).hostname.includes('memori.ai')
|
|
33
|
+
(new URL(resourceURI).hostname.includes('memori.ai') ||
|
|
34
|
+
new URL(resourceURI).hostname.includes('aclambda.online'))
|
|
34
35
|
) {
|
|
35
|
-
return `${resourceURI}${
|
|
36
|
+
return `${resourceURI}${
|
|
37
|
+
resourceURI.endsWith('/') || !sessionID ? '' : '/'
|
|
38
|
+
}${sessionID || ''}`;
|
|
36
39
|
} else if (resourceURI.startsWith('cloud://')) {
|
|
37
40
|
return `${
|
|
38
41
|
apiURL?.replace(/v2/, 'v1') || ''
|
|
@@ -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/helpers/utils.ts
CHANGED
package/src/styles.css
CHANGED