Skip to content

Commit e5dd602

Browse files
committed
test for filter by langaugae
1 parent d53e7f4 commit e5dd602

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

test/unit/widgets/forms/autocomplete/language.test.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ jest.mock('solid-auth-client', () => ({
3333
trackSession: () => null
3434
}))
3535

36+
const kb = store
37+
3638
const prefixes = `@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
3739
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
3840
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@@ -68,7 +70,13 @@ const charlieProfileText = prefixes + `
6870
<#me> a foaf:Person . # Nothing stated about languages`
6971
parse(charlieProfileText, store, charlie.doc().uri)
7072

71-
const kb = store
73+
// const kb = store
74+
const elephants = [
75+
{ subject: kb.sym('https://www.wikidata.org/wiki/Q7378'), name: kb.literal('Elefant', 'de') },
76+
{ subject: kb.sym('https://www.wikidata.org/wiki/Q7378'), name: kb.literal('elephant', 'en') },
77+
{ subject: kb.sym('https://www.wikidata.org/wiki/Q7378'), name: kb.literal('elefante', 'it') },
78+
{ subject: kb.sym('https://www.wikidata.org/wiki/Q7378'), name: kb.literal('éléphant', 'fr') }
79+
]
7280

7381
describe('defaultPreferedLangages', () => {
7482
it('exists as a array', () => {
@@ -91,9 +99,21 @@ describe('getPreferredLanagugesFor', () => {
9199
const result = await getPreferredLanagugesFor(bob)
92100
expect(result).toEqual(['en', 'fr', 'de', 'it', 'ar'])
93101
})
94-
it('returns nothing for Charlie, plus deafults', async () => {
102+
it('returns nothing for Charlie, just deafults', async () => {
95103
const result = await getPreferredLanagugesFor(charlie)
96104
expect(result).toEqual(expectedDefaults)
97105
})
98106
})
99-
//
107+
108+
describe('filterByLanguage', () => {
109+
it('exists as a function', () => {
110+
expect(filterByLanguage).toBeInstanceOf(Function)
111+
})
112+
113+
it('filters according to the precendence of the language preferences', async () => {
114+
const result = filterByLanguage(elephants, defaultPreferedLangages)
115+
const names = result.map(binding => binding.name.value)
116+
expect(names).toEqual(['elephant'])
117+
})
118+
})
119+
// ends

0 commit comments

Comments
 (0)