Skip to content

Commit

Permalink
UIEUS-357: Add counter 5.1 for report release (#500)
Browse files Browse the repository at this point in the history
* UIEUS-357-add-counter-5.1-for-reportRelease

* UIEUS-357-add-counter-5.1-for-reportRelease

* UIEUS-357-add-counter-5.1-for-reportRelease

* UIEUS-357-add-counter-5.1-for-reportRelease

* UIEUS-357-add-counter-5.1-for-reportRelease

* UIEUS-357-add-counter-5.1-for-reportRelease

* UIEUS-357-add-counter-5.1-for-reportRelease

---------

Co-authored-by: elsenhans <elsenhans@users.noreply.github.com>
  • Loading branch information
elsenhans and elsenhans authored Oct 7, 2024
1 parent 173c5e9 commit 21d0516
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 185 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Correct heading when confirming deletion of a single counter report ([UIEUS-376](https://folio-org.atlassian.net/browse/UIEUS-376))
* COUNTER statistics: Show the COUNTER release version for reports in an additional column ([UIEUS-368](https://folio-org.atlassian.net/browse/UIEUS-368))
* Leverage `yarn.lock` ([UIEUS-377](https://folio-org.atlassian.net/browse/UIEUS-377))
* COUNTER 5.1 Support: Harvesting configuration for usage data providers ([UIEUS-357](https://folio-org.atlassian.net/browse/UIEUS-357))

## [9.0.0](https://github.com/folio-org/ui-erm-usage/tree/v9.0.0) (2024-04-17)
* *BREAKING* Use `multipart/form-data` to upload COUNTER reports ([UIEUS-353](https://folio-org.atlassian.net/browse/UIEUS-353))
Expand Down
2 changes: 1 addition & 1 deletion src/components/Counter/ReportInfo/ReportInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const ReportInfo = ({
const getFileType = (release) => {
if (release === '4') {
return 'xml';
} else if (release === '5') {
} else if (release === '5' || release === '5.1') {
return 'json';
} else {
return 'unknown';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const HarvestingConfigurationForm = ({
form.mutators.setReportRelease({}, val);
}
if ((val === '4' && values.sushiCredentials?.apiKey) ||
(val === '5' && values.sushiCredentials?.apiKey && values.sushiCredentials?.requestorId)) {
((val === '5' || val === '5.1') && values.sushiCredentials?.apiKey && values.sushiCredentials?.requestorId)) {
form.change('sushiCredentials.apiKey', undefined);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ import { FormattedMessage } from 'react-intl';
import { FieldArray } from 'react-final-form-arrays';
import { Label } from '@folio/stripes/components';
import formCss from '../../../util/sharedStyles/form.css';
import counterReports from './data/counterReports';
import counterReportMapping from './data/counterReports';
import css from './SelectedReportsForm.css';

import SelectReportType from './SelectReportType';
import { requiredArray } from '../../../util/validate';

const getCounterReportsForVersion = (counterVersion) => {
return _.filter(counterReports.getOptions(), [
'counterVersion',
counterVersion,
]);
return _.filter(counterReportMapping, ['counterVersion', counterVersion]);
};

class SelectedReportsForm extends React.Component {
Expand All @@ -27,17 +24,13 @@ class SelectedReportsForm extends React.Component {

constructor(props) {
super(props);
this.counterReports = counterReports.getOptions();
this.counterReportsForVersion = getCounterReportsForVersion(
props.counterVersion
);
this.counterReportsCurrentVersion = this.counterReportsForVersion;

this.counterReportsCurrentVersion = getCounterReportsForVersion(props.counterVersion);
}

componentDidUpdate(prevProps) {
if (this.props.counterVersion !== prevProps.counterVersion) {
const counterReportsForVersion = getCounterReportsForVersion(this.props.counterVersion);
this.counterReportsCurrentVersion = counterReportsForVersion;
this.counterReportsCurrentVersion = getCounterReportsForVersion(this.props.counterVersion);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,171 +1,26 @@

export const data = [
{
name: 'JR1',
code: 'jr1',
counterVersion: '4'
},
{
name: 'JR1 GOA',
code: 'jr1_goa',
counterVersion: '4'
},
{
name: 'JR1a',
code: 'jr1_a',
counterVersion: '4'
},
{
name: 'JR2',
code: 'jr2',
counterVersion: '4'
},
{
name: 'JR3',
code: 'jr3',
counterVersion: '4'
},

{
name: 'JR3 Mobile',
code: 'jr3_mobile',
counterVersion: '4'
},
{
name: 'JR4',
code: 'jr4',
counterVersion: '4'
},
{
name: 'JR5',
code: 'jr5',
counterVersion: '4'
},
{
name: 'DB1',
code: 'db1',
counterVersion: '4'
},
{
name: 'DB2',
code: 'db2',
counterVersion: '4'
},
{
name: 'PR1',
code: 'pr1',
counterVersion: '4'
},
{
name: 'BR1',
code: 'br1',
counterVersion: '4'
},
{
name: 'BR2',
code: 'br2',
counterVersion: '4'
},
{
name: 'BR3',
code: 'br3',
counterVersion: '4'
},
{
name: 'BR4',
code: 'br4',
counterVersion: '4'
},
{
name: 'BR5',
code: 'br5',
counterVersion: '4'
},
{
name: 'BR7',
code: 'br7',
counterVersion: '4'
},
{
name: 'MR1',
code: 'mr1',
counterVersion: '4'
},
{
name: 'MR1 Mobile',
code: 'mr1_mobile',
counterVersion: '4'
},
{
name: 'TR1',
code: 'tr1',
counterVersion: '4'
},
{
name: 'TR2',
code: 'tr2',
counterVersion: '4'
},
{
name: 'TR3',
code: 'tr3',
counterVersion: '4'
},
{
name: 'TR3 Mobile',
code: 'tr3_mobile',
counterVersion: '4'
},
{
name: 'DR',
code: 'dr',
counterVersion: '5'
},
{
name: 'IR',
code: 'ir',
counterVersion: '5'
},
{
name: 'PR',
code: 'pr',
counterVersion: '5'
},
{
name: 'TR',
code: 'tr',
counterVersion: '5'
}
];

const sortReports = (a, b) => {
if (a.label > b.label) {
return 1;
}
if (a.label < b.label) {
return -1;
}
return 0;
const rawCounterReportMapping = {
'4': ['BR1', 'BR2', 'BR3', 'BR4', 'BR5', 'BR7', 'DB1', 'DB2', 'JR1', 'JR1 GOA', 'JR1a', 'JR2', 'JR3', 'JR3 Mobile', 'JR4', 'JR5', 'MR1', 'MR1 Mobile', 'PR1', 'TR1', 'TR2', 'TR3', 'TR3 Mobile'],
'5': ['DR', 'IR', 'PR', 'TR'],
'5.1': ['DR', 'IR', 'PR', 'TR'],
};

const counterReports = {
function generateCounterData() {
const dataArray = [];

selectedOptions: selected => data.map(
r => ({
label: r.name,
value: r.name,
selected: r.name === selected
})
).sort(sortReports),
Object.keys(rawCounterReportMapping).forEach(version => {
const names = rawCounterReportMapping[version];
names.forEach(name => {
dataArray.push({
label: name,
value: name,
counterVersion: version,
});
});
});

getOptions: () => data.map(
r => ({
label: r.name,
value: r.name,
counterVersion: r.counterVersion,
})
).sort(sortReports),
return dataArray;
}

};
const counterReportMapping = generateCounterData();

export default counterReports;
export default counterReportMapping;
33 changes: 27 additions & 6 deletions src/components/views/UDPForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,26 @@ describe('UDPForm', () => {

describe('test report release and selected reports options', () => {
beforeEach(() => {
renderUDPForm(stripes);
renderUDPForm(stripes, {});
});

afterEach(() => {
jest.clearAllMocks();
});

test('should switch between counter 4 and 5 reports', async () => {
expect(screen.getByRole('option', { name: 'Counter 4' })).toBeInTheDocument();
const testSwitchFromCounterRelease4To5 = async (reportRelease) => {
expect(await screen.getByRole('option', { name: 'Counter 4' })).toBeInTheDocument();
await userEvent.selectOptions(screen.getByRole('combobox', { name: /report release/i }), ['Counter 4']);
await userEvent.click(await screen.getByRole('button', { name: /add report type/i }));

const reportTypeButton = screen.getByRole('button', { name: /Report type/ });
const reportTypeButton = await screen.getByRole('button', { name: /Report type/ });
expect(reportTypeButton).toBeInTheDocument();
await userEvent.click(reportTypeButton);

await userEvent.click(await screen.getByRole('option', { name: /BR1/ }));
expect(screen.getByLabelText('BR1')).toBeInTheDocument();

await userEvent.selectOptions(screen.getByRole('combobox', { name: /report release/i }), ['Counter 5']);
await userEvent.selectOptions(screen.getByRole('combobox', { name: /report release/i }), [reportRelease]);
expect(screen.getByRole('heading', { name: 'Clear report selection' })).toBeVisible();

await userEvent.click(await screen.getByRole('button', { name: 'Clear reports' }));
Expand All @@ -162,10 +166,23 @@ describe('UDPForm', () => {
const reportTypeButtonNew = screen.getByRole('button', { name: 'Report type' });
expect(reportTypeButtonNew).toBeInTheDocument();
await userEvent.click(reportTypeButtonNew);
expect(screen.getByRole('option', { name: /DR/ })).toBeInTheDocument();
expect(screen.getByRole('option', { name: /IR/ })).toBeInTheDocument();
expect(screen.getByRole('option', { name: /PR/ })).toBeInTheDocument();
expect(screen.getByRole('option', { name: /TR/ })).toBeInTheDocument();
await userEvent.click(await screen.getByRole('option', { name: /PR/ }));
expect(screen.getByLabelText('PR')).toBeInTheDocument();
expect(screen.queryByRole('option', { name: /BR1/ })).not.toBeInTheDocument();
expect(screen.queryByLabelText('BR1')).not.toBeInTheDocument();
});
};

test('select reportRelease 5', async () => {
await testSwitchFromCounterRelease4To5('Counter 5');
}, 10000);

test('select reportRelease 5.1', async () => {
await testSwitchFromCounterRelease4To5('Counter 5.1');
}, 10000);
});

describe('test harvesting start and end', () => {
Expand Down Expand Up @@ -418,6 +435,10 @@ describe('UDPForm', () => {
testSelectReportRelease('5');
});

test('select reportRelease 5.1', async () => {
testSelectReportRelease('5.1');
});

test('change reqId and apiKey with reportRelease 5 selected', async () => {
renderUDPForm(stripes, { harvestingConfig: { reportRelease: '5' } });
const reqIdBox = screen.getByRole('textbox', { name: 'Requestor ID' });
Expand Down
1 change: 1 addition & 0 deletions src/util/data/reportReleaseOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export default [
{ value: undefined, label: '' },
{ value: '4', label: 'Counter 4' },
{ value: '5', label: 'Counter 5' },
{ value: '5.1', label: 'Counter 5.1' },
];

0 comments on commit 21d0516

Please sign in to comment.