Remove use of getView()
and replace with getViewByURL()
where necessary. (#2544)
* WIP * Replace getView with getViewByURL
This commit is contained in:
@@ -30,6 +30,7 @@ jest.mock('electron', () => ({
|
||||
|
||||
jest.mock('../allowProtocolDialog', () => ({}));
|
||||
jest.mock('../windows/windowManager', () => ({
|
||||
getServerURLFromWebContentsId: jest.fn(),
|
||||
showMainWindow: jest.fn(),
|
||||
}));
|
||||
|
||||
@@ -83,7 +84,7 @@ describe('main/views/webContentsEvents', () => {
|
||||
const willNavigate = webContentsEventManager.generateWillNavigate(jest.fn());
|
||||
|
||||
beforeEach(() => {
|
||||
urlUtils.getView.mockImplementation(() => ({name: 'server_name', url: 'http://server-1.com'}));
|
||||
WindowManager.getServerURLFromWebContentsId.mockImplementation(() => new URL('http://server-1.com'));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -100,7 +101,7 @@ describe('main/views/webContentsEvents', () => {
|
||||
});
|
||||
|
||||
it('should allow navigation when url isAdminURL', () => {
|
||||
urlUtils.isAdminUrl.mockImplementation((serverURL, parsedURL) => parsedURL.toString().startsWith(`${serverURL}/admin_console`));
|
||||
urlUtils.isAdminUrl.mockImplementation((serverURL, parsedURL) => parsedURL.toString().startsWith(`${serverURL}admin_console`));
|
||||
willNavigate(event, 'http://server-1.com/admin_console/subpath');
|
||||
expect(event.preventDefault).not.toBeCalled();
|
||||
});
|
||||
@@ -146,7 +147,7 @@ describe('main/views/webContentsEvents', () => {
|
||||
const didStartNavigation = webContentsEventManager.generateDidStartNavigation(jest.fn());
|
||||
|
||||
beforeEach(() => {
|
||||
urlUtils.getView.mockImplementation(() => ({name: 'server_name', url: 'http://server-1.com'}));
|
||||
WindowManager.getServerURLFromWebContentsId.mockImplementation(() => new URL('http://server-1.com'));
|
||||
urlUtils.isTrustedURL.mockReturnValue(true);
|
||||
urlUtils.isInternalURL.mockImplementation((serverURL, parsedURL) => parsedURL.toString().startsWith(serverURL));
|
||||
urlUtils.isCustomLoginURL.mockImplementation((parsedURL) => parsedURL.toString().startsWith('http://loginurl.com/login'));
|
||||
@@ -176,11 +177,11 @@ describe('main/views/webContentsEvents', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
urlUtils.isValidURI.mockReturnValue(true);
|
||||
urlUtils.getView.mockReturnValue({name: 'server_name', url: 'http://server-1.com'});
|
||||
urlUtils.isTeamUrl.mockImplementation((serverURL, parsedURL) => parsedURL.toString().startsWith(`${serverURL}/myteam`));
|
||||
urlUtils.isAdminUrl.mockImplementation((serverURL, parsedURL) => parsedURL.toString().startsWith(`${serverURL}/admin_console`));
|
||||
urlUtils.isPluginUrl.mockImplementation((serverURL, parsedURL) => parsedURL.toString().startsWith(`${serverURL}/myplugin`));
|
||||
urlUtils.isManagedResource.mockImplementation((serverURL, parsedURL) => parsedURL.toString().startsWith(`${serverURL}/myplugin`));
|
||||
WindowManager.getServerURLFromWebContentsId.mockImplementation(() => new URL('http://server-1.com'));
|
||||
urlUtils.isTeamUrl.mockImplementation((serverURL, parsedURL) => parsedURL.toString().startsWith(`${serverURL}myteam`));
|
||||
urlUtils.isAdminUrl.mockImplementation((serverURL, parsedURL) => parsedURL.toString().startsWith(`${serverURL}admin_console`));
|
||||
urlUtils.isPluginUrl.mockImplementation((serverURL, parsedURL) => parsedURL.toString().startsWith(`${serverURL}myplugin`));
|
||||
urlUtils.isManagedResource.mockImplementation((serverURL, parsedURL) => parsedURL.toString().startsWith(`${serverURL}myplugin`));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -211,7 +212,7 @@ describe('main/views/webContentsEvents', () => {
|
||||
});
|
||||
|
||||
it('should open in the browser when there is no server matching', () => {
|
||||
urlUtils.getView.mockReturnValue(null);
|
||||
WindowManager.getServerURLFromWebContentsId.mockReturnValue(undefined);
|
||||
expect(newWindow({url: 'http://server-2.com/subpath'})).toStrictEqual({action: 'deny'});
|
||||
expect(shell.openExternal).toBeCalledWith('http://server-2.com/subpath');
|
||||
});
|
||||
|
Reference in New Issue
Block a user