Skip to content

Commit cd794a2

Browse files
author
Dmitry Eremin
committed
TMS workflow: unwrap test suite for test run linking
1 parent 1e809e7 commit cd794a2

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

js/test-management-scenarios/populate-test-run.js

+10-18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
var entities = require('@jetbrains/youtrack-scripting-api/entities');
1010
var workflow = require('@jetbrains/youtrack-scripting-api/workflow');
11+
var utils = require('./utils');
1112

1213
exports.rule = entities.Issue.onChange({
1314
title: 'Populate-test-run',
@@ -23,24 +24,15 @@ exports.rule = entities.Issue.onChange({
2324
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));
2425
TestCase.links[ctx.Execution.inward].delete(issue);
2526

26-
// New issue creation
27-
var TestCaseRun = TestCase.copy();
28-
TestCaseRun.Type = ctx.Type.TestExecution.name;
29-
TestCaseRun.Status = ctx.Status.NoRun.name;
30-
31-
// Remove all links from Test Case Execution
32-
Object.keys(TestCaseRun.links).forEach(function(linkType) {
33-
if (!TestCaseRun.links[linkType])
34-
return;
35-
TestCaseRun.links[linkType].clear();
36-
});
37-
TestCaseRun.summary = "[TEST_CASE_EXECUTION" + "] [" + TestCaseRun.summary + "]";
27+
if (TestCase.Type.name == ctx.Type.TestSuite.name) {
28+
var linkedTestCases = TestCase.links[ctx.Subtask.outward]
29+
linkedTestCases.forEach(function(testCase) {
30+
utils.createTestCaseRun(testCase, issue, ctx);
31+
});
32+
} else {
33+
utils.createTestCaseRun(TestCase, issue, ctx);
34+
}
3835

39-
// Links population
40-
TestCaseRun.links[ctx.Subtask.inward].add(issue);
41-
issue.links[ctx.Subtask.outward].add(TestCaseRun);
42-
TestCaseRun.links[ctx.Execution.outward].add(TestCase);
43-
});
4436
issue.fields['Total number of test cases'] = totalTestRuns;
4537
},
4638
requirements: {
@@ -99,4 +91,4 @@ exports.rule = entities.Issue.onChange({
9991
},
10092
},
10193
}
102-
});
94+
});

js/test-management-scenarios/utils.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,24 @@ exports.resetStatuses = function(testRun, testRunCopy) {
2525
testRunCopy.fields['Number of passed test cases'] = 0;
2626
testRunCopy.fields['Number of failed test cases'] = 0;
2727
return true;
28-
};
28+
};
29+
exports.createTestCaseRun = function(testCase, testRun, ctx) {
30+
// New issue creation
31+
var testCaseRun = testCase.copy();
32+
33+
testCaseRun.Type = ctx.Type.TestExecution.name;
34+
testCaseRun.Status = ctx.Status.NoRun.name;
35+
36+
// Remove all links from Test Case Execution
37+
Object.keys(testCaseRun.links).forEach(function(linkType) {
38+
if (!testCaseRun.links[linkType])
39+
return;
40+
testCaseRun.links[linkType].clear();
41+
});
42+
testCaseRun.summary = "[TEST_CASE_EXECUTION" + "] [" + testCaseRun.summary + "]";
43+
44+
// Links population
45+
testCaseRun.links[ctx.Subtask.inward].add(testRun);
46+
testRun.links[ctx.Subtask.outward].add(testCaseRun);
47+
testCaseRun.links[ctx.Execution.outward].add(testCase);
48+
};

0 commit comments

Comments
 (0)