Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update locahost href to use correct url when displaying network url #105

Merged
merged 3 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ typings/
bundle-*.js
/.vagrant
.DS_Store
.vscode/
.idea/

/packages.png
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
2 changes: 1 addition & 1 deletion wallet/src/components/ConnectionSettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
74 changes: 74 additions & 0 deletions wallet/src/components/tests/ConnectionSettingsDialog.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { mount } from 'enzyme';
import ConnectionSettingsDialog from '../ConnectionSettingsDialog';
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);

const appTheme = createTheme({
palette: {
// @ts-expect-error not in Palette
cancel: {
main: '#595959',
},
},
});

const MOCK_LOCALHOST = 'http://foobar:440';

const withApplicationContext =
(Component, _) =>
({ ...props }) => {
return (
<ThemeProvider theme={appTheme}>
<Component {...props} />
</ThemeProvider>
);
};

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(
<ConnectionSettingsDialog
allConnectionConfigs={DEFAULT_CONNECTION_CONFIGS}
connectionConfig={{ href: KnownNetworkConfigUrls.main }}
open
/>,
);

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`,
);
});
});