2017-02-17 10:55:52 +00:00
|
|
|
import { RegexMatchViewComponent } from './regex-match-view.component';
|
|
|
|
|
|
|
|
|
|
|
|
describe("RegexMatchViewComponent", () => {
|
|
|
|
var component: RegexMatchViewComponent;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
component = new RegexMatchViewComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("filterMatches", () => {
|
2017-02-17 21:40:05 +00:00
|
|
|
var items: ({value: string})[];
|
2017-02-17 10:55:52 +00:00
|
|
|
|
2017-02-17 21:40:05 +00:00
|
|
|
beforeEach(() => {
|
2017-02-17 23:46:43 +00:00
|
|
|
items = [{value: "heads/master"}, {value: "heads/develop"}, {value: "heads/production"}];
|
2017-02-17 21:40:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("returns null if given invalid regex expression", () => {
|
|
|
|
var regexstr: string = "\\asfd\\";
|
|
|
|
|
|
|
|
expect(component.filterMatches(regexstr, items, true)).toBe(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("returns a subset of given items matching the given regex expression if given 'shouldMatch' as true", () => {
|
|
|
|
var regexstr: string = `^${items[0].value}$`;
|
|
|
|
var matches: ({value: string})[] = component.filterMatches(regexstr, items, true);
|
|
|
|
|
|
|
|
expect(matches.length).toBeGreaterThan(0);
|
|
|
|
matches.forEach((match) => {
|
|
|
|
expect(items).toContain(match);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("returns a subset of given items not matching the given regex expression if given 'shouldMatch' as false", () => {
|
|
|
|
var regexstr: string = `^${items[0].value}$`;
|
|
|
|
var nonMatches: ({value: string})[] = component.filterMatches(regexstr, items, false);
|
|
|
|
|
|
|
|
expect(nonMatches.length).toBeGreaterThan(0);
|
|
|
|
nonMatches.forEach((nonMatch) => {
|
|
|
|
expect(items).toContain(nonMatch);
|
|
|
|
});
|
|
|
|
});
|
2017-02-17 10:55:52 +00:00
|
|
|
});
|
|
|
|
});
|