Skip to content

Commit

Permalink
Test Dropdown predicate construction as well (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgonggrijp committed May 11, 2021
1 parent e6f91b9 commit 5967c68
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions frontend/src/semantic-search/dropdown-view-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { constant } from 'lodash';
import { constant, each } from 'lodash';

import { enableI18n, startStore, endStore, event } from '../test-util';
import mockOntology from '../mock-data/mock-ontology';
Expand Down Expand Up @@ -37,21 +37,26 @@ describe('semantic search DropdownView', function() {
expect(view.$('optgroup:nth-child(2)').text()).not.toContain('Person');
});

it('can be constructed with a single class', async function() {
const model = new Model({
precedent: ldChannel.request('obtain', readit('Reader')),
});
const view = new Dropdown({ model });
await event(view.predicateGroup.collection.at(0), 'change:classLabel');
expect(view.$('select optgroup').length).toBe(3);
expect(view.$('optgroup:first-child').prop('label')).toBe('apply logic');
expect(view.$('optgroup:first-child option').length).toBe(3);
expect(view.$('optgroup:nth-child(2)').prop('label')).toBe('apply filter');
expect(view.$('optgroup:nth-child(2) option').length).toBe(2);
expect(view.$('optgroup:nth-child(2)').text()).toContain('Is exactly');
expect(view.$('optgroup:nth-child(2)').text()).not.toContain('Is less than');
expect(view.$('optgroup:nth-child(3)').prop('label')).toBe('traverse predicate');
expect(view.$('optgroup:nth-child(3) option').length).toBe(2);
expect(view.$('optgroup:nth-child(3)').text()).toContain('description of');
});
each({
'single class': 'Reader',
'property': 'descriptionOf',
}, (term, label) =>
it(`can be constructed with a ${label}`, async function() {
const model = new Model({
precedent: ldChannel.request('obtain', readit(term)),
});
const view = new Dropdown({ model });
await event(view.predicateGroup.collection.at(0), 'change:classLabel');
expect(view.$('select optgroup').length).toBe(3);
expect(view.$('optgroup:first-child').prop('label')).toBe('apply logic');
expect(view.$('optgroup:first-child option').length).toBe(3);
expect(view.$('optgroup:nth-child(2)').prop('label')).toBe('apply filter');
expect(view.$('optgroup:nth-child(2) option').length).toBe(2);
expect(view.$('optgroup:nth-child(2)').text()).toContain('Is exactly');
expect(view.$('optgroup:nth-child(2)').text()).not.toContain('Is less than');
expect(view.$('optgroup:nth-child(3)').prop('label')).toBe('traverse predicate');
expect(view.$('optgroup:nth-child(3) option').length).toBe(2);
expect(view.$('optgroup:nth-child(3)').text()).toContain('description of');
})
);
});

0 comments on commit 5967c68

Please sign in to comment.