Skip to content

Commit

Permalink
[OGUI-1561] Add a test setup for the FE tests using NodeJS Test Runne…
Browse files Browse the repository at this point in the history
…r test dependency model (#2636)

* makes use of the test and subtests functionality of NodeJS to make sure tests from other files wait for the `before` hook to finish starting and setting up the test server and browser.
* remove `index` file containing page tests as these will be declared all in `test-index` once migrated to improve maintainability and following which tests are being executed. 
* adds an initial page setup test suite for FE
* updates the test configuration file to be up to date with current expected one.
  • Loading branch information
graduta authored Oct 24, 2024
1 parent 1038f9f commit 33125f7
Show file tree
Hide file tree
Showing 7 changed files with 529 additions and 400 deletions.
29 changes: 9 additions & 20 deletions QualityControl/test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,19 @@
export const config = {
demoData: true,
http: {
port: 8181,
port: 8080,
hostname: 'localhost',
tls: false,
},
mysql: {
host: 'aaaa',
user: 'aaaa',
password: 'aaaa',
database: 'quality_control',
},
tobject2json: {
host: 'localhost',
port: 7777,
},
consul: {
hostname: 'localhost',
port: 8500,
},
ccdb: {
hostname: 'ccdb',
port: 8500,
prefix: 'test',
protocol: 'http',
hostname: 'localhost',
port: 8081,
prefix: 'qc/test',
cachePrefix: 'qc/test',
cacheRefreshRate: 120 * 1000,
},
quality_control: {
version: '0.19.5-1',
qc: {
enabled: false,
},
};
288 changes: 288 additions & 0 deletions QualityControl/test/public/components/qcDrawingOptions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
/**
* @license
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
* All rights not expressly granted are reserved.
*
* This software is distributed under the terms of the GNU General Public
* License v3 (GPL Version 3), copied verbatim in the file 'COPYING'.
*
* 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 assert from 'node:assert';

/**
* Initial page setup tests
* @param {string} url - URL needed to open page for testing
* @param {object} page - Puppeteer page object
* @param {number} timeout - Timeout PER individual test; default 1000
* @param {object} testParent - Node.js test object
*/
export const qcDrawingOptionsTests = async (url, page, timeout = 1000, testParent) => {
await testParent.test('should load', { timeout }, async () => {
// Id 5aba4a059b755d517e76ea12 is set in QCModelDemo
await page.goto(
`${url}?page=layoutShow&layoutId=5aba4a059b755d517e76ea10`,
{ waitUntil: 'networkidle0' },
);
const location = await page.evaluate(() => window.location);
assert.strictEqual(
location.search,
'?page=layoutShow&layoutId=5aba4a059b755d517e76ea10',
);
});

await testParent.test('should merge options on layoutShow and no ignoreDefaults field', async () => {
const drawingOptions = await page.evaluate(() => {
const tabObject = { options: ['args', 'coly'] };
const objectRemoteData = {
payload: { qcObject: { fOption: 'lego colz' } },
};
return window.model.object.generateDrawingOptions(
tabObject,
objectRemoteData,
);
});

const expDrawingOpts = ['lego', 'colz', 'args', 'coly'];
assert.deepStrictEqual(drawingOptions, expDrawingOpts);
});

await testParent.test('should merge options on layoutShow and false ignoreDefaults field', async () => {
const drawingOptions = await page.evaluate(() => {
const tabObject = { ignoreDefaults: false, options: ['args', 'coly'] };
const objectRemoteData = {
payload: { qcObject: { fOption: 'lego colz' } },
};
return window.model.object.generateDrawingOptions(
tabObject,
objectRemoteData,
);
});

const expDrawingOpts = ['lego', 'colz', 'args', 'coly'];
assert.deepStrictEqual(drawingOptions, expDrawingOpts);
});

await testParent.test('should ignore default options on layoutShow and true ignoreDefaults field', async () => {
const drawingOptions = await page.evaluate(() => {
const tabObject = { ignoreDefaults: true, options: ['args', 'coly'] };
const objectRemoteData = {
payload: { qcObject: { fOption: 'lego colz' } },
};
return window.model.object.generateDrawingOptions(
tabObject,
objectRemoteData,
);
});

const expDrawingOpts = ['args', 'coly'];
assert.deepStrictEqual(drawingOptions, expDrawingOpts);
});

await testParent.test('should use only default options on objectTree', async () => {
const drawingOptions = await page.evaluate(() => {
window.model.page = 'objectTree';
const tabObject = { options: ['args', 'coly'] };
const objectRemoteData = {
payload: { qcObject: { fOption: 'lego colz' } },
};
return window.model.object.generateDrawingOptions(
tabObject,
objectRemoteData,
);
});

const expDrawingOpts = ['lego', 'colz'];
assert.deepStrictEqual(drawingOptions, expDrawingOpts);
});

await testParent.test(
'should use only default options(foption and metadata) on objectView when no layoutId or objectId is set',
async () => {
const drawingOptions = await page.evaluate(() => {
window.model.page = 'objectView';
window.model.router.params.objectId = undefined;
window.model.router.params.layoutId = undefined;
const tabObject = { options: ['args', 'coly'] };
const objectRemoteData = {
payload: {
qcObject: {
fOption: 'lego colz',
displayHints: 'hint hint2',
drawingOptions: 'option option2',
},
},
};
return window.model.object.generateDrawingOptions(
tabObject,
objectRemoteData,
);
});

const expDrawingOpts = [
'lego',
'colz',
'option',
'option2',
'hint',
'hint2',
];
assert.deepStrictEqual(expDrawingOpts, drawingOptions);
},
);

await testParent.test('should use only default options on objectView when no layoutId is set', async () => {
const drawingOptions = await page.evaluate(() => {
window.model.page = 'objectView';
window.model.router.params.layoutId = undefined;
window.model.router.params.objectId = '123';
const tabObject = { options: ['args', 'coly'] };
const objectRemoteData = {
payload: { qcObject: { fOption: 'lego colz' } },
};
return window.model.object.generateDrawingOptions(
tabObject,
objectRemoteData,
);
});

const expDrawingOpts = ['lego', 'colz'];
assert.deepStrictEqual(drawingOptions, expDrawingOpts);
});

await testParent.test('should use only default options on objectView when no objectId is set', async () => {
const drawingOptions = await page.evaluate(() => {
window.model.page = 'objectView';
window.model.router.params.objectId = undefined;
window.model.router.params.layoutId = '123';
const tabObject = { options: ['args', 'coly'] };
const objectRemoteData = {
payload: { qcObject: { fOption: 'lego colz' } },
};
return window.model.object.generateDrawingOptions(
tabObject,
objectRemoteData,
);
});

const expDrawingOpts = ['lego', 'colz'];
assert.deepStrictEqual(drawingOptions, expDrawingOpts);
});

await testParent.test('should merge options on objectView and no ignoreDefaults field', async () => {
const drawingOptions = await page.evaluate(() => {
window.model.page = 'objectView';
window.model.router.params.objectId = '5aba4a059b755d517e76ef54';
window.model.router.params.layoutId = '5aba4a059b755d517e76ea10';
window.model.layout.requestedLayout.kind = 'Success';
window.model.layout.requestedLayout.payload = {};
window.model.layout.requestedLayout.payload.tabs = [
{
id: '5aba4a059b755d517e76eb61',
name: 'SDD',
objects: [
{
id: '5aba4a059b755d517e76ef54',
options: ['gridx'],
name: 'DAQ01/EquipmentSize/CPV/CPV',
x: 0,
y: 0,
w: 1,
h: 1,
},
],
},
];
const objectRemoteData = {
payload: { qcObject: { fOption: 'lego colz' } },
};
return window.model.object.generateDrawingOptions(
null,
objectRemoteData,
);
});

const expDrawingOpts = ['lego', 'colz', 'gridx'];
assert.deepStrictEqual(drawingOptions, expDrawingOpts);
});

await testParent.test('should merge options on objectView and false ignoreDefaults field', async () => {
const drawingOptions = await page.evaluate(() => {
window.model.page = 'objectView';
window.model.router.params.objectId = '5aba4a059b755d517e76ef54';
window.model.router.params.layoutId = '5aba4a059b755d517e76ea10';
window.model.layout.requestedLayout.kind = 'Success';
window.model.layout.requestedLayout.payload = {};
window.model.layout.requestedLayout.payload.tabs = [
{
id: '5aba4a059b755d517e76eb61',
name: 'SDD',
objects: [
{
id: '5aba4a059b755d517e76ef54',
options: ['gridx'],
ignoreDefaults: false,
name: 'DAQ01/EquipmentSize/CPV/CPV',
x: 0,
y: 0,
w: 1,
h: 1,
},
],
},
];
const objectRemoteData = {
payload: { qcObject: { fOption: 'lego colz' } },
};
return window.model.object.generateDrawingOptions(
null,
objectRemoteData,
);
});

const expDrawingOpts = ['lego', 'colz', 'gridx'];
assert.deepStrictEqual(drawingOptions, expDrawingOpts);
});

await testParent.test('should ignore default options on objectView and true ignoreDefaults field', async () => {
const drawingOptions = await page.evaluate(() => {
window.model.page = 'objectView';
window.model.router.params.objectId = '5aba4a059b755d517e76ef54';
window.model.router.params.layoutId = '5aba4a059b755d517e76ea10';
window.model.layout.requestedLayout.kind = 'Success';
window.model.layout.requestedLayout.payload = {};
window.model.layout.requestedLayout.payload.tabs = [
{
id: '5aba4a059b755d517e76eb61',
name: 'SDD',
objects: [
{
id: '5aba4a059b755d517e76ef54',
options: ['gridx'],
ignoreDefaults: true,
name: 'DAQ01/EquipmentSize/CPV/CPV',
x: 0,
y: 0,
w: 1,
h: 1,
},
],
},
];
const objectRemoteData = {
payload: { qcObject: { fOption: 'lego colz' } },
};
return window.model.object.generateDrawingOptions(
null,
objectRemoteData,
);
});

const expDrawingOpts = ['gridx'];
assert.deepStrictEqual(drawingOptions, expDrawingOpts);
});
};
Loading

0 comments on commit 33125f7

Please sign in to comment.