From f1ce71c88c407709987dd4a7b40bdb7596b6baa2 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 11 Apr 2023 15:08:32 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/frontend/lib/utils/web_ide_navigator_spec.js | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 spec/frontend/lib/utils/web_ide_navigator_spec.js (limited to 'spec/frontend/lib') diff --git a/spec/frontend/lib/utils/web_ide_navigator_spec.js b/spec/frontend/lib/utils/web_ide_navigator_spec.js new file mode 100644 index 00000000000..0f5cd09d50e --- /dev/null +++ b/spec/frontend/lib/utils/web_ide_navigator_spec.js @@ -0,0 +1,38 @@ +import { visitUrl, webIDEUrl } from '~/lib/utils/url_utility'; +import { openWebIDE } from '~/lib/utils/web_ide_navigator'; + +jest.mock('~/lib/utils/url_utility', () => ({ + visitUrl: jest.fn(), + webIDEUrl: jest.fn().mockImplementation((path) => `/-/ide/projects${path}`), +})); + +describe('openWebIDE', () => { + it('when called without projectPath throws TypeError and does not call visitUrl', () => { + expect(() => { + openWebIDE(); + }).toThrow(new TypeError('projectPath parameter is required')); + expect(visitUrl).not.toHaveBeenCalled(); + }); + + it('when called with projectPath and without fileName calls visitUrl with correct path', () => { + const params = { projectPath: 'project-path' }; + const expectedNonIDEPath = `/${params.projectPath}/edit/main/-/`; + const expectedIDEPath = `/-/ide/projects${expectedNonIDEPath}`; + + openWebIDE(params.projectPath); + + expect(webIDEUrl).toHaveBeenCalledWith(expectedNonIDEPath); + expect(visitUrl).toHaveBeenCalledWith(expectedIDEPath); + }); + + it('when called with projectPath and fileName calls visitUrl with correct path', () => { + const params = { projectPath: 'project-path', fileName: 'README' }; + const expectedNonIDEPath = `/${params.projectPath}/edit/main/-/${params.fileName}/`; + const expectedIDEPath = `/-/ide/projects${expectedNonIDEPath}`; + + openWebIDE(params.projectPath, params.fileName); + + expect(webIDEUrl).toHaveBeenCalledWith(expectedNonIDEPath); + expect(visitUrl).toHaveBeenCalledWith(expectedIDEPath); + }); +}); -- cgit v1.2.3