Files
stale/src/functions/is-labeled.spec.ts
Geoffrey Testelin 324009e5d0 fix(label): allow to use spaces inside the labels (#199)
* chore(git): ignore .idea folder to avoid adding WebStorm files

* test(jest): find all spec files as well

* refactor(labels): create a dedicated function to parse the labels

at first I thought that the parseCommaSeparatedString method was causing the issue so I move it to a dedicated file to test it since it was private
also because I think that this repo could have more clean code and code splitting
anyway this was not the root of the #98 issue :/

* fix(label): allow to use spaces inside the labels

* docs(isLabeled): add JSDoc

* chore(npm): add lint:fix script
2020-11-20 06:48:33 -05:00

188 lines
4.2 KiB
TypeScript

import {Issue} from '../IssueProcessor';
import {isLabeled} from './is-labeled';
describe('isLabeled()', (): void => {
let issue: Issue;
let label: string;
describe('when the given issue contains no label', (): void => {
beforeEach((): void => {
issue = ({
labels: []
} as unknown) as Issue;
});
describe('when the given label is a simple label', (): void => {
beforeEach((): void => {
label = 'label';
});
it('should return false', (): void => {
expect.assertions(1);
const result = isLabeled(issue, label);
expect(result).toStrictEqual(false);
});
});
});
describe('when the given issue contains a simple label', (): void => {
beforeEach((): void => {
issue = {
labels: [
{
name: 'label'
}
]
} as Issue;
});
describe('when the given label is a simple label', (): void => {
beforeEach((): void => {
label = 'label';
});
it('should return true', (): void => {
expect.assertions(1);
const result = isLabeled(issue, label);
expect(result).toStrictEqual(true);
});
});
});
describe('when the given issue contains a kebab case label', (): void => {
beforeEach((): void => {
issue = {
labels: [
{
name: 'kebab-case-label'
}
]
} as Issue;
});
describe('when the given label is a kebab case label', (): void => {
beforeEach((): void => {
label = 'kebab-case-label';
});
it('should return true', (): void => {
expect.assertions(1);
const result = isLabeled(issue, label);
expect(result).toStrictEqual(true);
});
});
});
describe('when the given issue contains a multiple word label', (): void => {
beforeEach((): void => {
issue = {
labels: [
{
name: 'label like a sentence'
}
]
} as Issue;
});
describe('when the given label is a multiple word label', (): void => {
beforeEach((): void => {
label = 'label like a sentence';
});
it('should return true', (): void => {
expect.assertions(1);
const result = isLabeled(issue, label);
expect(result).toStrictEqual(true);
});
});
});
describe('when the given issue contains a multiple word label with %20 spaces', (): void => {
beforeEach((): void => {
issue = {
labels: [
{
name: 'label%20like%20a%20sentence'
}
]
} as Issue;
});
describe('when the given label is a multiple word label with %20 spaces', (): void => {
beforeEach((): void => {
label = 'label%20like%20a%20sentence';
});
it('should return true', (): void => {
expect.assertions(1);
const result = isLabeled(issue, label);
expect(result).toStrictEqual(true);
});
});
});
describe('when the given issue contains a label wih diacritical marks', (): void => {
beforeEach((): void => {
issue = {
labels: [
{
name: 'déjà vu'
}
]
} as Issue;
});
describe('when the given issue contains a label', (): void => {
beforeEach((): void => {
label = 'deja vu';
});
it('should return true', (): void => {
expect.assertions(1);
const result = isLabeled(issue, label);
expect(result).toStrictEqual(true);
});
});
describe('when the given issue contains an uppercase label', (): void => {
beforeEach((): void => {
label = 'DEJA VU';
});
it('should return true', (): void => {
expect.assertions(1);
const result = isLabeled(issue, label);
expect(result).toStrictEqual(true);
});
});
describe('when the given issue contains a label wih diacritical marks', (): void => {
beforeEach((): void => {
label = 'déjà vu';
});
it('should return true', (): void => {
expect.assertions(1);
const result = isLabeled(issue, label);
expect(result).toStrictEqual(true);
});
});
});
});