Skip to content

Commit

Permalink
refactor(test): add labeler.ts tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Apr 22, 2024
1 parent e09680e commit 3df0d0f
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 71 deletions.
54 changes: 54 additions & 0 deletions test/unit/config.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
export const emptyConfig = {};

export const basicConfig = {
policy: [
{
section: [
{
id: ['type'],
label: [
{ name: 'bug 🐛', keys: ['Bug Report'] },
{ name: 'RFE 🎁', keys: ['Feature Request'] },
],
},
],
},
],
};

export const templateConfig = {
policy: [
{
template: ['bug.yml', 'feature.yml'],
section: [
{
id: ['type'],
label: [
{ name: 'bug 🐛', keys: ['Bug Report'] },
{ name: 'RFE 🎁', keys: ['Feature Request'] },
],
},
{
id: ['severity'],
label: [
{ name: 'high', keys: ['High'] },
{ name: 'medium', keys: ['Medium'] },
{ name: 'low', keys: ['Low'] },
],
},
],
},
{
template: ['custom.yml'],
section: [
{
id: ['type'],
label: [
{ name: 'custom1', keys: ['Custom 1'] },
{ name: 'custom2', keys: ['Custom 2'] },
],
},
],
},
],
};
75 changes: 28 additions & 47 deletions test/unit/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,10 @@ import { describe, expect, test } from 'vitest';

import { Config } from '../../src/config';

const emptyConfig = {};

const basicConfig = {
policy: [
{
section: [
{
id: ['type'],
label: [
{ name: 'bug 🐛', keys: ['Bug Report'] },
{ name: 'RFE 🎁', keys: ['Feature Request'] },
],
},
],
},
],
};

const templateConfig = {
policy: [
{
template: ['bug.yml', 'feature.yml'],
section: [
{
id: ['type'],
label: [
{ name: 'bug 🐛', keys: ['Bug Report'] },
{ name: 'RFE 🎁', keys: ['Feature Request'] },
],
},
],
},
{
template: ['custom.yml'],
section: [
{
id: ['type'],
label: [
{ name: 'custom1', keys: ['Custom 1'] },
{ name: 'custom2', keys: ['Custom 2'] },
],
},
],
},
],
};
import { basicConfig, emptyConfig, templateConfig } from './config.fixture';

describe('Test Config class', () => {
test('Config class is defined', () => {
test('smoke test', () => {
const config = new Config(basicConfig, '.github/issue-labeler.yml');

expect(config.policy).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -201,6 +156,32 @@ describe('Test Config class', () => {
},
],
},
{
"block-list": [],
"id": [
"severity",
],
"label": [
{
"keys": [
"High",
],
"name": "high",
},
{
"keys": [
"Medium",
],
"name": "medium",
},
{
"keys": [
"Low",
],
"name": "low",
},
],
},
],
"template": [
"bug.yml",
Expand Down
14 changes: 14 additions & 0 deletions test/unit/issue-form.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const emptyForm = {};

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

export const dropdownForm = {
title: 'Test issue',
body: 'Test body',
severity: 'High',
type: 'Bug Report, Feature Request, other, none',
checkList: ['one', 'two', 'three'],
};
34 changes: 10 additions & 24 deletions test/unit/issue-form.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
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'],
};
import { basicForm, dropdownForm } from './issue-form.fixture';

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

expect(issueForm.parsed).toMatchInlineSnapshot(`
Expand All @@ -43,7 +29,7 @@ describe('Test IssueForm class', () => {
`"Test issue"`
);
expect(issueForm.getSafeProperty('severity')).toMatchInlineSnapshot(
`"high"`
`"High"`
);
expect(issueForm.getSafeProperty('nonexistent')).toBeUndefined();
});
Expand All @@ -53,17 +39,17 @@ describe('Test IssueForm class', () => {

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

expect(issueForm.listKeywords('multiDropdown', ['other', 'none']))
expect(issueForm.listKeywords('type', ['other', 'none']))
.toMatchInlineSnapshot(`
[
"one",
"two",
]
`);
[
"Bug Report",
"Feature Request",
]
`);

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

0 comments on commit 3df0d0f

Please sign in to comment.