From cd794a2cce7c37f06d08a1df5d7efa15d10760f3 Mon Sep 17 00:00:00 2001 From: Dmitry Eremin Date: Sat, 27 Nov 2021 01:24:56 +0300 Subject: [PATCH] TMS workflow: unwrap test suite for test run linking --- .../populate-test-run.js | 28 +++++++------------ js/test-management-scenarios/utils.js | 22 ++++++++++++++- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/js/test-management-scenarios/populate-test-run.js b/js/test-management-scenarios/populate-test-run.js index b3589af..e6a8d87 100644 --- a/js/test-management-scenarios/populate-test-run.js +++ b/js/test-management-scenarios/populate-test-run.js @@ -8,6 +8,7 @@ var entities = require('@jetbrains/youtrack-scripting-api/entities'); var workflow = require('@jetbrains/youtrack-scripting-api/workflow'); +var utils = require('./utils'); exports.rule = entities.Issue.onChange({ title: 'Populate-test-run', @@ -23,24 +24,15 @@ exports.rule = entities.Issue.onChange({ workflow.check((TestCase.Type.name == ctx.Type.TestCase.name) || (TestCase.Type.name == ctx.Type.TestSuite.name), workflow.i18n('\'Test Run\' can be linked to \'Test Case\' and \'Test Suite\' only, but {0} has \'{1}\' type!', message, TestCase.Type.name)); TestCase.links[ctx.Execution.inward].delete(issue); - // New issue creation - var TestCaseRun = TestCase.copy(); - TestCaseRun.Type = ctx.Type.TestExecution.name; - TestCaseRun.Status = ctx.Status.NoRun.name; - - // Remove all links from Test Case Execution - Object.keys(TestCaseRun.links).forEach(function(linkType) { - if (!TestCaseRun.links[linkType]) - return; - TestCaseRun.links[linkType].clear(); - }); - TestCaseRun.summary = "[TEST_CASE_EXECUTION" + "] [" + TestCaseRun.summary + "]"; + if (TestCase.Type.name == ctx.Type.TestSuite.name) { + var linkedTestCases = TestCase.links[ctx.Subtask.outward] + linkedTestCases.forEach(function(testCase) { + utils.createTestCaseRun(testCase, issue, ctx); + }); + } else { + utils.createTestCaseRun(TestCase, issue, ctx); + } - // Links population - TestCaseRun.links[ctx.Subtask.inward].add(issue); - issue.links[ctx.Subtask.outward].add(TestCaseRun); - TestCaseRun.links[ctx.Execution.outward].add(TestCase); - }); issue.fields['Total number of test cases'] = totalTestRuns; }, requirements: { @@ -99,4 +91,4 @@ exports.rule = entities.Issue.onChange({ }, }, } -}); \ No newline at end of file +}); diff --git a/js/test-management-scenarios/utils.js b/js/test-management-scenarios/utils.js index 7135832..ef4bec6 100644 --- a/js/test-management-scenarios/utils.js +++ b/js/test-management-scenarios/utils.js @@ -25,4 +25,24 @@ exports.resetStatuses = function(testRun, testRunCopy) { testRunCopy.fields['Number of passed test cases'] = 0; testRunCopy.fields['Number of failed test cases'] = 0; return true; -}; \ No newline at end of file +}; +exports.createTestCaseRun = function(testCase, testRun, ctx) { + // New issue creation + var testCaseRun = testCase.copy(); + + testCaseRun.Type = ctx.Type.TestExecution.name; + testCaseRun.Status = ctx.Status.NoRun.name; + + // Remove all links from Test Case Execution + Object.keys(testCaseRun.links).forEach(function(linkType) { + if (!testCaseRun.links[linkType]) + return; + testCaseRun.links[linkType].clear(); + }); + testCaseRun.summary = "[TEST_CASE_EXECUTION" + "] [" + testCaseRun.summary + "]"; + + // Links population + testCaseRun.links[ctx.Subtask.inward].add(testRun); + testRun.links[ctx.Subtask.outward].add(testCaseRun); + testCaseRun.links[ctx.Execution.outward].add(testCase); +};