Skip to content

Commit

Permalink
feat: title links
Browse files Browse the repository at this point in the history
  • Loading branch information
ASaiAnudeep committed Jul 9, 2022
1 parent 86abe18 commit f274571
Show file tree
Hide file tree
Showing 10 changed files with 436 additions and 453 deletions.
22 changes: 10 additions & 12 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}

Expand Down
3 changes: 3 additions & 0 deletions src/targets/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<a href="${target.inputs.title_link}">${title_text_with_emoji}</a>`;
}
const text = `<b>${title_text_with_emoji}</b><br><br><b>Results</b>: ${result_text}<br><b>Duration</b>: ${duration_text}`;
payload.sections.push({
"widgets": [
Expand Down
9 changes: 6 additions & 3 deletions src/targets/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 7 additions & 4 deletions src/targets/teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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 = '';
Expand All @@ -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,
Expand All @@ -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];
Expand Down
61 changes: 45 additions & 16 deletions test/mocks/chat.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { addInteractionHandler } = require('pactum').handler;
const { addDataTemplate } = require('pactum').stash;

addDataTemplate({
'RESULT_SINGLE_SUITE': {
'CHAT_RESULT_SINGLE_SUITE': {
"widgets": [
{
"textParagraph": {
Expand All @@ -11,7 +11,7 @@ addDataTemplate({
}
]
},
'RESULT_SINGLE_SUITE_FAILURES': {
'CHAT_RESULT_SINGLE_SUITE_FAILURES': {
"widgets": [
{
"textParagraph": {
Expand All @@ -20,7 +20,7 @@ addDataTemplate({
}
]
},
'RESULT_MULTIPLE_SUITE_FAILURES': {
'CHAT_RESULT_MULTIPLE_SUITE_FAILURES': {
"widgets": [
{
"textParagraph": {
Expand All @@ -29,7 +29,7 @@ addDataTemplate({
}
]
},
'RESULT_MULTIPLE_SUITE_FAILURES_WITH_EMOJI': {
'CHAT_RESULT_MULTIPLE_SUITE_FAILURES_WITH_EMOJI': {
"widgets": [
{
"textParagraph": {
Expand Down Expand Up @@ -83,7 +83,7 @@ addInteractionHandler('post test-summary to chat', () => {
{
"sections": [
{
"@DATA:TEMPLATE@": "RESULT_SINGLE_SUITE"
"@DATA:TEMPLATE@": "CHAT_RESULT_SINGLE_SUITE"
}
]
}
Expand All @@ -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"
Expand All @@ -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"
}
]
}
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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": [
Expand Down Expand Up @@ -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"
}
]
}
Expand All @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand All @@ -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": "<b><a href=\"some-url\">✅ Default suite</a></b><br><br><b>Results</b>: 4 / 4 Passed (100%)<br><b>Duration</b>: 0:02"
}
}
]
}
]
}
]
}
},
response: {
status: 200
}
}
});
Loading

0 comments on commit f274571

Please sign in to comment.