Skip to content

Commit

Permalink
fix: toTreeView should traverse all children
Browse files Browse the repository at this point in the history
  • Loading branch information
mvegter committed Jun 6, 2020
1 parent 7e1cb32 commit 677377b
Show file tree
Hide file tree
Showing 5 changed files with 285 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/presentation/log/toTreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ const toTreeView = (root, children) => {
}

for (const child of obj.children) {
return traverse(child, id);
const parent = traverse(child, id);
if (parent) {
return parent;
}
}

return null;
};

for (const child of children) {
Expand Down
2 changes: 2 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

const DatabaseSuite = require('./database');
const EndToEndSuite = require('./e2e');
const PresentationSuite = require('./presentation');
const PublicSuite = require('./public');
const ServerSuite = require('./server');
const UseCasesSuite = require('./usecases');
Expand All @@ -32,6 +33,7 @@ describe('Bookkeeping', () => {

describe('Unit Suite', () => {
describe('Database', DatabaseSuite);
describe('Presentation', PresentationSuite);
describe('Server', ServerSuite);
describe('Use Cases', UseCasesSuite);
describe('Utilities', UtilitiesSuite);
Expand Down
18 changes: 18 additions & 0 deletions test/presentation/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. 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-o2.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.
*/

const LogSuite = require('./log');

module.exports = () => {
describe('Log', LogSuite);
};
18 changes: 18 additions & 0 deletions test/presentation/log/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. 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-o2.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.
*/

const toTreeViewSuite = require('./toTreeView.test');

module.exports = () => {
describe('toTreeView', toTreeViewSuite);
};
241 changes: 241 additions & 0 deletions test/presentation/log/toTreeView.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. 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-o2.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.
*/

const {
log: {
toTreeView,
},
} = require('../../../lib/presentation');
const chai = require('chai');

const { expect } = chai;

module.exports = () => {
it('should work', () => {
const root = {
id: 1,
authorId: 'John Doe',
title: 'First entry',
creationTime: 1591219115000,
tags: [
{
id: 3,
text: 'MAINTENANCE',
},
],
text: 'Power interruption due to unplugged wire.',
origin: 'human',
subtype: 'run',
rootLogId: 1,
parentLogId: 1,
};

const children = [
{
id: 2,
authorId: 'John Doe',
title: 'Second entry',
creationTime: 1591219115000,
tags: [
{
id: 2,
text: 'RUN',
},
{
id: 5,
text: 'TEST',
},
],
text: 'Detected particle ABC123',
origin: 'process',
subtype: 'subsystem',
rootLogId: 1,
parentLogId: 1,
},
{
id: 3,
authorId: 'John Doe',
title: 'Third entry',
creationTime: 1591219115000,
tags: [
{
id: 1,
text: 'FOOD',
},
{
id: 4,
text: 'GLOBAL',
},
{
id: 6,
text: 'OTHER',
},
],
text: 'Cake at the particle accelerator!',
origin: 'human',
subtype: 'announcement',
rootLogId: 1,
parentLogId: 1,
},
{
id: 4,
authorId: 'John Doe',
title: 'Fourth entry',
creationTime: 1591219115000,
tags: [],
text: 'The cake is a lie!',
origin: 'human',
subtype: 'comment',
rootLogId: 1,
parentLogId: 2,
},
{
id: 14,
authorId: 'John Doe',
title: 'test on third',
creationTime: 1591446994000,
tags: [],
text: 'text',
origin: 'process',
subtype: 'run',
rootLogId: 1,
parentLogId: 3,
},
{
id: 15,
authorId: 'John Doe',
title: 'depth',
creationTime: 1591450185000,
tags: [],
text: '4444',
origin: 'process',
subtype: 'run',
rootLogId: 1,
parentLogId: 14,
},
];

expect(toTreeView(root, children)).to.deep.equal([
{
id: 1,
authorId: 'John Doe',
title: 'First entry',
creationTime: 1591219115000,
tags: [
{
id: 3,
text: 'MAINTENANCE',
},
],
text: 'Power interruption due to unplugged wire.',
origin: 'human',
subtype: 'run',
rootLogId: 1,
parentLogId: 1,
children: [
{
id: 2,
authorId: 'John Doe',
title: 'Second entry',
creationTime: 1591219115000,
tags: [
{
id: 2,
text: 'RUN',
},
{
id: 5,
text: 'TEST',
},
],
text: 'Detected particle ABC123',
origin: 'process',
subtype: 'subsystem',
rootLogId: 1,
parentLogId: 1,
children: [
{
id: 4,
authorId: 'John Doe',
title: 'Fourth entry',
creationTime: 1591219115000,
tags: [],
text: 'The cake is a lie!',
origin: 'human',
subtype: 'comment',
rootLogId: 1,
parentLogId: 2,
children: [],
},
],
},
{
id: 3,
authorId: 'John Doe',
title: 'Third entry',
creationTime: 1591219115000,
tags: [
{
id: 1,
text: 'FOOD',
},
{
id: 4,
text: 'GLOBAL',
},
{
id: 6,
text: 'OTHER',
},
],
text: 'Cake at the particle accelerator!',
origin: 'human',
subtype: 'announcement',
rootLogId: 1,
parentLogId: 1,
children: [
{
id: 14,
authorId: 'John Doe',
title: 'test on third',
creationTime: 1591446994000,
tags: [],
text: 'text',
origin: 'process',
subtype: 'run',
rootLogId: 1,
parentLogId: 3,
children: [
{
id: 15,
authorId: 'John Doe',
title: 'depth',
creationTime: 1591450185000,
tags: [],
text: '4444',
origin: 'process',
subtype: 'run',
rootLogId: 1,
parentLogId: 14,
children: [],
},
],
},
],
},
],
},
]);
});
};

0 comments on commit 677377b

Please sign in to comment.