Skip to content

Commit

Permalink
refactor(test): add issue-form.ts tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Apr 22, 2024
1 parent 7508c5f commit e09680e
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 16 deletions.
5 changes: 1 addition & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/issue-form.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions dist/issue-form.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/issue-form.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/issue-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ export class IssueForm {
return this.parsed.hasOwnProperty(key);
}

getProperty(key: string) {
return this.parsed[key];
}

getSafeProperty(key: string) {
if (!this.isProperty(key)) return undefined;

return this.getProperty(key);
return this.parsed[key];
}

listKeywords(key: string, blockList: string[]) {
Expand Down
72 changes: 72 additions & 0 deletions test/unit/issue-form.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { describe, expect, test } from 'vitest';

import { IssueForm } from '../../src/issue-form';

const emptyForm = {};

const basicForm = {
title: 'Test issue',
body: 'Test body',
};

const dropdownForm = {
title: 'Test issue',
body: 'Test body',
severity: 'high',
multiDropdown: 'one, two, other, none',
checkList: ['one', 'two', 'three'],
};

describe('Test IssueForm class', () => {
test('IssueForm class is defined', () => {
const issueForm = new IssueForm(basicForm);

expect(issueForm.parsed).toMatchInlineSnapshot(`
{
"body": "Test body",
"title": "Test issue",
}
`);
});

test('isProperty()', () => {
const issueForm = new IssueForm(basicForm);

expect(issueForm.isProperty('title')).toBe(true);
expect(issueForm.isProperty('nonexistent')).toBe(false);
});

test('getSafeProperty()', () => {
const issueForm = new IssueForm(dropdownForm);

expect(issueForm.getSafeProperty('title')).toMatchInlineSnapshot(
`"Test issue"`
);
expect(issueForm.getSafeProperty('severity')).toMatchInlineSnapshot(
`"high"`
);
expect(issueForm.getSafeProperty('nonexistent')).toBeUndefined();
});

test('listKeywords()', () => {
const issueForm = new IssueForm(dropdownForm);

expect(issueForm.listKeywords('severity', ['none'])).toMatchInlineSnapshot(`
[
"high",
]
`);

expect(issueForm.listKeywords('multiDropdown', ['other', 'none']))
.toMatchInlineSnapshot(`
[
"one",
"two",
]
`);

// Checklists are unsupported at the moment
expect(issueForm.listKeywords('checkList', [])).toBeUndefined();
expect(issueForm.listKeywords('nonexistent', ['none'])).toBeUndefined();
});
});

0 comments on commit e09680e

Please sign in to comment.