Skip to content

Commit

Permalink
test: extend tests for issue-form.ts and labeler.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Dec 14, 2022
1 parent 281bf7c commit 6ee6fdd
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 14 deletions.
86 changes: 86 additions & 0 deletions test/unit/__snapshots__/issue-form.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Vitest Snapshot v1

exports[`IssueForm Object > getProperty() 1`] = `undefined`;

exports[`IssueForm Object > getProperty() 2`] = `"Security guidelines provided by GitHub: [Security hardening for GitHub Actions ](https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#overview)"`;

exports[`IssueForm Object > getProperty() 3`] = `undefined`;

exports[`IssueForm Object > getSafeProperty() 1`] = `undefined`;

exports[`IssueForm Object > getSafeProperty() 2`] = `"Security guidelines provided by GitHub: [Security hardening for GitHub Actions ](https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#overview)"`;

exports[`IssueForm Object > getSafeProperty() 3`] = `undefined`;

exports[`IssueForm Object > isProperty() 1`] = `false`;

exports[`IssueForm Object > isProperty() 2`] = `true`;

exports[`IssueForm Object > isProperty() 3`] = `false`;

exports[`IssueForm Object > listKeywords() 1`] = `undefined`;

exports[`IssueForm Object > listKeywords() 2`] = `undefined`;

exports[`IssueForm Object > listKeywords() 3`] = `undefined`;

exports[`IssueForm Object > listKeywords() 4`] = `undefined`;

exports[`IssueForm Object > listKeywords() 5`] = `undefined`;

exports[`IssueForm Object > listKeywords() 6`] = `undefined`;

exports[`IssueForm Object > listKeywords() 7`] = `
[
"Feature Request",
"none",
"other",
]
`;

exports[`IssueForm Object > listKeywords() 8`] = `undefined`;

exports[`IssueForm Object > listKeywords() 9`] = `
[
"Feature Request",
"none",
]
`;

exports[`IssueForm Object > listKeywords() 10`] = `undefined`;

exports[`IssueForm Object > listKeywords() 11`] = `
[
"Feature Request",
]
`;

exports[`IssueForm Object > listKeywords() 12`] = `undefined`;

exports[`IssueForm Object > listKeywords() 13`] = `undefined`;

exports[`IssueForm Object > listKeywords() 14`] = `
[
"bootctl",
"systemd-boot",
"other",
]
`;

exports[`IssueForm Object > listKeywords() 15`] = `undefined`;

exports[`IssueForm Object > listKeywords() 16`] = `
[
"bootctl",
"systemd-boot",
]
`;

exports[`IssueForm Object > listKeywords() 17`] = `undefined`;

exports[`IssueForm Object > listKeywords() 18`] = `
[
"bootctl",
"systemd-boot",
]
`;
2 changes: 2 additions & 0 deletions test/unit/__snapshots__/labeler.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Vitest Snapshot v1

exports[`IssueForm Object > gatherLabels() 1`] = `undefined`;

exports[`IssueForm Object > get config() 1`] = `undefined`;

exports[`IssueForm Object > get inputs() 1`] = `
Expand Down
47 changes: 47 additions & 0 deletions test/unit/fixtures/issue-form.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { IssueForm } from '../../../src/issue-form';

export interface IIssueFormTestContext {
issueForms: IssueForm[];
blockLists: string[][];
invalid: IssueForm[];
}

export const issueFormContextFixture: IIssueFormTestContext = {
issueForms: [
new IssueForm({}),
// issue: https://github.com/redhat-plumbers-in-action/advanced-issue-labeler/issues/171
new IssueForm({
type: 'Feature Request, none, other',
description:
'Security guidelines provided by GitHub: [Security hardening for GitHub Actions ](https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#overview)',
solution:
"Let's review the document from GitHub regarding GitHub Actions and security. And make Advanced Issue Labeler more secure!\n\nSecurity is a long-term goal, not one of, so it would be great to have some ci check or checkbox in the Pull Request template to ensure that when reviewing new code, we comply with best security policies and guidelines.",
}),
// issue: https://github.com/systemd/systemd/issues/25737
new IssueForm({
version: '252.3-1',
distro: 'Arch Linux',
kernel: '6.0.12-arch1-1 and 5.15.82-1-lts',
architecture: 'x86_64',
component: 'bootctl, systemd-boot, other',
'expected-behaviour': 'System booting correctly with systemd-boot.',
'unexpected-behaviour':
'System hangs immediately after choosing the boot-entry, just showing a black screen with the following message in top left corner in red letters:\n\nFailed to open random seed file: Media changed\r\nError opening root path: Invalid Parameter',
'steps-to-reproduce':
"- Coming from systemd 251.7-4 (which worked flawlessly) and updating to 252.3-1.\r\n- Running 'bootctl update'\r\n- Reboot\n\nUpdating to 252.3-1 WITHOUT running 'bootctl update' afterwards works fine. The system boots without any problems.\n\nSo the problem seems really systemd-boot related. Maybe something in 'systemd-bootx64.efi\" have changed and my Lenovo E15 Gen 2 doesn't like that.",
'additional-information': '',
}),
],

blockLists: [[], ['other'], ['block1', 'block2', 'other', 'none']],

invalid: [
// @ts-expect-error: Let's ignore a type error, it's required for testing
new IssueForm(),
// @ts-expect-error: Let's ignore a type error, it's required for testing
new IssueForm(undefined),
// @ts-expect-error: Let's ignore a type error, it's required for testing
new IssueForm(null),
new IssueForm('form'),
],
};
80 changes: 69 additions & 11 deletions test/unit/issue-form.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,80 @@ import { describe, it, expect, beforeEach, test } from 'vitest';

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

import {
IIssueFormTestContext,
issueFormContextFixture,
} from './fixtures/issue-form.fixture';

describe('IssueForm Object', () => {
let issueForms: IssueForm[];
beforeEach<IIssueFormTestContext>(context => {
context.issueForms = issueFormContextFixture.issueForms;
context.blockLists = issueFormContextFixture.blockLists;
context.invalid = issueFormContextFixture.invalid;
});

it<IIssueFormTestContext>('can be instantiated', context =>
context.issueForms.map(issueFormItem =>
expect(issueFormItem).toBeDefined()
));

// private
test.todo('get parsed()');

test<IIssueFormTestContext>('isProperty()', context => {
context.issueForms.map(issueFormItem => {
expect(issueFormItem.isProperty('')).toEqual(false);
expect(issueFormItem.isProperty('description')).toMatchSnapshot();
});

beforeEach(() => {
issueForms = [new IssueForm({})];
let issueForm = new IssueForm({ section: 'content' });
expect(issueForm.isProperty('section')).toEqual(true);
});

it('can be instantiated', () => {
issueForms.map(item => expect(item).toBeDefined());
test<IIssueFormTestContext>('getProperty()', context => {
context.issueForms.map(issueFormItem => {
expect(issueFormItem.getProperty('')).toBeUndefined();
expect(issueFormItem.getProperty('description')).toMatchSnapshot();
});

let issueForm = new IssueForm({ section: 'content' });
expect(issueForm.getProperty('section')).toEqual('content');
});

test.todo('get parsed()');
test<IIssueFormTestContext>('getSafeProperty()', context => {
context.issueForms.map(issueFormItem => {
expect(issueFormItem.getSafeProperty('')).toBeUndefined();
expect(issueFormItem.getSafeProperty('description')).toMatchSnapshot();
});

test.todo('isProperty()');
test.todo('getProperty()');
test.todo('getSafeProperty()');
test.todo('listKeywords()');
test.todo('isCompliant()');
let issueForm = new IssueForm({ section: 'content' });
expect(issueForm.getSafeProperty('section')).toEqual('content');
});

test<IIssueFormTestContext>('listKeywords()', context => {
context.issueForms.map(issueFormItem =>
context.blockLists.map(blockListItem => {
expect(
issueFormItem.listKeywords('type', blockListItem)
).toMatchSnapshot();
expect(
issueFormItem.listKeywords('component', blockListItem)
).toMatchSnapshot();
})
);
});

test('isCompliant()', () => {
const issueForm = new IssueForm({});
// @ts-expect-error: Let's ignore a type error, it's required for testing
expect(issueForm.isCompliant(['item1'], undefined)).toEqual(false);

expect(issueForm.isCompliant(['item1', 'item2', 'item3'], 'item1')).toEqual(
true
);

expect(issueForm.isCompliant(['item1', 'item2', 'item3'], 'item4')).toEqual(
false
);
});
});
14 changes: 11 additions & 3 deletions test/unit/labeler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('IssueForm Object', () => {
test.todo('set inputs()');

test('setInputs()', () => {
//! FIXME: There is probably a better way how to do this ...
let labeler = new Labeler(new IssueForm({}));
labeler.setInputs({ section: 'section' });
expect(labeler.inputs).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -111,7 +112,10 @@ describe('IssueForm Object', () => {
test.todo('get issueForm()');
test.todo('set issueForm()');

test.todo('gatherLabels()');
test<ILabelerTestContext>('gatherLabels()', context =>
context.labelers.map(labelerItem =>
expect(labelerItem.gatherLabels()).toMatchSnapshot()
));

// private
test.todo('inputBasedLabels()');
Expand All @@ -120,8 +124,12 @@ describe('IssueForm Object', () => {
it<ILabelerTestContext>('is valid', async context =>
context.labelers.map(async labelerItem => {
//! FIXME: There is probably a better way how to do this ...
labelerItem.setInputs({ section: 'section' });
expect(Labeler.validate(labelerItem)).resolves.toMatchObject([]);
let localLabeler = Object.assign(
Object.create(Object.getPrototypeOf(labelerItem)),
labelerItem
);
localLabeler.setInputs({ section: 'section' });
expect(Labeler.validate(localLabeler)).resolves.toMatchObject([]);
}));

it<ILabelerTestContext>('is invalid', async context =>
Expand Down

0 comments on commit 6ee6fdd

Please sign in to comment.