Skip to content

Commit

Permalink
fix: always include MinimumFieldsToInclude
Browse files Browse the repository at this point in the history
  • Loading branch information
y-lakhdar committed Jun 27, 2024
1 parent 0b046a3 commit 718b879
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ui/Base/QueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ export class QueryBuilder {

public computeFieldsToInclude() {
if (this.includeRequiredFields || this.fieldsToInclude != null) {
return this.requiredFields.concat(this.fieldsToInclude || []);
return _.uniq(this.requiredFields.concat(this.fieldsToInclude || []));
} else {
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion src/ui/ResultList/ResultList.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'styling/_Result';
import 'styling/_ResultFrame';
import 'styling/_ResultList';
import { chain, compact, contains, each, flatten, map, unique, without, uniqueId, find } from 'underscore';
import { compact, contains, each, flatten, map, without, uniqueId, find, unique, chain } from 'underscore';
import {
IBuildingQueryEventArgs,
IDuringQueryEventArgs,
Expand Down Expand Up @@ -668,6 +668,7 @@ export class ResultList extends Component {
}

protected handleBuildingQuery(args: IBuildingQueryEventArgs) {
args.queryBuilder.addFieldsToInclude(this.getMinimalFieldsToInclude());
if (this.options.fieldsToInclude != null) {
// remove the @
args.queryBuilder.addFieldsToInclude(map(this.options.fieldsToInclude, field => field.substr(1)));
Expand Down
21 changes: 21 additions & 0 deletions unitTests/ui/ResultListTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,17 @@ export function ResultListTest() {
);
});

it('should also get the minimal amount of fields to include when the option is false', () => {
test = Mock.optionsComponentSetup<ResultList, IResultListOptions>(ResultList, {
autoSelectFieldsToInclude: false
});

const simulation = Simulate.query(test.env);
expect(simulation.queryBuilder.build().fieldsToInclude).toEqual(
jasmine.arrayContaining(['author', 'language', 'urihash', 'objecttype', 'collection', 'source', 'language', 'permanentid'])
);
});

it('should allow to get the auto select fields to include', () => {
expect(test.cmp.getAutoSelectedFieldsToInclude()).toEqual(
jasmine.arrayContaining(['author', 'language', 'urihash', 'objecttype', 'collection', 'source', 'language', 'permanentid'])
Expand Down Expand Up @@ -692,6 +703,16 @@ export function ResultListTest() {
expect(simulation.queryBuilder.fieldsToInclude).toContain('field3');
});

it('fieldsToInclude should always include minimal amount of required fields', () => {
test = Mock.optionsComponentSetup<ResultList, IResultListOptions>(ResultList, {
fieldsToInclude: ['@field1', '@field2', '@field3']
});
const simulation = Simulate.query(test.env);
expect(simulation.queryBuilder.fieldsToInclude).toEqual(
jasmine.arrayContaining(['author', 'language', 'urihash', 'objecttype', 'collection', 'source', 'language', 'permanentid'])
);
});

describe('layout', () => {
it('should correctly listen to populateResultLayout', () => {
test = Mock.optionsComponentSetup<ResultList, IResultListOptions>(ResultList, {
Expand Down

0 comments on commit 718b879

Please sign in to comment.