Skip to content

Commit

Permalink
Merge branch 'check-tooltitp' of https://github.com/adessoAG/Seed-Test
Browse files Browse the repository at this point in the history
…into check-tooltitp
  • Loading branch information
jonycoo committed Nov 3, 2023
2 parents e5531ce + 122c4a6 commit 0f81931
Show file tree
Hide file tree
Showing 37 changed files with 2,749 additions and 1,501 deletions.
42 changes: 42 additions & 0 deletions backend/features/step_definitions/stepdefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,48 @@ Then(
}
);

Then('So the picture {string} has the name {string}', async function checkPicture(picture, name) {
const world = this;
const identifiers = [`//picture[source[contains(@srcset, '${picture}')] or img[contains(@src, '${picture}') or contains(@alt, '${picture}') or @id='${picture}' or contains(@title, '${picture}')]]`, `//img[contains(@src, '${picture}') or contains(@alt, '${picture}') or @id='${picture}' or contains(@title, '${picture}')]`, `${picture}`];
const promises = [];
for (const idString of identifiers) promises.push(driver.wait(until.elementLocated(By.xpath(idString)), searchTimeout, `Timed out after ${searchTimeout} ms`, 100));
const domain = (await driver.getCurrentUrl()).split('/').slice(0, 3).join('/');
let finSrc = '';
await Promise.any(promises)
.then(async (elem) => {
if (await elem.getTagName() === 'picture') {
const childSourceElems = await elem.findElements(By.xpath('.//source'));
const elementWithSrcset = await childSourceElems.find(async (element) => {
const srcsetValue = await element.getAttribute('srcset');
return srcsetValue && srcsetValue.includes(name);
});
finSrc = await elementWithSrcset.getAttribute('srcset');
}
const primSrc = await elem.getAttribute('src');
const secSrc = await elem.getAttribute('srcset');
if (!finSrc && primSrc && primSrc.includes(name)) finSrc = primSrc;
if (!finSrc && secSrc && secSrc.includes(name)) finSrc = secSrc;
finSrc = finSrc.split(' ').filter((substring) => substring.includes(name));
})
.catch(async (e) => {
await driver.takeScreenshot().then(async (buffer) => {
world.attach(buffer, 'image/png');
});
throw Error(e);
});
await fetch(domain + finSrc, { method: 'HEAD' })
.then((response) => {
if (!response.ok) throw Error(`Image ${finSrc} not Found`);
})
.catch(async (e) => {
await driver.takeScreenshot().then(async (buffer) => {
world.attach(buffer, 'image/png');
});
throw Error(`Image availability check: could not reach image source ${domain + finSrc} `, e);
});
await driver.sleep(100 + currentParameters.waitTime);
});

// Search if a text isn't in html code
Then('So I can\'t see the text: {string}', async function checkIfTextIsMissing(expectedText) {
const world = this;
Expand Down
12 changes: 6 additions & 6 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions backend/src/database/DbServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,9 @@ async function saveBlock(block) {

async function updateBlock(blockId, updatedBlock) {
try {
updatedBlock._id = ObjectId(updatedBlock._id);
updatedBlock.repositoryId = ObjectId(updatedBlock.repositoryId);
updatedBlock.owner = ObjectId(updatedBlock.owner);
const db = dbConnection.getConnection();
updatedBlock._id = ObjectId(updatedBlock._id)
updatedBlock.repositoryId = ObjectId(updatedBlock.repositoryId);
Expand All @@ -1179,6 +1182,18 @@ async function updateBlock(blockId, updatedBlock) {
}
}

// get one Block by Id
async function getBlock(blockId) {
try {
const db = dbConnection.getConnection();
return await db.collection(CustomBlocksCollection)
.findOne({ _id: ObjectId(blockId) });
} catch (e) {
console.log(`ERROR in getBlock: ${e}`);
throw e;
}
}

// get all Blocks by Id returns Array with all existing CustomBlocks
async function getBlocks(repoId) {
try {
Expand Down Expand Up @@ -1371,6 +1386,7 @@ module.exports = {
getResetRequestByEmail,
saveBlock,
updateBlock,
getBlock,
getBlocks,
deleteBlock,
getWorkgroup,
Expand Down
7 changes: 7 additions & 0 deletions backend/src/database/stepTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,13 @@ function stepDefs() {
type: 'Tool-Tip',
pre: 'So the element',
mid: 'has the tool-tip ',

}, {
id: 3,
stepType: 'then',
type: 'Check Image',
pre: 'So the picture',
mid: 'has the name ',
values: [
'',
''
Expand Down
43 changes: 39 additions & 4 deletions backend/src/serverHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ function getExamples(steps) {
return `${data}\n`;
}

// parse Steps from stepDefinition container to feature content
async function parseSteps(steps) {
let data = '';
if (steps.given !== undefined) data += `${getSteps(steps.given, Object.keys(steps)[0])}\n`;
if (steps.when !== undefined) data += `${getSteps(steps.when, Object.keys(steps)[1])}\n`;
if (steps.then !== undefined) data += `${getSteps(steps.then, Object.keys(steps)[2])}\n`;
return data;
}

// Building feature file scenario-name-content
function getScenarioContent(scenarios, storyID) {
let data = '';
Expand Down Expand Up @@ -132,8 +141,11 @@ function writeFile(story) {

// Updates feature file based on _id
async function updateFeatureFile(issueID) {
const result = await mongo.getOneStory(issueID);
if (result != null) writeFile(result);
const story = await mongo.getOneStory(issueID);
if (story != null) {
story.scenarios = await replaceRefBlocks(story.scenarios);
writeFile(story);
};
}

async function deleteFeatureFile(storyTitle, storyId) {
Expand Down Expand Up @@ -224,7 +236,6 @@ async function executeTest(req, mode, story) {
});
}


function scenarioPrep(scenarios, driver) {
const parameters = { scenarios: [] };
scenarios.forEach((scenario) => {
Expand Down Expand Up @@ -332,11 +343,34 @@ async function updateScenarioTestStatus(uploadedReport) {
}
}


async function replaceRefBlocks(scenarios) {
if (!scenarios.some((scen) => scen.hasRefBlock)) return scenarios;
const retScenarios = [];
for (const scen of scenarios) {
let stepdef = {};
// eslint-disable-next-line guard-for-in
for (const steps in scen.stepDefinitions) { // iterate over given, when, then
const promised = await scen.stepDefinitions[steps].map(async (elem) => {
if (!elem._blockReferenceId) return [elem];
return mongo.getBlock(elem._blockReferenceId).then((block) => {
// Get an array of the values of the given, when, then and example properties
let steps = Object.values(block.stepDefinitions);
// Flatten array
return steps.flat(1);
});
});
stepdef[steps] = await Promise.all(promised).then((resSteps) => resSteps.flat(1));
}
scen.stepDefinitions = stepdef;
retScenarios.push(scen);
}
return retScenarios;
}

async function exportSingleFeatureFile(_id) {
const dbStory = mongo.getOneStory(_id);
return dbStory.then(async (story) => {
story.scenarios = await replaceRefBlocks(story.scenarios);
writeFile(story);
return pfs.readFile(`./features/${this.cleanFileName(story.title + story._id.toString())}.feature`, 'utf8')
.catch((err) => console.log('couldn`t read File'));
Expand All @@ -348,6 +382,7 @@ async function exportProjectFeatureFiles(repoId, versionId) {
return dbStories.then(async (stories) => {
const zip = new AdmZip();
return Promise.all(stories.map(async (story) => {
story.scenarios = await replaceRefBlocks(story.scenarios);
writeFile(story);
const postfix = versionId ? `-v${versionId}` : '';
const filename = this.cleanFileName(story.title + story._id.toString());
Expand Down
14 changes: 14 additions & 0 deletions backend/src/serverRouter/blockRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ router.post('/', async (req, res) => {
}
});

// update Block a Block
router.put('/block', async (req, res) => {
try {
const { body } = req;
if (!req.user) res.sendStatus(401);
else {
const result = await mongo.updateBlock(body);
res.status(200).json(result.value);
}
} catch (error) {
handleError(res, error, error, 500);
}
});

// update custom Blocks
router.put('/:blockId', async (req, res) => {
try {
Expand Down
53 changes: 26 additions & 27 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0f81931

Please sign in to comment.