This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/directives/ui/regex-match-view/regex-match-view.component.spec.ts
2017-02-28 16:51:42 -05:00

44 lines
1.4 KiB
TypeScript

import { RegexMatchViewComponent } from './regex-match-view.component';
describe("RegexMatchViewComponent", () => {
var component: RegexMatchViewComponent;
beforeEach(() => {
component = new RegexMatchViewComponent();
});
describe("filterMatches", () => {
var items: ({value: string})[];
beforeEach(() => {
items = [{value: "master"}, {value: "develop"}, {value: "production"}];
});
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);
});
});
});
});