Skip to content

Commit

Permalink
test: multiple paragraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Sep 12, 2021
1 parent 3e0e2b4 commit a19bc3d
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fixtures/multiple-paragraphs/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"textarea": "1st paragraph\n\n2nd paragraph"
}
5 changes: 5 additions & 0 deletions fixtures/multiple-paragraphs/form.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
body:
- type: textarea
id: textarea
attributes:
label: My textarea input
5 changes: 5 additions & 0 deletions fixtures/multiple-paragraphs/issue-body.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### My textarea input

1st paragraph

2nd paragraph
10 changes: 10 additions & 0 deletions fixtures/multiple-paragraphs/issue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { resolve } = require("path");
const { readFileSync } = require("fs");

const issueBodyPath = resolve(__dirname, "issue-body.md");

module.exports = {
issue: {
body: readFileSync(issueBodyPath, "utf-8"),
},
};
50 changes: 50 additions & 0 deletions test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,53 @@ it("readme example", () => {

run(env, eventPayload, fs, core);
});

it("multiple paragraphs", () => {
const expectedOutput = require("./fixtures/multiple-paragraphs/expected.json");
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);

// mock ENV
const env = {
HOME: "<home path>",
};

// mock event payload
const eventPayload = require("./fixtures/multiple-paragraphs/issue");

// mock fs
const fs = {
readFileSync(path, encoding) {
expect(path).toBe("<template-path>");
expect(encoding).toBe("utf8");
return readFileSync("fixtures/multiple-paragraphs/form.yml", "utf-8");
},
writeFileSync(path, content) {
expect(path).toBe("<home path>/issue-parser-result.json");
expect(content).toBe(expectedOutputJson);
},
};

// mock core
const core = {
getInput(inputName) {
expect(inputName).toBe("template-path");
return "<template-path>";
},
setOutput(outputName, outputValue) {
if (outputName === "jsonString") {
expect(outputValue).toBe(expectedOutputJson);
return;
}

if (outputName.startsWith("issueparser_")) {
const key = outputName.substr("issueparser_".length);
expect(Object.keys(expectedOutput)).toContain(key);

expect(outputValue).toBe(expectedOutput[key]);
return;
}
},
};

run(env, eventPayload, fs, core);
});

0 comments on commit a19bc3d

Please sign in to comment.