Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support dimension units #340

Merged
merged 4 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/solid-crs-client/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { login, handleIncomingRedirect, logout, fetch, getDefaultSession } from '@inrupt/solid-client-authn-browser';
export { getSolidDataset, getThing, getStringNoLocale, getStringNoLocaleAll, getUrl, getStringByLocaleAll, getStringWithLocale, getStringWithLocaleAll, getThingAll, getUrlAll, removeAll, removeThing, saveSolidDatasetAt, setThing, removeUrl, Thing, addStringWithLocale, addStringNoLocale, addUrl, addDatetime, getDatetime, createThing, asUrl, overwriteFile, deleteFile, ThingPersisted, getInteger, addInteger, access } from '@inrupt/solid-client';
export { getSolidDataset, getThing, getStringNoLocale, getStringNoLocaleAll, getUrl, getStringByLocaleAll, getStringWithLocale, getStringWithLocaleAll, getThingAll, getUrlAll, removeAll, removeThing, saveSolidDatasetAt, setThing, removeUrl, Thing, addStringWithLocale, addStringNoLocale, addUrl, addDatetime, getDatetime, createThing, asUrl, overwriteFile, deleteFile, ThingPersisted, getInteger, addInteger, access, addDecimal, getDecimal } from '@inrupt/solid-client';
4 changes: 4 additions & 0 deletions packages/solid-crs-manage/lib/app-root.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export class AppRootComponent extends RxLitElement {
width: 0,
depth: 0,
weight: 0,
heightUnit: 'CMT',
widthUnit: 'CMT',
depthUnit: 'CMT',
weightUnit: 'KGM',
}
)).withContext({
alerts: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as client from '@netwerk-digitaal-erfgoed/solid-crs-client';
import { getInteger, getStringNoLocale, getStringWithLocale, getUrl } from '@netwerk-digitaal-erfgoed/solid-crs-client';
import { addDecimal, getStringNoLocale, getStringWithLocale, getUrl } from '@netwerk-digitaal-erfgoed/solid-crs-client';
import { Collection, CollectionObject } from '@netwerk-digitaal-erfgoed/solid-crs-core';
import { CollectionObjectSolidStore } from './collection-object-solid-store';

Expand Down Expand Up @@ -32,6 +32,14 @@ describe('CollectionObjectSolidStore', () => {
type: 'http://test.type',
image: 'http://test.image',
mainEntityOfPage: 'http://test.uri/',
weight: 2,
height: 2,
depth: 2,
width: 2,
weightUnit: 'KGM',
heightUnit: 'CMT',
depthUnit: 'CMT',
widthUnit: 'CMT',
};

});
Expand Down Expand Up @@ -88,6 +96,31 @@ describe('CollectionObjectSolidStore', () => {

});

it('should set default uris for related object when not found', async () => {

let objectThing = client.createThing({ url: mockObject.uri });
objectThing = client.addUrl(objectThing, 'http://schema.org/isPartOf', mockCollection.uri);

client.getSolidDataset = jest.fn(async () => 'test-dataset');
client.getThing = jest.fn(() => client.createThing({ url: mockObject.uri }));
client.getThingAll = jest.fn(() => [ objectThing ]);
client.getUrl = jest.fn((thing, uri) => uri === 'http://schema.org/isPartOf' ? 'http://test.uri/' : null);

const url = mockObject.uri;
const result = await service.getObjectsForCollection(mockCollection);

expect(result).toBeTruthy();

expect(client.getThing.mock.calls).toEqual([
[ 'test-dataset', CollectionObjectSolidStore.getDigitalObjectUri(url) ],
[ 'test-dataset', `${url}-height` ],
[ 'test-dataset', `${url}-width` ],
[ 'test-dataset', `${url}-depth` ],
[ 'test-dataset', `${url}-weight` ],
]);

});

});

describe('get()', () => {
Expand All @@ -101,11 +134,12 @@ describe('CollectionObjectSolidStore', () => {
it('should return collection object', async () => {

client.getSolidDataset = jest.fn(async () => 'test-dataset');
client.getThing = jest.fn(() => 'test-thing');
client.getThing = jest.fn(() => client.createThing());
client.getUrl = jest.fn(() => 'test-url');
client.getStringWithLocale = jest.fn(() => 'test-string');
client.getStringNoLocale = jest.fn(() => 'test-string');
client.getInteger = jest.fn(() => 1);
client.getDecimal = jest.fn(() => 1);
client.asUrl = jest.fn(() => 'test-url');

await expect(service.get('test-url')).resolves.toEqual(
Expand All @@ -118,6 +152,28 @@ describe('CollectionObjectSolidStore', () => {

});

it('should set default uris for related object when not found', async () => {

client.getSolidDataset = jest.fn(async () => 'test-dataset');
client.getThing = jest.fn(() => client.createThing());
client.getUrl = jest.fn(() => null);

const url = 'test-url';
const result = await service.get('test-url');

expect(result).toBeTruthy();

expect(client.getThing.mock.calls).toEqual([
[ 'test-dataset', url ],
[ 'test-dataset', CollectionObjectSolidStore.getDigitalObjectUri(url) ],
[ 'test-dataset', `${url}-height` ],
[ 'test-dataset', `${url}-width` ],
[ 'test-dataset', `${url}-depth` ],
[ 'test-dataset', `${url}-weight` ],
]);

});

});

describe('all()', () => {
Expand All @@ -141,7 +197,7 @@ describe('CollectionObjectSolidStore', () => {
it('should return collection when deleted', () => {

client.getSolidDataset = jest.fn(async () => 'test-dataset');
client.getThing = jest.fn(() => 'test-thing');
client.getThing = jest.fn(() => client.createThing());
client.removeUrl = jest.fn(() => 'test-thing');
client.setThing = jest.fn(() => 'test-dataset');
client.removeThing = jest.fn(() => 'test-thing');
Expand Down Expand Up @@ -174,7 +230,7 @@ describe('CollectionObjectSolidStore', () => {
it('should return object when saved', async () => {

client.getSolidDataset = jest.fn(async () => 'test-dataset');
client.getThing = jest.fn(() => 'test-thing');
client.getThing = jest.fn(() => client.createThing());
client.getUrl = jest.fn(() => 'http://test-uri/');
client.setThing = jest.fn(() => 'test-thing');
client.removeThing = jest.fn(() => 'test-thing');
Expand All @@ -183,6 +239,7 @@ describe('CollectionObjectSolidStore', () => {
client.addStringNoLocale = jest.fn(() => 'test-url');
client.addStringWithLocale = jest.fn(() => 'test-url');
client.addInteger = jest.fn(() => 'test-url');
client.addDecimal = jest.fn(() => 'test-url');

const result = await service.save(mockObject)
;
Expand All @@ -203,7 +260,7 @@ describe('CollectionObjectSolidStore', () => {
delete mockObject.uri;

client.getSolidDataset = jest.fn(async () => 'test-dataset');
client.getThing = jest.fn(() => 'test-thing');
client.getThing = jest.fn(() => client.createThing());
client.getUrl = jest.fn(() => 'http://test-url/');
client.setThing = jest.fn(() => 'test-thing');
client.removeThing = jest.fn(() => 'test-thing');
Expand All @@ -230,7 +287,10 @@ describe('CollectionObjectSolidStore', () => {

const mockObject2 = { uri: mockObject.uri } as CollectionObject;

const { object: result, digitalObject } = CollectionObjectSolidStore.toThing(mockObject2);
const { object: result } = CollectionObjectSolidStore.toThing(mockObject2);

client.addDecimal = jest.fn((thing) => thing);
client.addStringNoLocale = jest.fn((thing) => thing);

expect(getStringNoLocale(result, 'http://schema.org/dateModified')).toBeFalsy();
expect(getUrl(result, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type')).toBeFalsy();
Expand All @@ -249,10 +309,10 @@ describe('CollectionObjectSolidStore', () => {
expect(getStringNoLocale(result, 'http://schema.org/Person')).toBeFalsy();
expect(getStringNoLocale(result, 'http://schema.org/Organization')).toBeFalsy();
expect(getStringNoLocale(result, 'http://schema.org/Event')).toBeFalsy();
expect(getInteger(result, 'http://schema.org/height')).toBeFalsy();
expect(getInteger(result, 'http://schema.org/width')).toBeFalsy();
expect(getInteger(result, 'http://schema.org/depth')).toBeFalsy();
expect(getInteger(result, 'http://schema.org/weight')).toBeFalsy();
expect(getUrl(result, 'http://schema.org/height')).toBeFalsy();
expect(getUrl(result, 'http://schema.org/width')).toBeFalsy();
expect(getUrl(result, 'http://schema.org/depth')).toBeFalsy();
expect(getUrl(result, 'http://schema.org/weight')).toBeFalsy();
expect(getUrl(result, 'http://schema.org/image')).toBeFalsy();
expect(getUrl(result, 'http://schema.org/mainEntityOfPage')).toBeFalsy();
expect(getUrl(result, 'http://schema.org/license')).toBeFalsy();
Expand Down Expand Up @@ -284,6 +344,10 @@ describe('CollectionObjectSolidStore', () => {
width: 2,
depth: 2,
weight: 2,
heightUnit: 'CMT',
widthUnit: 'CMT',
depthUnit: 'CMT',
weightUnit: 'KGM',
image: 'http://test.url/',
mainEntityOfPage: 'http://test.url',
license: 'http://test.url',
Expand All @@ -299,15 +363,36 @@ describe('CollectionObjectSolidStore', () => {

describe('fromThing()', () => {

it('should error when object is null', () => {

expect(() => CollectionObjectSolidStore.fromThing(null, client.createThing({ url: mockObject.uri }))).toThrow();

});

it('should error when digitalObject is null', () => {

expect(() => CollectionObjectSolidStore.fromThing(client.createThing({ url: mockObject.uri }), null)).toThrow();
it.each([
'object',
'digitalObject',
'height',
'width',
'depth',
'weight',
])('should error when object is %s', (value) => {

const thing = client.createThing({ url: mockObject.uri });

const params = {
object: thing,
digitalObject: thing,
height: thing,
width: thing,
depth: thing,
weight: thing,
};

params[value] = null;

expect(() => CollectionObjectSolidStore.fromThing(
params.object,
params.digitalObject,
params.height,
params.width,
params.depth,
params.weight,
)).toThrow();

});

Expand All @@ -318,9 +403,20 @@ describe('CollectionObjectSolidStore', () => {
client.getStringWithLocale = jest.fn(() => undefined);
client.asUrl = jest.fn(() => undefined);

jest.clearAllMocks();
jest.resetAllMocks();
jest.restoreAllMocks();

const objectThing = client.createThing({ url: mockObject.uri });

const result = CollectionObjectSolidStore.fromThing(objectThing, objectThing);
const result = CollectionObjectSolidStore.fromThing(
objectThing,
objectThing,
objectThing,
objectThing,
objectThing,
objectThing,
);

expect(result.updated).toEqual(undefined);
expect(result.type).toEqual(undefined);
Expand All @@ -337,6 +433,14 @@ describe('CollectionObjectSolidStore', () => {
expect(result.image).toEqual(undefined);
expect(result.mainEntityOfPage).toEqual(undefined);
expect(result.subject).toEqual(undefined);
expect(result.height).toEqual(undefined);
expect(result.width).toEqual(undefined);
expect(result.depth).toEqual(undefined);
expect(result.weight).toEqual(undefined);
expect(result.heightUnit).toEqual(undefined);
expect(result.widthUnit).toEqual(undefined);
expect(result.depthUnit).toEqual(undefined);
expect(result.weightUnit).toEqual(undefined);

});

Expand Down Expand Up @@ -376,17 +480,23 @@ describe('CollectionObjectSolidStore', () => {

});

it('should error when object is empty', () => {

expect(() => CollectionObjectSolidStore.getDigitalObjectUri(' ')).toThrow();

});

it('should error when object uri is not set', () => {

delete mockObject.uri;

expect(() => CollectionObjectSolidStore.getDigitalObjectUri(mockObject)).toThrow();
expect(() => CollectionObjectSolidStore.getDigitalObjectUri(mockObject.uri)).toThrow();

});

it('should return correct uri', () => {

expect(CollectionObjectSolidStore.getDigitalObjectUri(mockObject)).toEqual(`${mockObject.uri}-digital`);
expect(CollectionObjectSolidStore.getDigitalObjectUri(mockObject.uri)).toEqual(`${mockObject.uri}-digital`);

});

Expand Down
Loading