mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
* Re-organize common folder * fix: Correct paths in tests * fix: move new content to proper folder * chore: Move audio folder to assets * Move sprites to sprites assets directory * Move css sprites to assets directory * Split out readmes for common code and sprites * Move images to assets directory * Move destinatin of shared browserified file * remove unused file * move compiled js to client-old * Fix karma tests * fix: Correct paths for sprites
54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
import shared from '../../../website/common';
|
|
import { v4 as generateUUID } from 'uuid';
|
|
|
|
describe('refPush', () => {
|
|
it('it hashes one object into another by its id', () => {
|
|
let referenceObject = {};
|
|
let objectToHash = {
|
|
a: 1,
|
|
id: generateUUID(),
|
|
};
|
|
|
|
shared.refPush(referenceObject, objectToHash);
|
|
|
|
expect(referenceObject[objectToHash.id].a).to.equal(objectToHash.a);
|
|
expect(referenceObject[objectToHash.id].id).to.equal(objectToHash.id);
|
|
expect(referenceObject[objectToHash.id].sort).to.equal(0);
|
|
});
|
|
|
|
it('it hashes one object into another by a uuid when object does not have an id', () => {
|
|
let referenceObject = {};
|
|
let objectToHash = {
|
|
a: 1,
|
|
};
|
|
|
|
shared.refPush(referenceObject, objectToHash);
|
|
|
|
let hashedObject = _.find(referenceObject, (hashedItem) => {
|
|
return objectToHash.a === hashedItem.a;
|
|
});
|
|
|
|
expect(hashedObject.a).to.equal(objectToHash.a);
|
|
expect(hashedObject.id).to.equal(objectToHash.id);
|
|
expect(hashedObject.sort).to.equal(0);
|
|
});
|
|
|
|
it('it hashes one object into another by a id and gives it the highest sort value', () => {
|
|
let referenceObject = {};
|
|
referenceObject[generateUUID()] = { b: 2, sort: 1 };
|
|
let objectToHash = {
|
|
a: 1,
|
|
};
|
|
|
|
shared.refPush(referenceObject, objectToHash);
|
|
|
|
let hashedObject = _.find(referenceObject, (hashedItem) => {
|
|
return objectToHash.a === hashedItem.a;
|
|
});
|
|
|
|
expect(hashedObject.a).to.equal(objectToHash.a);
|
|
expect(hashedObject.id).to.equal(objectToHash.id);
|
|
expect(hashedObject.sort).to.equal(2);
|
|
});
|
|
});
|