Skip to content

Commit

Permalink
Merge pull request #20 from Staffbase/truncate-test-environment-title
Browse files Browse the repository at this point in the history
Truncate test environment title
  • Loading branch information
jreimone authored Jul 10, 2023
2 parents 5ed3dba + 44e909f commit a043a87
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ export class Util {

public static convertPrepareObjectToTestIOPayload(prepareObject: any, repo: string, owner: string, pr: number, prTitle: string): any {
// 80 is restriction from TestIO
const titleBase = Util.truncateString(`[${owner}/${repo}/${pr}]${prTitle}`, 80);
const titleBase = `[${owner}/${repo}/${pr}]${prTitle}`;
const testioPayload = {
exploratory_test: {
test_title: titleBase,
test_title: Util.truncateString(titleBase, 80, "...", false),
test_environment: {
title: `${titleBase} [test environment]`,
title: Util.truncateString(titleBase, 80, "[test environment]", false),
url: prepareObject.test_environment.url,
access: prepareObject.test_environment.access,
},
Expand Down Expand Up @@ -118,11 +118,11 @@ export class Util {
return matches[1];
}

public static truncateString(string: string, maxLength: number) {
public static truncateString(string: string, maxLength: number, suffix: string, forceAddSuffix: boolean) {
if (string.length <= maxLength) {
return string;
}

return string.slice(0, maxLength - 4) + "...";
return string.slice(0, maxLength - suffix.length - 1) + suffix;
}
}
8 changes: 6 additions & 2 deletions test/Util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ describe("TestIO Trigger-from-PR logic", () => {
it('should truncate looooooong PR titles with ellipsis', () => {
const maxLength= 80;
let prTitle = "This is my short title";
let truncatedString = Util.truncateString(prTitle, maxLength);
let truncatedString = Util.truncateString(prTitle, maxLength, "...", false);
expect(truncatedString).toBe(prTitle);

prTitle = "This is my veryyyyyyyy loooooooooooooooooooooooooooooooooooooooooooooooooong PR title";
truncatedString = Util.truncateString(prTitle, maxLength);
truncatedString = Util.truncateString(prTitle, maxLength, "...", false);
expect(truncatedString).toBe("This is my veryyyyyyyy loooooooooooooooooooooooooooooooooooooooooooooooooong...");

prTitle = "This is my veryyyyyyyy loooooooooooooooooooooooooooooooooooooooooooooooooooooooong PR title";
truncatedString = Util.truncateString(prTitle, maxLength, "[test environment]", true);
expect(truncatedString).toBe("This is my veryyyyyyyy looooooooooooooooooooooooooooooooooooo[test environment]");
});

});

0 comments on commit a043a87

Please sign in to comment.