diff options
author | Nathan Friend <nfriend@gitlab.com> | 2019-03-12 19:35:55 +0300 |
---|---|---|
committer | mfluharty <mfluharty@gitlab.com> | 2019-04-03 08:58:01 +0300 |
commit | 06b88af04657be961a4da97a586706fb99eb6a27 (patch) | |
tree | e574c1a39cdc6ca75a734c8256604baa698aa447 /spec/javascripts/lib | |
parent | 645303c7e71d554c3ee1a338730d8b779c47acc1 (diff) |
Add reusable project_selector component
This commit adds a resuable UI component that allows a user to search
for a project name, shows the search results, and allows the user to
select one or more projects. This component communicates with its
parent using props and events.
This component was originally created for use in the EE-specific
"Operations Dashboard" page, but it is applicable for CE use cases as
well, and so was added as a CE shared component.
In addition, some logic was extracted from the frequent_items_list_item
component into shared filters to avoid logic duplication.
Diffstat (limited to 'spec/javascripts/lib')
-rw-r--r-- | spec/javascripts/lib/utils/higlight_spec.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/javascripts/lib/utils/higlight_spec.js b/spec/javascripts/lib/utils/higlight_spec.js new file mode 100644 index 00000000000..638bbf65ae9 --- /dev/null +++ b/spec/javascripts/lib/utils/higlight_spec.js @@ -0,0 +1,43 @@ +import highlight from '~/lib/utils/highlight'; + +describe('highlight', () => { + it(`should appropriately surround substring matches`, () => { + const expected = 'g<b>i</b><b>t</b>lab'; + + expect(highlight('gitlab', 'it')).toBe(expected); + }); + + it(`should return an empty string in the case of invalid inputs`, () => { + [null, undefined].forEach(input => { + expect(highlight(input, 'match')).toBe(''); + }); + }); + + it(`should return the original value if match is null, undefined, or ''`, () => { + [null, undefined].forEach(match => { + expect(highlight('gitlab', match)).toBe('gitlab'); + }); + }); + + it(`should highlight matches in non-string inputs`, () => { + const expected = '123<b>4</b><b>5</b>6'; + + expect(highlight(123456, 45)).toBe(expected); + }); + + it(`should sanitize the input string before highlighting matches`, () => { + const expected = 'hello <b>w</b>orld'; + + expect(highlight('hello <b>world</b>', 'w')).toBe(expected); + }); + + it(`should not highlight anything if no matches are found`, () => { + expect(highlight('gitlab', 'hello')).toBe('gitlab'); + }); + + it(`should allow wrapping elements to be customized`, () => { + const expected = '1<hello>2</hello>3'; + + expect(highlight('123', '2', '<hello>', '</hello>')).toBe(expected); + }); +}); |