Skip to content

Commit e931939

Browse files
Unit test linking and unlinking attributions
Signed-off-by: Markus Obendrauf <markusobendrauf@fb.com>
1 parent 635fb82 commit e931939

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

src/Frontend/state/helpers/__tests__/save-action-helpers.test.ts

+99
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import {
1919
createManualAttribution,
2020
deleteManualAttribution,
2121
updateManualAttribution,
22+
unlinkResourceFromAttributionId,
23+
linkToAttributionManualData,
2224
} from '../save-action-helpers';
2325

2426
const testUuid: string = uuidNil;
@@ -193,6 +195,103 @@ describe('The updateManualAttribution function', () => {
193195
});
194196
});
195197

198+
describe('The linkToAttributionManualData function', () => {
199+
it('links a manual attribution', () => {
200+
const testManualData: AttributionData = {
201+
attributions: {
202+
[testUuid]: {
203+
packageName: 'testpackage',
204+
packageVersion: '2.0',
205+
licenseText: 'Permission is hereby granted',
206+
},
207+
},
208+
resourcesToAttributions: {},
209+
attributionsToResources: {},
210+
resourcesWithAttributedChildren: {
211+
attributedChildren: {},
212+
pathsToIndices: {
213+
'/': 0,
214+
'/first/': 1,
215+
},
216+
paths: ['/', '/first/'],
217+
},
218+
};
219+
220+
const newManualData = linkToAttributionManualData(
221+
testManualData,
222+
'/first/',
223+
testUuid,
224+
() => false,
225+
);
226+
227+
expect(newManualData.attributions).toEqual(testManualData.attributions);
228+
expect(newManualData.resourcesToAttributions).toEqual({
229+
'/first/': [testUuid],
230+
});
231+
expect(newManualData.attributionsToResources).toEqual({
232+
[testUuid]: ['/first/'],
233+
});
234+
expect(newManualData.resourcesWithAttributedChildren).toEqual({
235+
attributedChildren: {
236+
'0': new Set<number>().add(1),
237+
},
238+
pathsToIndices: {
239+
'/': 0,
240+
'/first/': 1,
241+
},
242+
paths: ['/', '/first/'],
243+
});
244+
});
245+
});
246+
247+
describe('The unlinkResourceFromAttributionId function', () => {
248+
it('unlinks a manual attribution', () => {
249+
const testManualData: AttributionData = {
250+
attributions: {
251+
[testUuid]: {
252+
packageName: 'testpackage',
253+
packageVersion: '2.0',
254+
licenseText: 'Permission is hereby granted',
255+
},
256+
},
257+
resourcesToAttributions: {
258+
'/first/': [testUuid],
259+
},
260+
attributionsToResources: {
261+
[testUuid]: ['/first/'],
262+
},
263+
resourcesWithAttributedChildren: {
264+
attributedChildren: {
265+
'0': new Set<number>().add(1),
266+
},
267+
pathsToIndices: {
268+
'/': 0,
269+
'/first/': 1,
270+
},
271+
paths: ['/', '/first/'],
272+
},
273+
};
274+
275+
const newManualData: AttributionData = unlinkResourceFromAttributionId(
276+
testManualData,
277+
'/first/',
278+
testUuid,
279+
);
280+
281+
expect(newManualData.attributions).toEqual(testManualData.attributions);
282+
expect(isEmpty(newManualData.resourcesToAttributions)).toBe(true);
283+
expect(isEmpty(newManualData.attributionsToResources)).toBe(true);
284+
expect(newManualData.resourcesWithAttributedChildren).toEqual({
285+
attributedChildren: {},
286+
pathsToIndices: {
287+
'/': 0,
288+
'/first/': 1,
289+
},
290+
paths: ['/', '/first/'],
291+
});
292+
});
293+
});
294+
196295
describe('_removeManualAttributionFromChildrenIfAllAreIdentical', () => {
197296
it('three matching', () => {
198297
const testManualData: AttributionData = {

0 commit comments

Comments
 (0)