Skip to content

Commit

Permalink
Address frontend comments
Browse files Browse the repository at this point in the history
  • Loading branch information
EMaksy committed Jul 29, 2024
1 parent 3e00f5a commit a78c9f4
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 81 deletions.
3 changes: 1 addition & 2 deletions assets/js/lib/test-utils/factories/sapSystems.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const roles = () =>
'GATEWAY',
'ICMAN',
'IGS',
'J2EE',
]);

export const sapSystemApplicationInstanceFactory = Factory.define(() => ({
Expand All @@ -36,12 +37,10 @@ export const sapSystemFactory = Factory.define(({ params }) => {
const sid = params.sid || generateSid();
const databaseId = params.database_id || faker.string.uuid();
const databaseSid = params.database_sid || generateSid();
const sapSystemType = params.sap_system_type || 'ABAP';
return {
application_instances: sapSystemApplicationInstanceFactory.buildList(2, {
sap_system_id: id,
sid,
features: sapSystemType,
}),
database_instances: databaseInstanceFactory.buildList(2, {
database_id: databaseId,
Expand Down
32 changes: 13 additions & 19 deletions assets/js/pages/SapSystemsOverviewPage/SapSystemsOverview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,18 @@ function SapSystemsOverview({
},
{
title: 'Type',
key: 'applicationInstances',
render: (content) => {
const instanceTypes = uniq(
flatMap(content, (instance) => instance.features.split('|'))
key: 'type',
render: (_, items) =>
uniq(
flatMap(
filter(items.applicationInstances, { sap_system_id: items.id }),
({ features }) => features.split('|')
)
)
.filter((item) => item === 'J2EE' || item === 'ABAP')
.map((item) => (item === 'J2EE' ? 'JAVA' : item));
// Join the results in a fixed order ABAP, JAVA, ABAP/JAVA or ''
const sapSystemType = ['ABAP', 'JAVA']
.filter((type) => instanceTypes.includes(type))
.join('/');

return sapSystemType;
},
.map((item) => (item === 'J2EE' ? 'JAVA' : item))
.toSorted()
.join('/'),
},

{
Expand Down Expand Up @@ -138,21 +136,17 @@ function SapSystemsOverview({
),
};

const filteredApplicationInstances = (sapSystem) =>
filter(applicationInstances, {
sap_system_id: sapSystem.id,
});

const data = sapSystems.map((sapSystem) => ({
id: sapSystem.id,
health: sapSystem.health,
sid: sapSystem.sid,
attachedRdbms: sapSystem.database_sid,
tenant: sapSystem.tenant,
type: filteredApplicationInstances(sapSystem),
dbAddress: sapSystem.db_host,
ensaVersion: sapSystem.ensa_version || '-',
applicationInstances: filteredApplicationInstances(sapSystem),
applicationInstances: filter(applicationInstances, {
sap_system_id: sapSystem.id,
}),
databaseInstances: filter(databaseInstances, {
database_id: sapSystem.database_id,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,24 @@ const enrichedAbsentDatabaseInstances = enrichInstances(
'database_instances'
);

const sapSystemsWithDifferentTypes = [
sapSystemFactory.build({ sap_system_type: 'J2EE' }),
sapSystemFactory.build({ sap_system_type: 'ABAP' }),
sapSystemFactory.build({ sap_system_type: 'ABAP|J2EE' }),
sapSystemFactory.build({ sap_system_type: 'ABAP|J2EE|SAP_APP' }),
sapSystemFactory.build({ sap_system_type: 'J2EE|ABAP|SAP_APP' }),
sapSystemFactory.build({
sap_system_type: 'NOT_ABAP|NOT_JAVA|JAVA|NOT_J2EE|NOT_A_REAL_SAP_SYSTEM',
}),
const sapSystemTypes = [
'ABAP',
'J2EE',
'ABAP|J2EE',
'J2EE|ABAP',
'SOME_SAP_SYSTEM_FEATURE|NOT_A_REAL_SYSTEM',
];

const sapSystemsWithDifferentTypes = sapSystemFactory
.buildList(5)
.map((sapSystem, index) => ({
...sapSystem,
application_instances: sapSystem.application_instances.map((instance) => ({
...instance,
features: sapSystemTypes[index],
})),
}));

const enrichedApplicationInstancesType = enrichInstances(
sapSystemsWithDifferentTypes,
'application_instances'
Expand Down
82 changes: 31 additions & 51 deletions assets/js/pages/SapSystemsOverviewPage/SapSystemsOverview.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ describe('SapSystemsOverviews component', () => {
});

it('should display the correct content for a SAP system main row', () => {
const sapSystemType = 'ABAP';
const sapSystem = sapSystemFactory.build({
ensa_version: 'ensa1',
sap_system_type: sapSystemType,
});
const {
id: sapSystemID,
Expand All @@ -57,11 +55,19 @@ describe('SapSystemsOverviews component', () => {
database_sid: attachedRdbms,
} = sapSystem;

const sapSystemType = 'ABAP';
const modifiedApplicationInstances = applicationInstances.map(
(instance) => ({
...instance,
features: sapSystemType,
})
);

renderWithRouter(
<SapSystemsOverview
sapSystems={[sapSystem]}
userAbilities={userAbilities}
applicationInstances={applicationInstances}
applicationInstances={modifiedApplicationInstances}
databaseInstances={databaseInstances}
/>
);
Expand Down Expand Up @@ -110,31 +116,22 @@ describe('SapSystemsOverviews component', () => {
'ABAP/JAVA',
'',
];
const sapSystems = [
sapSystemFactory.build({
sap_system_type: sapSystemTypes[0],
}),
sapSystemFactory.build({
sap_system_type: sapSystemTypes[1],
}),
sapSystemFactory.build({
sap_system_type: sapSystemTypes[2],
}),
sapSystemFactory.build({
sap_system_type: sapSystemTypes[3],
}),
sapSystemFactory.build({
sap_system_type: sapSystemTypes[4],
}),
];

const sapSystemApplicationInstances = [
sapSystems[0].application_instances,
sapSystems[1].application_instances,
sapSystems[2].application_instances,
sapSystems[3].application_instances,
sapSystems[4].application_instances,
].flat();
const sapSystems = sapSystemFactory.buildList(5);

const updatedSapSystems = sapSystems.map((sapSystem, index) => ({
...sapSystem,
application_instances: sapSystem.application_instances.map(
(instance) => ({
...instance,
features: sapSystemTypes[index],
})
),
}));

const sapSystemApplicationInstances = updatedSapSystems
.map((sapSystem) => sapSystem.application_instances)
.flat();

renderWithRouter(
<SapSystemsOverview
Expand All @@ -145,30 +142,13 @@ describe('SapSystemsOverviews component', () => {
/>
);
const rows = screen.getByRole('table').querySelectorAll('tbody > tr');
const firstSapSystem = rows[0];
const secondSapSystem = rows[2];
const thirdSapSystem = rows[4];
const fourthSapSystem = rows[6];
const fifthSapSystem = rows[8];

expect(firstSapSystem.querySelector('td:nth-child(5)')).toHaveTextContent(
expectedSapSystemTypes[0]
);
expect(
secondSapSystem.querySelector('td:nth-child(5)')
).toHaveTextContent(expectedSapSystemTypes[1]);

expect(thirdSapSystem.querySelector('td:nth-child(5)')).toHaveTextContent(
expectedSapSystemTypes[2]
);

expect(
fourthSapSystem.querySelector('td:nth-child(5)')
).toHaveTextContent(expectedSapSystemTypes[3]);

expect(fifthSapSystem.querySelector('td:nth-child(5)')).toHaveTextContent(
expectedSapSystemTypes[4]
);
expectedSapSystemTypes.forEach((expectedType, index) => {
const rowIndex = index * 2;
const sapSystemRow = rows[rowIndex];
expect(sapSystemRow.querySelector('td:nth-child(5)')).toHaveTextContent(
expectedType
);
});
});

it('should display the correct content for a SAP system instances', () => {
Expand Down

0 comments on commit a78c9f4

Please sign in to comment.