Skip to content
1 change: 1 addition & 0 deletions lib/domain/dtos/filters/LhcFillsFilterDto.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ exports.LhcFillsFilterDto = Joi.object({
runDuration: validateTimeDuration,
beamDuration: validateTimeDuration,
beamsType: Joi.string(),
schemeName: Joi.string().trim(),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE Trg. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-Trg.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

import { rawTextFilter } from '../common/filters/rawTextFilter.js';

/**
* Component to filter LHC-fills by scheme name
*
* @param {RawTextFilterModel} filterModel the filter model
* @returns {Component} the text field
*/
export const schemeNameFilter = (filterModel) => rawTextFilter(
filterModel,
{ classes: ['w-100'], placeholder: 'e.g. Single_12b_8_1024_8_2018' },
);
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { toggleStableBeamOnlyFilter } from '../../../components/Filters/LhcFills
import { fillNumberFilter } from '../../../components/Filters/LhcFillsFilter/fillNumberFilter.js';
import { durationFilter } from '../../../components/Filters/LhcFillsFilter/durationFilter.js';
import { beamsTypeFilter } from '../../../components/Filters/LhcFillsFilter/beamsTypeFilter.js';
import { schemeNameFilter } from '../../../components/Filters/LhcFillsFilter/schemeNameFilter.js';

/**
* List of active columns for a lhc fills table
Expand Down Expand Up @@ -175,6 +176,7 @@ export const lhcFillsActiveColumns = {
visible: true,
size: 'w-10',
format: (value) => value ? value : '-',
filter: (lhcFillModel) => schemeNameFilter(lhcFillModel.filteringModel.get('schemeName')),
balloon: true,
},
runs: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class LhcFillsOverviewModel extends OverviewPageModel {
runDuration: new TextComparisonFilterModel(),
hasStableBeams: new StableBeamFilterModel(),
beamsType: new BeamsTypeFilterModel(),
schemeName: new RawTextFilterModel(),
});

this._filteringModel.observe(() => this._applyFilters());
Expand Down
7 changes: 6 additions & 1 deletion lib/usecases/lhcFill/GetAllLhcFillsUseCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class GetAllLhcFillsUseCase {
let associatedStatisticsRequired = false;

if (filter) {
const { hasStableBeams, fillNumbers, beamDuration, runDuration, beamsType } = filter;
const { hasStableBeams, fillNumbers, schemeName, beamDuration, runDuration, beamsType } = filter;
if (hasStableBeams) {
// For now, if a stableBeamsStart is present, then a beam is stable
queryBuilder.where('stableBeamsStart').not().is(null);
Expand All @@ -65,6 +65,11 @@ class GetAllLhcFillsUseCase {
}
}

// Scheme name filter
if (schemeName) {
queryBuilder.where('filling_scheme_name').substring(schemeName);
}

// Run duration filter and corresponding operator.
if (runDuration?.limit !== undefined && runDuration?.operator) {
associatedStatisticsRequired = true;
Expand Down
50 changes: 50 additions & 0 deletions test/api/lhcFills.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,56 @@ module.exports = () => {
done();
});
});

it('should return 200 and an LHCFill array for scheme name filter, full', (done) => {
request(server)
.get('/api/lhcFills?page[offset]=0&page[limit]=15&filter[schemeName]=Single_12b_8_1024_8_2018')
.expect(200)
.end((err, res) => {
if (err) {
done(err);
return;
}

expect(res.body.data).to.have.lengthOf(1);
expect(res.body.data[0].fillNumber).to.equal(6);

done();
});
});

it('should return 200 and an LHCFill array for scheme name filter, partial', (done) => {
request(server)
.get('/api/lhcFills?page[offset]=0&page[limit]=15&filter[schemeName]=_1')
.expect(200)
.end((err, res) => {
if (err) {
done(err);
return;
}

expect(res.body.data).to.have.lengthOf(2);
expect(res.body.data[0].fillNumber).to.equal(6);

done();
});
});

it('should return 400 for scheme name filter, empty filter', (done) => {
request(server)
.get('/api/lhcFills?page[offset]=0&page[limit]=15&filter[schemeName]=')
.expect(400)
.end((err, res) => {
if (err) {
done(err);
return;
}

expect(res.body.errors[0].title).to.equal('Invalid Attribute');

done();
});
});
});
describe('POST /api/lhcFills', () => {
it('should return 201 if valid data is provided', async () => {
Expand Down
24 changes: 24 additions & 0 deletions test/lib/usecases/lhcFill/GetAllLhcFillsUseCase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,30 @@ module.exports = () => {
});
})

it('should only contain matching scheme name, one precise', async () => {
getAllLhcFillsDto.query = { filter: { hasStableBeams: true, schemeName: 'schemename' } };
const { lhcFills } = await new GetAllLhcFillsUseCase().execute(getAllLhcFillsDto);


expect(lhcFills).to.be.an('array').and.lengthOf(3)

lhcFills.forEach((lhcFill) => {
expect(lhcFill.fillingSchemeName).to.equal('schemename')
});
})

it('should only contain matching scheme name, one partial', async () => {
getAllLhcFillsDto.query = { filter: { schemeName: '25ns_2352b_2340_2004_2133' } };
const { lhcFills } = await new GetAllLhcFillsUseCase().execute(getAllLhcFillsDto);


expect(lhcFills).to.be.an('array').and.lengthOf(1)

lhcFills.forEach((lhcFill) => {
expect(lhcFill.fillingSchemeName).to.equal('25ns_2352b_2340_2004_2133_108bpi_24inj')
});
})

// Beam duration filter tests
it('should only contain specified stable beam durations, < 12:00:00', async () => {
getAllLhcFillsDto.query = { filter: { beamDuration: {limit: '43200', operator: '<'} } };
Expand Down
15 changes: 14 additions & 1 deletion test/public/lhcFills/overview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ module.exports = () => {
const meanRunDurationExpect = { selector: 'tbody tr:nth-child(1) td:nth-child(6)', value: '01:40:00' };
const totalRunsDurationExpect = { selector: 'tbody tr:nth-child(1) td:nth-child(7)', value: '05:00:00' };
const efficiencyExpect = { selector: 'tbody tr:nth-child(1) td:nth-child(8)', value: '41.67%' };
const schemeNameExpect = { selector: '#row6-fillingSchemeName > div:nth-child(1) > div:nth-child(1)', value: 'Single_12b_8_1024_8_2018'};

await goToPage(page, 'lhc-fill-overview');

Expand All @@ -265,6 +266,7 @@ module.exports = () => {
await expectInnerText(page, meanRunDurationExpect.selector, meanRunDurationExpect.value);
await expectInnerText(page, totalRunsDurationExpect.selector, totalRunsDurationExpect.value);
await expectInnerText(page, efficiencyExpect.selector, efficiencyExpect.value);
await expectInnerText(page, schemeNameExpect.selector, schemeNameExpect.value);
});

it('should successfully display filter elements', async () => {
Expand All @@ -276,7 +278,7 @@ module.exports = () => {
const filterRunDurationPlaceholderExpect = {selector: '#run-duration-filter-operand', value: 'e.g 16:14:15 (HH:MM:SS)'};
const filterSBDurationOperatorExpect = { value: true };
const filterBeamTypeExpect = {selector: 'div.flex-row:nth-child(5) > div:nth-child(1)', value: 'Beam Type'}

const filterSchemeNamePlaceholderExpect = {selector: '.fillingSchemeName-filter input', value: 'e.g. Single_12b_8_1024_8_2018'}

await goToPage(page, 'lhc-fill-overview');
// Open the filtering panel
Expand All @@ -290,6 +292,7 @@ module.exports = () => {
await expectInnerText(page, filterRunDurationExpect.selector, filterRunDurationExpect.value);
await expectAttributeValue(page, filterRunDurationPlaceholderExpect.selector, 'placeholder', filterRunDurationPlaceholderExpect.value);
await expectInnerText(page, filterBeamTypeExpect.selector, filterBeamTypeExpect.value);
await expectAttributeValue(page, filterSchemeNamePlaceholderExpect.selector, 'placeholder', filterSchemeNamePlaceholderExpect.value);
});

it('should successfully un-apply Stable Beam filter menu', async () => {
Expand Down Expand Up @@ -347,4 +350,14 @@ module.exports = () => {
await pressElement(page, filterBeamTypePb_Pb);
await waitForTableLength(page, 2);
});

it('should successfully apply scheme name filter', async () => {
const filterSchemeNameInputField= '.fillingSchemeName-filter input';
await goToPage(page, 'lhc-fill-overview');
await waitForTableLength(page, 5);
// Open the filtering panel
await openFilteringPanel(page);
await fillInput(page, filterSchemeNameInputField, 'Single_12b_8_1024_8_2018', ['change']);
await waitForTableLength(page, 1);
});
};
Loading