diff --git a/src/index.d.ts b/src/index.d.ts index cae5f5b..7e1a5bc 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -76,30 +76,28 @@ export interface Link { condition?: Condition; } - -export interface SlackInputs { +export interface TargetInputs { url: string; - publish?: PublishReportType; - only_failures?: boolean; title?: string; title_suffix?: string; + title_link?: string; duration?: string; -} - -export interface TeamsInputs { - url: string; publish?: PublishReportType; only_failures?: boolean; - title?: string; - title_suffix?: string; +} + +export interface SlackInputs extends TargetInputs {} + +export interface TeamsInputs extends TargetInputs { width?: string; - duration?: string; } +export interface ChatInputs extends TargetInputs {} + export interface Target { name: TargetName; condition: Condition; - inputs: SlackInputs | TeamsInputs; + inputs: SlackInputs | TeamsInputs | ChatInputs; extensions?: Extension[]; } diff --git a/src/targets/chat.js b/src/targets/chat.js index 557985e..25a20da 100644 --- a/src/targets/chat.js +++ b/src/targets/chat.js @@ -52,6 +52,9 @@ function setMainBlock({ result, target, payload }) { } else { title_text_with_emoji = `${emoji} ${title_text}`; } + if (target.inputs.title_link) { + title_text_with_emoji = `${title_text_with_emoji}`; + } const text = `${title_text_with_emoji}

Results: ${result_text}
Duration: ${duration_text}`; payload.sections.push({ "widgets": [ diff --git a/src/targets/slack.js b/src/targets/slack.js index d689647..2cb6630 100644 --- a/src/targets/slack.js +++ b/src/targets/slack.js @@ -54,11 +54,14 @@ function setMainBlock({ result, target, payload }) { } function getTitleText(result, target) { - const title = target.inputs.title ? target.inputs.title : result.name; + let text = target.inputs.title ? target.inputs.title : result.name; if (target.inputs.title_suffix) { - return `${title} ${target.inputs.title_suffix}`; + text = `${text} ${target.inputs.title_suffix}`; } - return `${title}`; + if (target.inputs.title_link) { + text = `<${target.inputs.title_link}|${text}>`; + } + return text; } function getResultText(result) { diff --git a/src/targets/teams.js b/src/targets/teams.js index 88d656f..ad5839a 100644 --- a/src/targets/teams.js +++ b/src/targets/teams.js @@ -8,10 +8,10 @@ async function run({ result, target }) { const root_payload = getRootPayload(); const payload = getMainPayload(target); await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.START }); - setTitleBlock(result, { target, payload }); + setTitleBlock({ result, target, payload }); setMainBlock({ result, target, payload }); await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.POST_MAIN }); - setSuiteBlock(result, { target, payload }); + setSuiteBlock({ result, target, payload }); await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.END }); setRootPayload(root_payload, payload); return request.post({ @@ -55,7 +55,7 @@ function getTitleText(result, target) { return `${title}`; } -function setTitleBlock(result, { target, payload }) { +function setTitleBlock({ result, target, payload }) { const title = getTitleText(result, target); const emoji = result.status === 'PASS' ? '✅' : '❌'; let text = ''; @@ -66,6 +66,9 @@ function setTitleBlock(result, { target, payload }) { } else { text = `${emoji} ${title}`; } + if (target.inputs.title_link) { + text = `[${text}](${target.inputs.title_link})` + } payload.body.push({ "type": "TextBlock", "text": text, @@ -92,7 +95,7 @@ function setMainBlock({ result, target, payload }) { }); } -function setSuiteBlock(result, { target, payload }) { +function setSuiteBlock({ result, target, payload }) { if (target.inputs.include_suites) { for (let i = 0; i < result.suites.length; i++) { const suite = result.suites[i]; diff --git a/test/mocks/chat.mock.js b/test/mocks/chat.mock.js index fe1a485..4350077 100644 --- a/test/mocks/chat.mock.js +++ b/test/mocks/chat.mock.js @@ -2,7 +2,7 @@ const { addInteractionHandler } = require('pactum').handler; const { addDataTemplate } = require('pactum').stash; addDataTemplate({ - 'RESULT_SINGLE_SUITE': { + 'CHAT_RESULT_SINGLE_SUITE': { "widgets": [ { "textParagraph": { @@ -11,7 +11,7 @@ addDataTemplate({ } ] }, - 'RESULT_SINGLE_SUITE_FAILURES': { + 'CHAT_RESULT_SINGLE_SUITE_FAILURES': { "widgets": [ { "textParagraph": { @@ -20,7 +20,7 @@ addDataTemplate({ } ] }, - 'RESULT_MULTIPLE_SUITE_FAILURES': { + 'CHAT_RESULT_MULTIPLE_SUITE_FAILURES': { "widgets": [ { "textParagraph": { @@ -29,7 +29,7 @@ addDataTemplate({ } ] }, - 'RESULT_MULTIPLE_SUITE_FAILURES_WITH_EMOJI': { + 'CHAT_RESULT_MULTIPLE_SUITE_FAILURES_WITH_EMOJI': { "widgets": [ { "textParagraph": { @@ -83,7 +83,7 @@ addInteractionHandler('post test-summary to chat', () => { { "sections": [ { - "@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE" + "@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE" } ] } @@ -106,7 +106,7 @@ addInteractionHandler('post test-summary to chat with multiple suites', () => { { "sections": [ { - "@DATA:TEMPLATE@": "RESULT_MULTIPLE_SUITE_FAILURES" + "@DATA:TEMPLATE@": "CHAT_RESULT_MULTIPLE_SUITE_FAILURES" }, { "@DATA:TEMPLATE@": "SUITE_MULTIPLE_SUITE_FAILURES" @@ -132,7 +132,7 @@ addInteractionHandler('post test-summary-slim to chat with multiple suites', () { "sections": [ { - "@DATA:TEMPLATE@": "RESULT_MULTIPLE_SUITE_FAILURES_WITH_EMOJI" + "@DATA:TEMPLATE@": "CHAT_RESULT_MULTIPLE_SUITE_FAILURES_WITH_EMOJI" } ] } @@ -155,7 +155,7 @@ addInteractionHandler('post failure-details to chat with multiple suites', () => { "sections": [ { - "@DATA:TEMPLATE@": "RESULT_MULTIPLE_SUITE_FAILURES" + "@DATA:TEMPLATE@": "CHAT_RESULT_MULTIPLE_SUITE_FAILURES" }, { "@DATA:TEMPLATE@": "SUITE_MULTIPLE_SUITE_FAILURE_DETAILS" @@ -181,7 +181,7 @@ addInteractionHandler('post failure-details to chat with single suite', () => { { "sections": [ { - "@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE_FAILURES" + "@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE_FAILURES" }, { "@DATA:TEMPLATE@": "SINGLE_SUITE_FAILURE_DETAILS" @@ -207,7 +207,7 @@ addInteractionHandler('post test-summary with hyperlinks to chat', () => { { "sections": [ { - "@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE" + "@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE" }, { "widgets": [ @@ -240,7 +240,7 @@ addInteractionHandler('post test-summary to chat with mentions', () => { { "sections": [ { - "@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE_FAILURES" + "@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE_FAILURES" } ] } @@ -263,7 +263,7 @@ addInteractionHandler('post test-summary to chat with report portal analysis', ( { "sections": [ { - "@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE_FAILURES" + "@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE_FAILURES" }, { "widgets": [ @@ -295,7 +295,7 @@ addInteractionHandler('post test-summary to chat with report portal history', () { "sections": [ { - "@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE_FAILURES" + "@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE_FAILURES" }, { "widgets": [ @@ -327,7 +327,7 @@ addInteractionHandler('post test-summary to chat with percy analysis', () => { { "sections": [ { - "@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE_FAILURES" + "@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE_FAILURES" }, { "widgets": [ @@ -359,7 +359,7 @@ addInteractionHandler('post percy analysis with removed snapshots to chat', () = { "sections": [ { - "@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE_FAILURES" + "@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE_FAILURES" }, { "widgets": [ @@ -391,7 +391,7 @@ addInteractionHandler('post percy analysis with un-reviewed snapshots to chat', { "sections": [ { - "@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE_FAILURES" + "@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE_FAILURES" }, { "widgets": [ @@ -411,4 +411,33 @@ addInteractionHandler('post percy analysis with un-reviewed snapshots to chat', status: 200 } } +}); + +addInteractionHandler('post test-summary to chat with title_link', () => { + return { + request: { + method: 'POST', + path: '/message', + body: { + "cards": [ + { + "sections": [ + { + "widgets": [ + { + "textParagraph": { + "text": "✅ Default suite

Results: 4 / 4 Passed (100%)
Duration: 0:02" + } + } + ] + } + ] + } + ] + } + }, + response: { + status: 200 + } + } }); \ No newline at end of file diff --git a/test/mocks/slack.mock.js b/test/mocks/slack.mock.js index e960f61..ff01b0c 100644 --- a/test/mocks/slack.mock.js +++ b/test/mocks/slack.mock.js @@ -1,4 +1,43 @@ const { addInteractionHandler } = require('pactum').handler; +const { addDataTemplate } = require('pactum').stash; + +addDataTemplate({ + 'SLACK_ROOT_SINGLE_SUITE': { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Default suite*\n\n*Results*: 4 / 4 Passed (100%)\n*Duration*: 0:02" + } + }, + 'SLACK_ROOT_SINGLE_SUITE_FAILURE': { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 0:02" + } + }, + 'SLACK_ROOT_MULTIPLE_SUITES': { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Regression Tests*\n\n*Results*: 8 / 20 Passed (40%)\n*Duration*: 23:23" + } + }, + 'SLACK_SUITE_CHROME': { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*❌ desktop-chrome*\n\n*Results*: 2 / 5 Passed (40%)\n*Duration*: 3:22" + } + }, + 'SLACK_SUITE_IOS': { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*❌ mobile-ios*\n\n*Results*: 2 / 5 Passed (40%)\n*Duration*: 9:05" + } + } +}); addInteractionHandler('post test-summary to slack', () => { return { @@ -11,11 +50,7 @@ addInteractionHandler('post test-summary to slack', () => { "color": "#36A64F", "blocks": [ { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Default suite*\n\n*Results*: 4 / 4 Passed (100%)\n*Duration*: 0:02" - } + "@DATA:TEMPLATE@": "SLACK_ROOT_SINGLE_SUITE" } ] } @@ -39,25 +74,13 @@ addInteractionHandler('post test-summary to slack with multiple suites', () => { "color": "#DC143C", "blocks": [ { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Regression Tests*\n\n*Results*: 8 / 20 Passed (40%)\n*Duration*: 23:23" - } + "@DATA:TEMPLATE@": "SLACK_ROOT_MULTIPLE_SUITES" }, { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*❌ desktop-chrome*\n\n*Results*: 2 / 5 Passed (40%)\n*Duration*: 3:22" - } + "@DATA:TEMPLATE@": "SLACK_SUITE_CHROME" }, { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*❌ mobile-ios*\n\n*Results*: 2 / 5 Passed (40%)\n*Duration*: 9:05" - } + "@DATA:TEMPLATE@": "SLACK_SUITE_IOS" } ] } @@ -81,11 +104,7 @@ addInteractionHandler('post test-summary-slim to slack with multiple suites', () "color": "#DC143C", "blocks": [ { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Regression Tests*\n\n*Results*: 8 / 20 Passed (40%)\n*Duration*: 23:23" - } + "@DATA:TEMPLATE@": "SLACK_ROOT_MULTIPLE_SUITES" } ] } @@ -109,18 +128,10 @@ addInteractionHandler('post failure-details to slack with multiple suites', () = "color": "#DC143C", "blocks": [ { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Regression Tests*\n\n*Results*: 8 / 20 Passed (40%)\n*Duration*: 23:23" - } + "@DATA:TEMPLATE@": "SLACK_ROOT_MULTIPLE_SUITES" }, { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*❌ desktop-chrome*\n\n*Results*: 2 / 5 Passed (40%)\n*Duration*: 3:22" - } + "@DATA:TEMPLATE@": "SLACK_SUITE_CHROME" }, { "type": "section", @@ -130,11 +141,7 @@ addInteractionHandler('post failure-details to slack with multiple suites', () = } }, { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*❌ mobile-ios*\n\n*Results*: 2 / 5 Passed (40%)\n*Duration*: 9:05" - } + "@DATA:TEMPLATE@": "SLACK_SUITE_IOS" }, { "type": "section", @@ -165,11 +172,7 @@ addInteractionHandler('post failure-details to slack with single suite', () => { "color": "#DC143C", "blocks": [ { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 0:02" - } + "@DATA:TEMPLATE@": "SLACK_ROOT_SINGLE_SUITE_FAILURE" }, { "type": "section", @@ -200,11 +203,7 @@ addInteractionHandler('post test-summary with hyperlinks to slack - pass status' "color": "#36A64F", "blocks": [ { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Default suite*\n\n*Results*: 4 / 4 Passed (100%)\n*Duration*: 0:02" - } + "@DATA:TEMPLATE@": "SLACK_ROOT_SINGLE_SUITE" }, { "type": "context", @@ -237,11 +236,7 @@ addInteractionHandler('post test-summary with hyperlinks to slack - fail status' "color": "#DC143C", "blocks": [ { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 0:02" - } + "@DATA:TEMPLATE@": "SLACK_ROOT_SINGLE_SUITE_FAILURE" }, { "type": "context", @@ -274,11 +269,7 @@ addInteractionHandler('post test-summary to slack with report portal analysis', "color": "#DC143C", "blocks": [ { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 0:02" - } + "@DATA:TEMPLATE@": "SLACK_ROOT_SINGLE_SUITE_FAILURE" }, { "type": "section", @@ -309,11 +300,7 @@ addInteractionHandler('post test-summary to slack with report portal analysis wi "color": "#DC143C", "blocks": [ { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 0:02" - } + "@DATA:TEMPLATE@": "SLACK_ROOT_SINGLE_SUITE_FAILURE" }, { "type": "section", @@ -344,11 +331,7 @@ addInteractionHandler('post test-summary to slack with report portal analysis wi "color": "#DC143C", "blocks": [ { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 0:02" - } + "@DATA:TEMPLATE@": "SLACK_ROOT_SINGLE_SUITE_FAILURE" }, { "type": "divider" @@ -382,11 +365,7 @@ addInteractionHandler('post test-summary with mentions to slack', () => { "color": "#DC143C", "blocks": [ { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 0:02" - } + "@DATA:TEMPLATE@": "SLACK_ROOT_SINGLE_SUITE_FAILURE" }, { "type": "section", @@ -417,15 +396,13 @@ addInteractionHandler('post test-summary to slack with qc-test-summary', (ctx) = "color": "#DC143C", "blocks": [ { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 0:02" - }, - "accessory": { - "type": "image", - "image_url": `${ctx.data.quickChartUrl}/chart?c=%7B%22type%22%3A%22radialGauge%22%2C%22data%22%3A%7B%22datasets%22%3A%5B%7B%22data%22%3A%5B75%5D%2C%22backgroundColor%22%3A%22green%22%7D%5D%7D%2C%22options%22%3A%7B%22trackColor%22%3A%22%23FF0000%22%2C%22roundedCorners%22%3Afalse%2C%22centerPercentage%22%3A80%2C%22centerArea%22%3A%7B%22fontSize%22%3A80%2C%22text%22%3A%2275%25%22%7D%7D%7D`, - "alt_text": "overall-results-summary" + "@DATA:TEMPLATE@": "SLACK_ROOT_SINGLE_SUITE_FAILURE", + "@OVERRIDES@": { + "accessory": { + "type": "image", + "image_url": `${ctx.data.quickChartUrl}/chart?c=%7B%22type%22%3A%22radialGauge%22%2C%22data%22%3A%7B%22datasets%22%3A%5B%7B%22data%22%3A%5B75%5D%2C%22backgroundColor%22%3A%22green%22%7D%5D%7D%2C%22options%22%3A%7B%22trackColor%22%3A%22%23FF0000%22%2C%22roundedCorners%22%3Afalse%2C%22centerPercentage%22%3A80%2C%22centerArea%22%3A%7B%22fontSize%22%3A80%2C%22text%22%3A%2275%25%22%7D%7D%7D`, + "alt_text": "overall-results-summary" + } } } ] @@ -450,11 +427,7 @@ addInteractionHandler('post test-summary to slack with report portal history', ( "color": "#DC143C", "blocks": [ { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 0:02" - } + "@DATA:TEMPLATE@": "SLACK_ROOT_SINGLE_SUITE_FAILURE" }, { "type": "section", @@ -484,18 +457,42 @@ addInteractionHandler('post test-summary to slack with percy analysis', () => { { "color": "#DC143C", "blocks": [ + { + "@DATA:TEMPLATE@": "SLACK_ROOT_SINGLE_SUITE_FAILURE" + }, { "type": "section", "text": { "type": "mrkdwn", - "text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 0:02" + "text": "**\n\n*✔ AP - 1* | 🔎 UR - 0 | 🗑 RM - 0" } - }, + } + ] + } + ] + } + }, + response: { + status: 200 + } + } +}); + +addInteractionHandler('post test-summary to slack with title_link', () => { + return { + request: { + method: 'POST', + path: '/message', + body: { + "attachments": [ + { + "color": "#36A64F", + "blocks": [ { "type": "section", "text": { "type": "mrkdwn", - "text": "**\n\n*✔ AP - 1* | 🔎 UR - 0 | 🗑 RM - 0" + "text": "**\n\n*Results*: 4 / 4 Passed (100%)\n*Duration*: 0:02" } } ] diff --git a/test/mocks/teams.mock.js b/test/mocks/teams.mock.js index 512c783..586f87b 100644 --- a/test/mocks/teams.mock.js +++ b/test/mocks/teams.mock.js @@ -1,4 +1,99 @@ const { addInteractionHandler } = require('pactum').handler; +const { addDataTemplate } = require('pactum').stash; + +addDataTemplate({ + 'TEAMS_ROOT_TITLE_SINGLE_SUITE': { + "type": "TextBlock", + "text": "✅ Default suite", + "size": "medium", + "weight": "bolder", + "wrap": true + }, + 'TEAMS_ROOT_TITLE_SINGLE_SUITE_FAILURE': { + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE", + "@OVERRIDES@": { + "text": "❌ Default suite", + } + }, + 'TEAMS_ROOT_RESULTS_SINGLE_SUITE': { + "type": "FactSet", + "facts": [ + { + "title": "Results:", + "value": "4 / 4 Passed (100%)" + }, + { + "title": "Duration:", + "value": "0:02" + } + ] + }, + 'TEAMS_ROOT_RESULTS_SINGLE_SUITE_FAILURES': { + "type": "FactSet", + "facts": [ + { + "title": "Results:", + "value": "3 / 4 Passed (75%)" + }, + { + "title": "Duration:", + "value": "0:02" + } + ] + }, + 'TEAMS_ROOT_RESULTS_MULTIPLE_SUITES': { + "type": "FactSet", + "facts": [ + { + "title": "Results:", + "value": "8 / 20 Passed (40%)" + }, + { + "title": "Duration:", + "value": "23:23" + } + ] + }, + 'TEAMS_SUITE_CHROME_TITLE': { + "type": "TextBlock", + "text": "❌ desktop-chrome", + "isSubtle": true, + "weight": "bolder", + "wrap": true + }, + 'TEAMS_SUITE_IOS_TITLE': { + "@DATA:TEMPLATE@": "TEAMS_SUITE_CHROME_TITLE", + "@OVERRIDES@": { + "text": "❌ mobile-ios", + } + }, + 'TEAMS_SUITE_CHROME_RESULTS': { + "type": "FactSet", + "facts": [ + { + "title": "Results:", + "value": "2 / 5 Passed (40%)" + }, + { + "title": "Duration:", + "value": "3:22" + } + ] + }, + 'TEAMS_SUITE_IOS_RESULTS': { + "type": "FactSet", + "facts": [ + { + "title": "Results:", + "value": "2 / 5 Passed (40%)" + }, + { + "title": "Duration:", + "value": "9:05" + } + ] + }, +}); addInteractionHandler('post test-summary to teams', () => { return { @@ -16,24 +111,10 @@ addInteractionHandler('post test-summary to teams', () => { "version": "1.0", "body": [ { - "type": "TextBlock", - "text": "✅ Default suite", - "size": "medium", - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE" }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "4 / 4 Passed (100%)" - }, - { - "title": "Duration:", - "value": "0:02" - } - ] + "@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_SINGLE_SUITE", } ], "actions": [] @@ -64,64 +145,25 @@ addInteractionHandler('post test-summary to teams with multiple suites', () => { "version": "1.0", "body": [ { - "type": "TextBlock", - "text": "Regression Tests", - "size": "medium", - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE", + "@OVERRIDES@": { + "text": "Regression Tests", + }, }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "8 / 20 Passed (40%)" - }, - { - "title": "Duration:", - "value": "23:23" - } - ] + "@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_MULTIPLE_SUITES", }, { - "type": "TextBlock", - "text": "❌ desktop-chrome", - "isSubtle": true, - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_SUITE_CHROME_TITLE", }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "2 / 5 Passed (40%)" - }, - { - "title": "Duration:", - "value": "3:22" - } - ] + "@DATA:TEMPLATE@": "TEAMS_SUITE_CHROME_RESULTS", }, { - "type": "TextBlock", - "text": "❌ mobile-ios", - "isSubtle": true, - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_SUITE_IOS_TITLE", }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "2 / 5 Passed (40%)" - }, - { - "title": "Duration:", - "value": "9:05" - } - ] + "@DATA:TEMPLATE@": "TEAMS_SUITE_IOS_RESULTS", } ], "actions": [] @@ -152,24 +194,13 @@ addInteractionHandler('post test-summary-slim to teams with multiple suites', () "version": "1.0", "body": [ { - "type": "TextBlock", - "text": "❌ Regression Tests", - "size": "medium", - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE", + "@OVERRIDES@": { + "text": "❌ Regression Tests", + }, }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "8 / 20 Passed (40%)" - }, - { - "title": "Duration:", - "value": "23:23" - } - ] + "@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_MULTIPLE_SUITES", } ], "actions": [] @@ -200,44 +231,19 @@ addInteractionHandler('post failure-details to teams with multiple suites', () = "version": "1.0", "body": [ { - "type": "TextBlock", - "text": "Regression Tests", - "size": "medium", - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE", + "@OVERRIDES@": { + "text": "Regression Tests", + }, }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "8 / 20 Passed (40%)" - }, - { - "title": "Duration:", - "value": "23:23" - } - ] + "@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_MULTIPLE_SUITES", }, { - "type": "TextBlock", - "text": "❌ desktop-chrome", - "isSubtle": true, - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_SUITE_CHROME_TITLE", }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "2 / 5 Passed (40%)" - }, - { - "title": "Duration:", - "value": "3:22" - } - ] + "@DATA:TEMPLATE@": "TEAMS_SUITE_CHROME_RESULTS", }, { "type": "FactSet", @@ -279,24 +285,10 @@ addInteractionHandler('post failure-details to teams with multiple suites', () = ] }, { - "type": "TextBlock", - "text": "❌ mobile-ios", - "isSubtle": true, - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_SUITE_IOS_TITLE", }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "2 / 5 Passed (40%)" - }, - { - "title": "Duration:", - "value": "9:05" - } - ] + "@DATA:TEMPLATE@": "TEAMS_SUITE_IOS_RESULTS" }, { "type": "FactSet", @@ -366,24 +358,10 @@ addInteractionHandler('post failure-details to teams with single suite', () => { "version": "1.0", "body": [ { - "type": "TextBlock", - "text": "❌ Default suite", - "size": "medium", - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE_FAILURE" }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "3 / 4 Passed (75%)" - }, - { - "title": "Duration:", - "value": "0:02" - } - ] + "@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_SINGLE_SUITE_FAILURES" }, { "type": "FactSet", @@ -427,24 +405,10 @@ addInteractionHandler('post test-summary with hyperlinks to teams - pass status' "version": "1.0", "body": [ { - "type": "TextBlock", - "text": "✅ Default suite", - "size": "medium", - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE" }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "4 / 4 Passed (100%)" - }, - { - "title": "Duration:", - "value": "0:02" - } - ] + "@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_SINGLE_SUITE", }, { "type": "TextBlock", @@ -481,24 +445,10 @@ addInteractionHandler('post test-summary with hyperlinks to teams - fail status' "version": "1.0", "body": [ { - "type": "TextBlock", - "text": "❌ Default suite", - "size": "medium", - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE_FAILURE" }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "3 / 4 Passed (75%)" - }, - { - "title": "Duration:", - "value": "0:02" - } - ] + "@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_SINGLE_SUITE_FAILURES" }, { "type": "TextBlock", @@ -535,24 +485,10 @@ addInteractionHandler('post test-summary with hyperlinks having a title and with "version": "1.0", "body": [ { - "type": "TextBlock", - "text": "✅ Default suite", - "size": "medium", - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE" }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "4 / 4 Passed (100%)" - }, - { - "title": "Duration:", - "value": "0:02" - } - ] + "@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_SINGLE_SUITE", }, { "type": "TextBlock", @@ -596,24 +532,10 @@ addInteractionHandler('post test-summary to teams with report portal analysis', "version": "1.0", "body": [ { - "type": "TextBlock", - "text": "❌ Default suite", - "size": "medium", - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE_FAILURE" }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "3 / 4 Passed (75%)" - }, - { - "title": "Duration:", - "value": "0:02" - } - ] + "@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_SINGLE_SUITE_FAILURES" }, { "type": "TextBlock", @@ -657,24 +579,10 @@ addInteractionHandler('post test-summary to teams with report portal analysis wi "version": "1.0", "body": [ { - "type": "TextBlock", - "text": "❌ Default suite", - "size": "medium", - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE_FAILURE" }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "3 / 4 Passed (75%)" - }, - { - "title": "Duration:", - "value": "0:02" - } - ] + "@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_SINGLE_SUITE_FAILURES" }, { "type": "TextBlock", @@ -718,24 +626,10 @@ addInteractionHandler('post test-summary to teams with mentions', () => { "version": "1.0", "body": [ { - "type": "TextBlock", - "text": "❌ Default suite", - "size": "medium", - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE_FAILURE" }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "3 / 4 Passed (75%)" - }, - { - "title": "Duration:", - "value": "0:02" - } - ] + "@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_SINGLE_SUITE_FAILURES" }, { "type": "TextBlock", @@ -798,24 +692,10 @@ addInteractionHandler('post test-summary to teams with qc-test-summary', (ctx) = "type": "Column", "items": [ { - "type": "TextBlock", - "text": "❌ Default suite", - "size": "medium", - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE_FAILURE" }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "3 / 4 Passed (75%)" - }, - { - "title": "Duration:", - "value": "0:02" - } - ] + "@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_SINGLE_SUITE_FAILURES" } ], "width": "stretch" @@ -863,24 +743,10 @@ addInteractionHandler('post test-summary to teams with report portal history', ( "version": "1.0", "body": [ { - "type": "TextBlock", - "text": "❌ Default suite", - "size": "medium", - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE_FAILURE" }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "3 / 4 Passed (75%)" - }, - { - "title": "Duration:", - "value": "0:02" - } - ] + "@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_SINGLE_SUITE_FAILURES" }, { "type": "TextBlock", @@ -924,24 +790,10 @@ addInteractionHandler('post test-summary to teams with report portal history wit "version": "1.0", "body": [ { - "type": "TextBlock", - "text": "❌ Default suite", - "size": "medium", - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE_FAILURE" }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "3 / 4 Passed (75%)" - }, - { - "title": "Duration:", - "value": "0:02" - } - ] + "@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_SINGLE_SUITE_FAILURES" }, { "type": "TextBlock", @@ -978,24 +830,10 @@ addInteractionHandler('post test-summary to teams with full width', () => { "version": "1.0", "body": [ { - "type": "TextBlock", - "text": "✅ Default suite", - "size": "medium", - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE" }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "4 / 4 Passed (100%)" - }, - { - "title": "Duration:", - "value": "0:02" - } - ] + "@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_SINGLE_SUITE", } ], "actions": [], @@ -1029,11 +867,10 @@ addInteractionHandler('post test-summary-slim with verbose duration', () => { "version": "1.0", "body": [ { - "type": "TextBlock", - "text": "❌ Regression Tests", - "size": "medium", - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE", + "@OVERRIDES@": { + "text": "❌ Regression Tests", + }, }, { "type": "FactSet", @@ -1077,24 +914,10 @@ addInteractionHandler('post test-summary to teams with percy analysis', () => { "version": "1.0", "body": [ { - "type": "TextBlock", - "text": "❌ Default suite", - "size": "medium", - "weight": "bolder", - "wrap": true + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE_FAILURE" }, { - "type": "FactSet", - "facts": [ - { - "title": "Results:", - "value": "3 / 4 Passed (75%)" - }, - { - "title": "Duration:", - "value": "0:02" - } - ] + "@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_SINGLE_SUITE_FAILURES" }, { "type": "TextBlock", @@ -1120,4 +943,41 @@ addInteractionHandler('post test-summary to teams with percy analysis', () => { status: 200 } } +}); + +addInteractionHandler('post test-summary to teams with title_link', () => { + return { + request: { + method: 'POST', + path: '/message', + body: { + "type": "message", + "attachments": [ + { + "contentType": "application/vnd.microsoft.card.adaptive", + "content": { + "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", + "type": "AdaptiveCard", + "version": "1.0", + "body": [ + { + "@DATA:TEMPLATE@": "TEAMS_ROOT_TITLE_SINGLE_SUITE", + "@OVERRIDES@": { + "text": "[✅ Default suite](some-url)", + } + }, + { + "@DATA:TEMPLATE@": "TEAMS_ROOT_RESULTS_SINGLE_SUITE", + } + ], + "actions": [] + } + } + ] + } + }, + response: { + status: 200 + } + } }); \ No newline at end of file diff --git a/test/targets.chat.spec.js b/test/targets.chat.spec.js index f226ebf..48a97d7 100644 --- a/test/targets.chat.spec.js +++ b/test/targets.chat.spec.js @@ -152,6 +152,36 @@ describe('targets - google chat', () => { assert.equal(mock.getInteraction(id).exercised, true); }); + it('should send test-summary with title_link', async () => { + const id = mock.addInteraction('post test-summary to chat with title_link'); + await publish({ + config: { + "reports": [ + { + "targets": [ + { + "name": "chat", + "inputs": { + "url": "http://localhost:9393/message", + "title_link": "some-url" + } + } + ], + "results": [ + { + "type": "testng", + "files": [ + "test/data/testng/single-suite.xml" + ] + } + ] + } + ] + } + }); + assert.equal(mock.getInteraction(id).exercised, true); + }); + afterEach(() => { mock.clearInteractions(); }); diff --git a/test/targets.slack.spec.js b/test/targets.slack.spec.js index 1c1027d..a598f26 100644 --- a/test/targets.slack.spec.js +++ b/test/targets.slack.spec.js @@ -152,6 +152,36 @@ describe('targets - slack', () => { assert.equal(mock.getInteraction(id).exercised, true); }); + it('should send test-summary with title_link', async () => { + const id = mock.addInteraction('post test-summary to slack with title_link'); + await publish({ + config: { + "reports": [ + { + "targets": [ + { + "name": "slack", + "inputs": { + "url": "http://localhost:9393/message", + "title_link": "some-url" + } + } + ], + "results": [ + { + "type": "testng", + "files": [ + "test/data/testng/single-suite.xml" + ] + } + ] + } + ] + } + }); + assert.equal(mock.getInteraction(id).exercised, true); + }); + afterEach(() => { mock.clearInteractions(); }); diff --git a/test/targets.teams.spec.js b/test/targets.teams.spec.js index 8c34fbc..97e9d11 100644 --- a/test/targets.teams.spec.js +++ b/test/targets.teams.spec.js @@ -152,7 +152,7 @@ describe('targets - teams', () => { assert.equal(mock.getInteraction(id).exercised, true); }); - it('should send test-summary', async () => { + it('should send test-summary with full width', async () => { const id = mock.addInteraction('post test-summary to teams with full width'); await publish({ config: { @@ -213,6 +213,36 @@ describe('targets - teams', () => { assert.equal(mock.getInteraction(id).exercised, true); }); + it('should send test-summary with title_link', async () => { + const id = mock.addInteraction('post test-summary to teams with title_link'); + await publish({ + config: { + "reports": [ + { + "targets": [ + { + "name": "teams", + "inputs": { + "url": "http://localhost:9393/message", + "title_link": "some-url" + } + } + ], + "results": [ + { + "type": "testng", + "files": [ + "test/data/testng/single-suite.xml" + ] + } + ] + } + ] + } + }); + assert.equal(mock.getInteraction(id).exercised, true); + }); + afterEach(() => { mock.clearInteractions(); });