Skip to content

Commit df4946e

Browse files
authored
Merge pull request #65 from test-results-reporter/47-target-title-links
feat: title links
2 parents 86abe18 + f274571 commit df4946e

10 files changed

+436
-453
lines changed

src/index.d.ts

+10-12
Original file line numberDiff line numberDiff line change
@@ -76,30 +76,28 @@ export interface Link {
7676
condition?: Condition;
7777
}
7878

79-
80-
export interface SlackInputs {
79+
export interface TargetInputs {
8180
url: string;
82-
publish?: PublishReportType;
83-
only_failures?: boolean;
8481
title?: string;
8582
title_suffix?: string;
83+
title_link?: string;
8684
duration?: string;
87-
}
88-
89-
export interface TeamsInputs {
90-
url: string;
9185
publish?: PublishReportType;
9286
only_failures?: boolean;
93-
title?: string;
94-
title_suffix?: string;
87+
}
88+
89+
export interface SlackInputs extends TargetInputs {}
90+
91+
export interface TeamsInputs extends TargetInputs {
9592
width?: string;
96-
duration?: string;
9793
}
9894

95+
export interface ChatInputs extends TargetInputs {}
96+
9997
export interface Target {
10098
name: TargetName;
10199
condition: Condition;
102-
inputs: SlackInputs | TeamsInputs;
100+
inputs: SlackInputs | TeamsInputs | ChatInputs;
103101
extensions?: Extension[];
104102
}
105103

src/targets/chat.js

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ function setMainBlock({ result, target, payload }) {
5252
} else {
5353
title_text_with_emoji = `${emoji} ${title_text}`;
5454
}
55+
if (target.inputs.title_link) {
56+
title_text_with_emoji = `<a href="${target.inputs.title_link}">${title_text_with_emoji}</a>`;
57+
}
5558
const text = `<b>${title_text_with_emoji}</b><br><br><b>Results</b>: ${result_text}<br><b>Duration</b>: ${duration_text}`;
5659
payload.sections.push({
5760
"widgets": [

src/targets/slack.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@ function setMainBlock({ result, target, payload }) {
5454
}
5555

5656
function getTitleText(result, target) {
57-
const title = target.inputs.title ? target.inputs.title : result.name;
57+
let text = target.inputs.title ? target.inputs.title : result.name;
5858
if (target.inputs.title_suffix) {
59-
return `${title} ${target.inputs.title_suffix}`;
59+
text = `${text} ${target.inputs.title_suffix}`;
6060
}
61-
return `${title}`;
61+
if (target.inputs.title_link) {
62+
text = `<${target.inputs.title_link}|${text}>`;
63+
}
64+
return text;
6265
}
6366

6467
function getResultText(result) {

src/targets/teams.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ async function run({ result, target }) {
88
const root_payload = getRootPayload();
99
const payload = getMainPayload(target);
1010
await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.START });
11-
setTitleBlock(result, { target, payload });
11+
setTitleBlock({ result, target, payload });
1212
setMainBlock({ result, target, payload });
1313
await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.POST_MAIN });
14-
setSuiteBlock(result, { target, payload });
14+
setSuiteBlock({ result, target, payload });
1515
await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.END });
1616
setRootPayload(root_payload, payload);
1717
return request.post({
@@ -55,7 +55,7 @@ function getTitleText(result, target) {
5555
return `${title}`;
5656
}
5757

58-
function setTitleBlock(result, { target, payload }) {
58+
function setTitleBlock({ result, target, payload }) {
5959
const title = getTitleText(result, target);
6060
const emoji = result.status === 'PASS' ? '✅' : '❌';
6161
let text = '';
@@ -66,6 +66,9 @@ function setTitleBlock(result, { target, payload }) {
6666
} else {
6767
text = `${emoji} ${title}`;
6868
}
69+
if (target.inputs.title_link) {
70+
text = `[${text}](${target.inputs.title_link})`
71+
}
6972
payload.body.push({
7073
"type": "TextBlock",
7174
"text": text,
@@ -92,7 +95,7 @@ function setMainBlock({ result, target, payload }) {
9295
});
9396
}
9497

95-
function setSuiteBlock(result, { target, payload }) {
98+
function setSuiteBlock({ result, target, payload }) {
9699
if (target.inputs.include_suites) {
97100
for (let i = 0; i < result.suites.length; i++) {
98101
const suite = result.suites[i];

test/mocks/chat.mock.js

+45-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { addInteractionHandler } = require('pactum').handler;
22
const { addDataTemplate } = require('pactum').stash;
33

44
addDataTemplate({
5-
'RESULT_SINGLE_SUITE': {
5+
'CHAT_RESULT_SINGLE_SUITE': {
66
"widgets": [
77
{
88
"textParagraph": {
@@ -11,7 +11,7 @@ addDataTemplate({
1111
}
1212
]
1313
},
14-
'RESULT_SINGLE_SUITE_FAILURES': {
14+
'CHAT_RESULT_SINGLE_SUITE_FAILURES': {
1515
"widgets": [
1616
{
1717
"textParagraph": {
@@ -20,7 +20,7 @@ addDataTemplate({
2020
}
2121
]
2222
},
23-
'RESULT_MULTIPLE_SUITE_FAILURES': {
23+
'CHAT_RESULT_MULTIPLE_SUITE_FAILURES': {
2424
"widgets": [
2525
{
2626
"textParagraph": {
@@ -29,7 +29,7 @@ addDataTemplate({
2929
}
3030
]
3131
},
32-
'RESULT_MULTIPLE_SUITE_FAILURES_WITH_EMOJI': {
32+
'CHAT_RESULT_MULTIPLE_SUITE_FAILURES_WITH_EMOJI': {
3333
"widgets": [
3434
{
3535
"textParagraph": {
@@ -83,7 +83,7 @@ addInteractionHandler('post test-summary to chat', () => {
8383
{
8484
"sections": [
8585
{
86-
"@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE"
86+
"@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE"
8787
}
8888
]
8989
}
@@ -106,7 +106,7 @@ addInteractionHandler('post test-summary to chat with multiple suites', () => {
106106
{
107107
"sections": [
108108
{
109-
"@DATA:TEMPLATE@": "RESULT_MULTIPLE_SUITE_FAILURES"
109+
"@DATA:TEMPLATE@": "CHAT_RESULT_MULTIPLE_SUITE_FAILURES"
110110
},
111111
{
112112
"@DATA:TEMPLATE@": "SUITE_MULTIPLE_SUITE_FAILURES"
@@ -132,7 +132,7 @@ addInteractionHandler('post test-summary-slim to chat with multiple suites', ()
132132
{
133133
"sections": [
134134
{
135-
"@DATA:TEMPLATE@": "RESULT_MULTIPLE_SUITE_FAILURES_WITH_EMOJI"
135+
"@DATA:TEMPLATE@": "CHAT_RESULT_MULTIPLE_SUITE_FAILURES_WITH_EMOJI"
136136
}
137137
]
138138
}
@@ -155,7 +155,7 @@ addInteractionHandler('post failure-details to chat with multiple suites', () =>
155155
{
156156
"sections": [
157157
{
158-
"@DATA:TEMPLATE@": "RESULT_MULTIPLE_SUITE_FAILURES"
158+
"@DATA:TEMPLATE@": "CHAT_RESULT_MULTIPLE_SUITE_FAILURES"
159159
},
160160
{
161161
"@DATA:TEMPLATE@": "SUITE_MULTIPLE_SUITE_FAILURE_DETAILS"
@@ -181,7 +181,7 @@ addInteractionHandler('post failure-details to chat with single suite', () => {
181181
{
182182
"sections": [
183183
{
184-
"@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE_FAILURES"
184+
"@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE_FAILURES"
185185
},
186186
{
187187
"@DATA:TEMPLATE@": "SINGLE_SUITE_FAILURE_DETAILS"
@@ -207,7 +207,7 @@ addInteractionHandler('post test-summary with hyperlinks to chat', () => {
207207
{
208208
"sections": [
209209
{
210-
"@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE"
210+
"@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE"
211211
},
212212
{
213213
"widgets": [
@@ -240,7 +240,7 @@ addInteractionHandler('post test-summary to chat with mentions', () => {
240240
{
241241
"sections": [
242242
{
243-
"@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE_FAILURES"
243+
"@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE_FAILURES"
244244
}
245245
]
246246
}
@@ -263,7 +263,7 @@ addInteractionHandler('post test-summary to chat with report portal analysis', (
263263
{
264264
"sections": [
265265
{
266-
"@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE_FAILURES"
266+
"@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE_FAILURES"
267267
},
268268
{
269269
"widgets": [
@@ -295,7 +295,7 @@ addInteractionHandler('post test-summary to chat with report portal history', ()
295295
{
296296
"sections": [
297297
{
298-
"@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE_FAILURES"
298+
"@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE_FAILURES"
299299
},
300300
{
301301
"widgets": [
@@ -327,7 +327,7 @@ addInteractionHandler('post test-summary to chat with percy analysis', () => {
327327
{
328328
"sections": [
329329
{
330-
"@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE_FAILURES"
330+
"@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE_FAILURES"
331331
},
332332
{
333333
"widgets": [
@@ -359,7 +359,7 @@ addInteractionHandler('post percy analysis with removed snapshots to chat', () =
359359
{
360360
"sections": [
361361
{
362-
"@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE_FAILURES"
362+
"@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE_FAILURES"
363363
},
364364
{
365365
"widgets": [
@@ -391,7 +391,7 @@ addInteractionHandler('post percy analysis with un-reviewed snapshots to chat',
391391
{
392392
"sections": [
393393
{
394-
"@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE_FAILURES"
394+
"@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE_FAILURES"
395395
},
396396
{
397397
"widgets": [
@@ -411,4 +411,33 @@ addInteractionHandler('post percy analysis with un-reviewed snapshots to chat',
411411
status: 200
412412
}
413413
}
414+
});
415+
416+
addInteractionHandler('post test-summary to chat with title_link', () => {
417+
return {
418+
request: {
419+
method: 'POST',
420+
path: '/message',
421+
body: {
422+
"cards": [
423+
{
424+
"sections": [
425+
{
426+
"widgets": [
427+
{
428+
"textParagraph": {
429+
"text": "<b><a href=\"some-url\">✅ Default suite</a></b><br><br><b>Results</b>: 4 / 4 Passed (100%)<br><b>Duration</b>: 0:02"
430+
}
431+
}
432+
]
433+
}
434+
]
435+
}
436+
]
437+
}
438+
},
439+
response: {
440+
status: 200
441+
}
442+
}
414443
});

0 commit comments

Comments
 (0)