Skip to content

Commit 1753a03

Browse files
committed
Changing how mocking of rdflib works + fixing most tests
This allows for reusing most of rdflib.js as is, with the exception of Fetcher and UpdateManager (the latter is dependent on the former). I've fixed most tests that broke, with exception of peoplePicker.test.ts, pad.test.ts and forms.test.ts, as these are being currently worked on by others. I've simply commented this out, and they should prioritize their own work when merge conflict happen, and then fix the broken tests that may have come. Note: We might want to change UpdateManager in rdflib to optionally take in Fetcher so that we don't need to mock it.
1 parent 98796c4 commit 1753a03

41 files changed

Lines changed: 2378 additions & 2569 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

__mocks__/rdflib.ts

Lines changed: 69 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,86 @@
1-
export const Util = {
2-
mediaTypeClass: sym
3-
}
4-
5-
export function sym () {
6-
return {
7-
dir: sym,
8-
uri: 'uri',
9-
value: '',
10-
elements: [],
11-
doc: () => {
12-
return {
13-
equals: () => {},
14-
value: ''
15-
}
16-
},
17-
sameTerm: () => false
18-
}
19-
}
20-
21-
export const uri = {
22-
join: () => {}
23-
}
24-
export function st() {
25-
}
1+
// @@ TODO: Remove currently untyped methods as they are added
262

27-
export function literal() {
28-
}
29-
export class Query {
30-
vars: any
31-
pat: any
32-
constructor () {
33-
this.vars = []
34-
this.pat = {
35-
add() {}
36-
}
37-
}
38-
}
3+
import { IndexedFormula } from 'rdflib'
394

40-
export function variable () {
41-
}
5+
export {
6+
BlankNode,
7+
Collection,
8+
convert,
9+
DataFactory,
10+
Empty,
11+
Formula,
12+
// Store, // Not currently supported in @types/rdflib
13+
// jsonParser, // Not currently supported in @types/rdflib
14+
Literal,
15+
log,
16+
// N3Parser, // Not currently supported in @types/rdflib
17+
NamedNode,
18+
Namespace,
19+
Node,
20+
parse,
21+
Query,
22+
// queryToSPARQL, // Not currently supported in @types/rdflib
23+
// RDFaProcessor, // Not currently supported in @types/rdflib
24+
// RDFParser, // Not currently supported in @types/rdflib
25+
// serialize, // Not currently supported in @types/rdflib
26+
// Serializer, // Not currently supported in @types/rdflib
27+
// SPARQLToQuery, // Not currently supported in @types/rdflib
28+
// sparqlUpdateParser, // Not currently supported in @types/rdflib
29+
Statement,
30+
term,
31+
// UpdatesSocket, // Not currently supported in @types/rdflib
32+
// UpdatesVia, // Not currently supported in @types/rdflib
33+
uri,
34+
Util,
35+
Variable,
36+
NextId,
37+
fromNT,
38+
graph,
39+
lit,
40+
st,
41+
namedNode as sym,
42+
blankNode,
43+
defaultGraph,
44+
literal,
45+
namedNode,
46+
quad,
47+
triple,
48+
variable
49+
} from 'rdflib'
4250

43-
export function graph() {
44-
return new Graph()
45-
}
46-
class Graph {
47-
mockStatements
48-
fetcher
49-
constructor() {
50-
this.mockStatements = []
51-
this.fetcher = new Fetcher()
52-
}
53-
any () {
54-
return sym()
55-
}
56-
// see https://linkeddata.github.io/rdflib.js/doc/classes/indexedformula.html#each
57-
each (s, p, o, g) {
58-
if (s === undefined) {
59-
return this.mockStatements
60-
.filter(statement => p.uri === statement.p.uri)
61-
.filter(statement => o.uri === statement.o.uri)
62-
.filter(statement => g.uri === statement.g.uri)
63-
.map(statement => statement.s)
64-
}
65-
if (p === undefined) {
66-
return this.mockStatements
67-
.filter(statement => s.uri === statement.s.uri)
68-
.filter(statement => o.uri === statement.o.uri)
69-
.filter(statement => g.uri === statement.g.uri)
70-
.map(statement => statement.p)
71-
}
72-
if (o === undefined) {
73-
return this.mockStatements
74-
.filter(statement => s.uri === statement.s.uri)
75-
.filter(statement => p.uri === statement.p.uri)
76-
.filter(statement => g.uri === statement.g.uri)
77-
.map(statement => statement.o)
78-
}
79-
if (g === undefined) {
80-
return this.mockStatements
81-
.filter(statement => s.uri === statement.s.uri)
82-
.filter(statement => p.uri === statement.p.uri)
83-
.filter(statement => o.uri === statement.o.uri)
84-
.map(statement => statement.g)
85-
}
86-
}
87-
match () {
88-
return []
89-
}
90-
query () {
91-
return []
92-
}
93-
findTypeURIs () {
94-
return []
95-
}
96-
findSuperClassesNT () {
97-
return []
98-
}
99-
bottomTypeURIs () {
100-
return []
101-
}
102-
statementsMatching () {
103-
return []
104-
}
105-
sym () {
106-
return sym()
107-
}
51+
export function fetcher (store: any) {
52+
const fetcher = new Fetcher()
53+
store.fetcher = fetcher
54+
return fetcher
10855
}
10956

110-
export function fetcher() {
111-
return new Fetcher()
112-
}
11357
export class Fetcher {
11458
requested: any
115-
constructor() {
59+
60+
constructor () {
11661
this.requested = {}
11762
}
63+
11864
load () {
11965
}
66+
12067
nowOrWhenFetched () {
12168
return Promise.resolve()
12269
}
12370
}
124-
export function namedNode(str: string) {
125-
return {
126-
uri: str
127-
}
128-
}
129-
export function NamedNode() {
130-
}
131-
export function Namespace() {
132-
return () => {}
133-
}
71+
13472
export class UpdateManager {
135-
editable() {}
136-
update() {}
73+
// mock as needed
74+
75+
editable () {
76+
return Promise.resolve()
77+
}
78+
79+
put () {
80+
return Promise.resolve()
81+
}
82+
83+
update () {
84+
return Promise.resolve()
85+
}
13786
}

test/unit/acl/access-groups.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { instantiateAccessGroups } from '../helpers/instantiateAccessGroups'
44
import { JSDOM } from 'jsdom'
55
import store from '../../../src/store'
66

7-
jest.mock('rdflib')
87
jest.mock('solid-auth-client')
98
const dom = new JSDOM('<!DOCTYPE html><p>Hello world</p>').window.document
109

test/unit/acl/acl-control.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
shortNameForFolder
88
} from '../../../src/acl/acl-control'
99

10-
jest.mock('rdflib')
1110
jest.mock('solid-auth-client')
1211
const window = new JSDOM('<!DOCTYPE html><p>Hello world</p>').window
1312
const dom = window.document
@@ -18,7 +17,7 @@ describe('ACLControlBox5', () => {
1817
})
1918
it.skip('runs', () => {
2019
expect(ACLControlBox5(
21-
sym(''),
20+
sym('https://test.test'),
2221
{ dom } as DataBrowserContext,
2322
{} as any,
2423
graph())).toBeInstanceOf(HTMLElement)
@@ -39,7 +38,7 @@ describe('shortNameForFolder', () => {
3938
expect(shortNameForFolder).toBeInstanceOf(Function)
4039
})
4140
it('runs', () => {
42-
expect(shortNameForFolder(sym(''))).toEqual('uri')
41+
expect(shortNameForFolder(sym('https://test.test/uri'))).toEqual('uri')
4342
})
4443
it('works with trailing slashes', () => {
4544
expect(shortNameForFolder(namedNode('http://example.com/some/folder/'))).toEqual('folder')

0 commit comments

Comments
 (0)