Skip to content

Commit

Permalink
feat: add additional test for section with ####
Browse files Browse the repository at this point in the history
Add additional test for section with #### to prevent and catch in
future code change that would produce wrong parsing.

Signed-off-by: Christian Marangi <[email protected]>
  • Loading branch information
Ansuel committed Apr 26, 2024
1 parent 66ffdc2 commit 4a7eb3e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fixtures/paragraph-confusing-####/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"textarea-one": "Textarea input text 1 ####"
}
9 changes: 9 additions & 0 deletions fixtures/paragraph-confusing-####/form.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
body:
- type: textarea
id: textarea-one
attributes:
label: My textarea input
- type: textarea
id: textarea-two
attributes:
label: Another textarea input
3 changes: 3 additions & 0 deletions fixtures/paragraph-confusing-####/issue-body.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### My textarea input

Textarea input text 1 ####
6 changes: 6 additions & 0 deletions fixtures/paragraph-confusing-####/issue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { resolve } = require("path");
const { readFileSync } = require("fs");

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

module.exports = readFileSync(issueBodyPath, "utf-8")
39 changes: 39 additions & 0 deletions test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,45 @@ it("multiple paragraphs", () => {
expect(core.setOutput.mock.calls.length).toBe(3)
});

it("paragraph with confusing ####", () => {
const expectedOutput = require("./fixtures/paragraph-confusing-####/expected.json");
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);

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

// mock event payload
const eventPayload = require("./fixtures/paragraph-confusing-####/issue");

// mock fs
const fs = {
readFileSync(path, encoding) {
expect(path).toBe("<template-path>");
expect(encoding).toBe("utf8");
return readFileSync("fixtures/paragraph-confusing-####/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: jest.fn(() => '<template-path>'),
setOutput: jest.fn(),
};

run(env, eventPayload, fs, core);

expect(core.getInput).toHaveBeenCalledWith('template-path')
expect(core.setOutput).toHaveBeenCalledWith('jsonString', JSON.stringify(expectedOutput, null, 2))
expect(core.setOutput).toHaveBeenCalledWith('issueparser_textarea-one', 'Textarea input text 1 ####')
expect(core.setOutput.mock.calls.length).toBe(2)
});

it("blank", () => {
const expectedOutput = require("./fixtures/blank/expected.json");
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);
Expand Down

0 comments on commit 4a7eb3e

Please sign in to comment.