From 8c279b220205df4de99b630652a67d37d5774a52 Mon Sep 17 00:00:00 2001 From: Ikenna Omekam Date: Wed, 28 Jun 2023 15:12:12 -0700 Subject: [PATCH 1/3] fix: use location.origin for local network config --- .../components/ConnectionSettingsDialog.tsx | 2 +- .../tests/ConnectionSettingsDIalong.test.tsx | 66 +++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 wallet/src/components/tests/ConnectionSettingsDIalong.test.tsx diff --git a/wallet/src/components/ConnectionSettingsDialog.tsx b/wallet/src/components/ConnectionSettingsDialog.tsx index a6957bc9..99f90b2d 100644 --- a/wallet/src/components/ConnectionSettingsDialog.tsx +++ b/wallet/src/components/ConnectionSettingsDialog.tsx @@ -124,7 +124,7 @@ const ConnectionSettingsDialog = ({ break; case 'localhost': setConfig({ - href: `http://localhost:3000/wallet/network-config`, + href: `${window.location.origin}/wallet/network-config`, }); break; case 'custom': diff --git a/wallet/src/components/tests/ConnectionSettingsDIalong.test.tsx b/wallet/src/components/tests/ConnectionSettingsDIalong.test.tsx new file mode 100644 index 00000000..dfd3b769 --- /dev/null +++ b/wallet/src/components/tests/ConnectionSettingsDIalong.test.tsx @@ -0,0 +1,66 @@ +import { mount } from 'enzyme'; +import ConnectionSettingsDialog from '../ConnectionSettingsDialog'; +import { DEFAULT_CONNECTION_CONFIGS, KnownNetworkConfigUrls } from '../../util/connections'; +import { Input, Select, TextField, ThemeProvider, createTheme } from '@mui/material'; +import { act } from '@testing-library/react'; + +jest.mock('lodash-es/isEqual', () => () => true); + +const appTheme = createTheme({ + palette: { + // @ts-expect-error not in Palette + cancel: { + main: '#595959', + }, + }, +}); + +const MOCK_LOCALHOST = "http://foobar:440" + +const withApplicationContext = + (Component, _) => + ({ ...props }) => { + return ( + + + + ); + }; + +jest.mock('../../contexts/Application', () => { + return { withApplicationContext }; +}); + +describe("Connection setting dialog", () => { + const { location } = window; + + beforeAll(() => { + // @ts-expect-error mocking window.location + delete window.location; + + // @ts-expect-error mocking window.location + window.location = { origin: MOCK_LOCALHOST }; + }); + + afterAll(() => { + window.location = location; + }); + + test('displays the dapp', () => { + const component = mount( + ); + + const networkSelect = component.find(Select).first(); + act(() => networkSelect.props().onChange({ target: { value: 'localhost' } })); + component.update(); + + const textField = component.find(TextField).first() + const inputField = textField.find("input").first() + + expect(inputField.prop("value")).toEqual(`${MOCK_LOCALHOST}/wallet/network-config`) + }); +}); \ No newline at end of file From 1462187fbe227b09c9fabf1f5e63014b5eff7441 Mon Sep 17 00:00:00 2001 From: samsiegart Date: Thu, 29 Jun 2023 15:33:50 -0700 Subject: [PATCH 2/3] chore: set default vscode formatter --- .gitignore | 1 - .vscode/settings.json | 3 ++ .../tests/ConnectionSettingsDIalong.test.tsx | 48 +++++++++++-------- 3 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 0cb79197..6c3195ae 100644 --- a/.gitignore +++ b/.gitignore @@ -51,7 +51,6 @@ typings/ bundle-*.js /.vagrant .DS_Store -.vscode/ .idea/ /packages.png diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..65a19653 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.defaultFormatter": "esbenp.prettier-vscode" +} diff --git a/wallet/src/components/tests/ConnectionSettingsDIalong.test.tsx b/wallet/src/components/tests/ConnectionSettingsDIalong.test.tsx index dfd3b769..5fb1d510 100644 --- a/wallet/src/components/tests/ConnectionSettingsDIalong.test.tsx +++ b/wallet/src/components/tests/ConnectionSettingsDIalong.test.tsx @@ -1,7 +1,10 @@ import { mount } from 'enzyme'; import ConnectionSettingsDialog from '../ConnectionSettingsDialog'; -import { DEFAULT_CONNECTION_CONFIGS, KnownNetworkConfigUrls } from '../../util/connections'; -import { Input, Select, TextField, ThemeProvider, createTheme } from '@mui/material'; +import { + DEFAULT_CONNECTION_CONFIGS, + KnownNetworkConfigUrls, +} from '../../util/connections'; +import { Select, TextField, ThemeProvider, createTheme } from '@mui/material'; import { act } from '@testing-library/react'; jest.mock('lodash-es/isEqual', () => () => true); @@ -15,7 +18,7 @@ const appTheme = createTheme({ }, }); -const MOCK_LOCALHOST = "http://foobar:440" +const MOCK_LOCALHOST = 'http://foobar:440'; const withApplicationContext = (Component, _) => @@ -31,7 +34,7 @@ jest.mock('../../contexts/Application', () => { return { withApplicationContext }; }); -describe("Connection setting dialog", () => { +describe('Connection setting dialog', () => { const { location } = window; beforeAll(() => { @@ -47,20 +50,25 @@ describe("Connection setting dialog", () => { }); test('displays the dapp', () => { - const component = mount( - ); - - const networkSelect = component.find(Select).first(); - act(() => networkSelect.props().onChange({ target: { value: 'localhost' } })); - component.update(); - - const textField = component.find(TextField).first() - const inputField = textField.find("input").first() - - expect(inputField.prop("value")).toEqual(`${MOCK_LOCALHOST}/wallet/network-config`) + const component = mount( + , + ); + + const networkSelect = component.find(Select).first(); + act(() => + networkSelect.props().onChange({ target: { value: 'localhost' } }), + ); + component.update(); + + const textField = component.find(TextField).first(); + const inputField = textField.find('input').first(); + + expect(inputField.prop('value')).toEqual( + `${MOCK_LOCALHOST}/wallet/network-config`, + ); }); -}); \ No newline at end of file +}); From cac35c644a73d6688c1cf747c920c9e7af24d6ce Mon Sep 17 00:00:00 2001 From: samsiegart Date: Thu, 29 Jun 2023 15:36:09 -0700 Subject: [PATCH 3/3] chore: fix filename --- ...SettingsDIalong.test.tsx => ConnectionSettingsDialog.test.tsx} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename wallet/src/components/tests/{ConnectionSettingsDIalong.test.tsx => ConnectionSettingsDialog.test.tsx} (100%) diff --git a/wallet/src/components/tests/ConnectionSettingsDIalong.test.tsx b/wallet/src/components/tests/ConnectionSettingsDialog.test.tsx similarity index 100% rename from wallet/src/components/tests/ConnectionSettingsDIalong.test.tsx rename to wallet/src/components/tests/ConnectionSettingsDialog.test.tsx