Skip to content

Commit f51f8e5

Browse files
committed
Add tests.
1 parent ba41c1b commit f51f8e5

File tree

1 file changed

+157
-2
lines changed

1 file changed

+157
-2
lines changed

tests/misc.js

Lines changed: 157 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ function trackEvent({events, event}) {
507507
});
508508
}
509509

510-
describe.only('events', () => {
510+
describe('events', () => {
511511
// FIXME/TODO add object '*' handler and tests?
512512

513513
it('check default handler called', async () => {
@@ -932,7 +932,7 @@ describe.only('events', () => {
932932
});
933933
});
934934

935-
describe.only('expansionMap', () => {
935+
describe('expansionMap', () => {
936936
// track all the counts
937937
// use simple count object (don't use tricky test keys!)
938938
function addCounts(counts, info) {
@@ -1030,6 +1030,161 @@ describe.only('expansionMap', () => {
10301030
console.error('FIXME');
10311031
assert.deepStrictEqual(events, {});
10321032
});
1033+
1034+
it('should notify for @set free-floating scaler', async () => {
1035+
const docWithNoTerms =
1036+
{
1037+
"@set": [
1038+
"free-floating strings in set objects are removed",
1039+
{
1040+
"@id": "http://example.com/free-floating-node"
1041+
},
1042+
{
1043+
"@id": "http://example.com/node",
1044+
"urn:property": "nodes with properties are not removed"
1045+
}
1046+
]
1047+
}
1048+
;
1049+
const ex =
1050+
[
1051+
{
1052+
"@id": "http://example.com/node",
1053+
"urn:property": [
1054+
{
1055+
"@value": "nodes with properties are not removed"
1056+
}
1057+
]
1058+
}
1059+
]
1060+
;
1061+
1062+
const mapCounts = {};
1063+
const expansionMap = info => {
1064+
addCounts(mapCounts, info);
1065+
};
1066+
const events = {};
1067+
const eventHandler = ({event}) => {
1068+
trackEvent({events, event});
1069+
};
1070+
1071+
const e = await jsonld.expand(docWithNoTerms, {
1072+
expansionMap, eventHandler
1073+
});
1074+
1075+
assert.deepStrictEqual(e, ex);
1076+
assert.deepStrictEqual(mapCounts, {
1077+
expansionMap: 4,
1078+
unmappedValue: {
1079+
'__unknown__': 2,
1080+
'http://example.com/free-floating-node': 2
1081+
}
1082+
});
1083+
console.error('FIXME');
1084+
assert.deepStrictEqual(events, {});
1085+
});
1086+
1087+
it('should notify for @list free-floating scaler', async () => {
1088+
const docWithNoTerms =
1089+
{
1090+
"@list": [
1091+
"free-floating strings in list objects are removed",
1092+
{
1093+
"@id": "http://example.com/free-floating-node"
1094+
},
1095+
{
1096+
"@id": "http://example.com/node",
1097+
"urn:property": "nodes are removed with the @list"
1098+
}
1099+
]
1100+
}
1101+
;
1102+
const ex = [];
1103+
1104+
const mapCounts = {};
1105+
const expansionMap = info => {
1106+
addCounts(mapCounts, info);
1107+
};
1108+
const events = {};
1109+
const eventHandler = ({event}) => {
1110+
trackEvent({events, event});
1111+
};
1112+
1113+
const e = await jsonld.expand(docWithNoTerms, {
1114+
expansionMap, eventHandler
1115+
});
1116+
1117+
assert.deepStrictEqual(e, ex);
1118+
assert.deepStrictEqual(mapCounts, {
1119+
expansionMap: 5,
1120+
unmappedValue: {
1121+
'__unknown__': 3,
1122+
'http://example.com/free-floating-node': 2
1123+
}
1124+
});
1125+
console.error('FIXME');
1126+
assert.deepStrictEqual(events, {});
1127+
});
1128+
1129+
it('should notify for null @value', async () => {
1130+
const docWithNoTerms =
1131+
{
1132+
"urn:property": {
1133+
"@value": null
1134+
}
1135+
}
1136+
;
1137+
1138+
const mapCounts = {};
1139+
const expansionMap = info => {
1140+
addCounts(mapCounts, info);
1141+
};
1142+
const events = {};
1143+
const eventHandler = ({event}) => {
1144+
trackEvent({events, event});
1145+
};
1146+
1147+
await jsonld.expand(docWithNoTerms, {expansionMap, eventHandler});
1148+
1149+
assert.deepStrictEqual(mapCounts, {
1150+
expansionMap: 3,
1151+
unmappedValue: {
1152+
'__unknown__': 3
1153+
}
1154+
});
1155+
console.error('FIXME');
1156+
assert.deepStrictEqual(events, {});
1157+
});
1158+
1159+
it('should notify for @language alone', async () => {
1160+
const docWithNoTerms =
1161+
{
1162+
"urn:property": {
1163+
"@language": "en"
1164+
}
1165+
}
1166+
;
1167+
1168+
const mapCounts = {};
1169+
const expansionMap = info => {
1170+
addCounts(mapCounts, info);
1171+
};
1172+
const events = {};
1173+
const eventHandler = ({event}) => {
1174+
trackEvent({events, event});
1175+
};
1176+
1177+
await jsonld.expand(docWithNoTerms, {expansionMap, eventHandler});
1178+
1179+
assert.deepStrictEqual(mapCounts, {
1180+
expansionMap: 3,
1181+
unmappedValue: {
1182+
'__unknown__': 2
1183+
}
1184+
});
1185+
console.error('FIXME');
1186+
assert.deepStrictEqual(events, {});
1187+
});
10331188
});
10341189

10351190
describe('unmappedProperty', () => {

0 commit comments

Comments
 (0)