|
| 1 | +/* Test the language handling |
| 2 | +*/ |
| 3 | + |
| 4 | +import { getFileContent } from '../../../helpers/getFileContent' |
| 5 | +// Note different helpers directory: |
| 6 | +// import { silenceDebugMessages } from '../../../../helpers/setup' |
| 7 | +import { parse } from 'rdflib' |
| 8 | +import { |
| 9 | + autocompleteField |
| 10 | +} from '../../../../../src/widgets/forms/autocomplete/autocompleteField' |
| 11 | +import { |
| 12 | + languageCodeURIBase, |
| 13 | + defaultPreferedLangages, |
| 14 | + getPreferredLanagugesFor, |
| 15 | + getPreferredLanguages, |
| 16 | + filterByLanguage |
| 17 | +} from '../../../../../src/widgets/forms/autocomplete/language' |
| 18 | +import { store, ns } from '../../../../../src/' |
| 19 | +// import { textInputStyle } from '../../../../../src/style' |
| 20 | +import { |
| 21 | +// findByAltText, |
| 22 | + findByTestId, |
| 23 | + // getByAltText, |
| 24 | + // queryByAltText, |
| 25 | + waitFor |
| 26 | +} from '@testing-library/dom' |
| 27 | +import nock from 'nock' |
| 28 | + |
| 29 | +// jest.unmock('rdflib') // we need Fetcher to work (mocked) |
| 30 | +jest.unmock('debug') // while debugging only @@ |
| 31 | +jest.mock('solid-auth-client', () => ({ |
| 32 | + currentSession: () => Promise.resolve(), |
| 33 | + trackSession: () => null |
| 34 | +})) |
| 35 | + |
| 36 | +const prefixes = `@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. |
| 37 | +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. |
| 38 | +@prefix foaf: <http://xmlns.com/foaf/0.1/>. |
| 39 | +@prefix lang: <${languageCodeURIBase}>. |
| 40 | +@prefix owl: <http://www.w3.org/2002/07/owl#>. |
| 41 | +@prefix solid: <http://www.w3.org/ns/solid/terms#>. |
| 42 | +@prefix ui: <http://www.w3.org/ns/ui#>. |
| 43 | +@prefix schema: <http://schema.org/>. |
| 44 | +@prefix vcard: <http://www.w3.org/2006/vcard/ns#>. |
| 45 | +
|
| 46 | +@prefix org: <http://www.w3.org/ns/org#>. |
| 47 | +@prefix esco: <http://data.europa.eu/esco/model#>. |
| 48 | +@prefix wd: <http://www.wikidata.org/entity/>. |
| 49 | +@prefix wdt: <http://www.wikidata.org/prop/direct/>. |
| 50 | +
|
| 51 | +@prefix : <#>. |
| 52 | +` |
| 53 | +const alice = store.sym('https://alice.example.com/profile#me') |
| 54 | +const aliceProfileText = prefixes + ` |
| 55 | + <#me> a foaf:Person; schema:knowsLanguage ( [ solid:publicId lang:el ] ) . # Just greek |
| 56 | +` |
| 57 | +parse(aliceProfileText, store, alice.doc().uri) |
| 58 | + |
| 59 | +const bob = store.sym('https://bob.example.com/profile#me') |
| 60 | +const bobProfileText = prefixes + ` |
| 61 | + <#me> a foaf:Person; schema:knowsLanguage ( [ solid:publicId lang:en] [ solid:publicId lang:fr] ) . # Just english and french |
| 62 | +` |
| 63 | +/* |
| 64 | +const charlieProfileText = prefixes + ` |
| 65 | + <#me> a foaf:Person . # Nothing stated about languages |
| 66 | +` |
| 67 | +*/ |
| 68 | +const kb = store |
| 69 | + |
| 70 | +describe('getPreferredLanagugesFor', () => { |
| 71 | + let result |
| 72 | + beforeEach(() => { |
| 73 | + // fetch.resetMocks(); |
| 74 | + }) |
| 75 | + |
| 76 | + it('exists as a function', () => { |
| 77 | + expect(getPreferredLanagugesFor).toBeInstanceOf(Function) |
| 78 | + }) |
| 79 | + it('returns just greek for Alice, plus deafults', async () => { |
| 80 | + expect(getPreferredLanagugesFor).toBeInstanceOf(Function) |
| 81 | + |
| 82 | + result = await getPreferredLanagugesFor(alice) |
| 83 | + |
| 84 | + expect(result).toEqual(['el']) // toMatchSnapshot() |
| 85 | + }) |
| 86 | +}) |
| 87 | +// |
0 commit comments