diff options
Diffstat (limited to 'spec/frontend/projects/project_find_file_spec.js')
-rw-r--r-- | spec/frontend/projects/project_find_file_spec.js | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/spec/frontend/projects/project_find_file_spec.js b/spec/frontend/projects/project_find_file_spec.js index efc9d411a98..9dae2bdc5bb 100644 --- a/spec/frontend/projects/project_find_file_spec.js +++ b/spec/frontend/projects/project_find_file_spec.js @@ -30,12 +30,13 @@ describe('ProjectFindFile', () => { let element; let mock; - const getProjectFindFileInstance = () => - new ProjectFindFile(element, { - url: FILE_FIND_URL, + const getProjectFindFileInstance = (extraOptions) => { + return new ProjectFindFile(element, { treeUrl: FIND_TREE_URL, blobUrlTemplate: BLOB_URL_TEMPLATE, + ...extraOptions, }); + }; const findFiles = () => element @@ -64,9 +65,6 @@ describe('ProjectFindFile', () => { HTTP_STATUS_OK, files.map((x) => x.path), ); - getProjectFindFileInstance(); // This triggers a load / axios call + subsequent render in the constructor - - return waitForPromises(); }); afterEach(() => { @@ -75,19 +73,44 @@ describe('ProjectFindFile', () => { sanitize.mockClear(); }); - it('loads and renders elements from remote server', () => { - expect(findFiles()).toEqual( - files.map(({ path, escaped }) => ({ - text: path, - href: `${BLOB_URL_TEMPLATE}/${escaped}`, - })), - ); + describe('rendering without refType', () => { + beforeEach(() => { + const instance = getProjectFindFileInstance(); + instance.load(FILE_FIND_URL); // axios call + subsequent render + return waitForPromises(); + }); + + it('loads and renders elements from remote server', () => { + expect(findFiles()).toEqual( + files.map(({ path, escaped }) => ({ + text: path, + href: `${BLOB_URL_TEMPLATE}/${escaped}`, + })), + ); + }); + + it('sanitizes search text', () => { + const searchText = element.find('.file-finder-input').val(); + + expect(sanitize).toHaveBeenCalledTimes(1); + expect(sanitize).toHaveBeenCalledWith(searchText); + }); }); - it('sanitizes search text', () => { - const searchText = element.find('.file-finder-input').val(); + describe('with refType option', () => { + beforeEach(() => { + const instance = getProjectFindFileInstance({ refType: 'heads' }); + instance.load(FILE_FIND_URL); // axios call + subsequent render + return waitForPromises(); + }); - expect(sanitize).toHaveBeenCalledTimes(1); - expect(sanitize).toHaveBeenCalledWith(searchText); + it('loads and renders elements from remote server', () => { + expect(findFiles()).toEqual( + files.map(({ path, escaped }) => ({ + text: path, + href: `${BLOB_URL_TEMPLATE}/${escaped}?ref_type=heads`, + })), + ); + }); }); }); |