-
Notifications
You must be signed in to change notification settings - Fork 970
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
Fix Tests since MWA is no longer autoselected #1021
base: revert-1012
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,7 +201,32 @@ describe('WalletProvider when the environment is `MOBILE_WEB`', () => { | |
expect(jest.mocked(SolanaMobileWalletAdapter).mock.calls[0][0].cluster).toBe('fake-cluster-for-test'); | ||
}); | ||
}); | ||
|
||
describe('when another wallet adapter is supplied in the adapters array', () => { | ||
beforeEach(() => { | ||
adapters.push(new FooWalletAdapter()); | ||
}); | ||
it('does not load the mobile wallet adapter into state as the default', () => { | ||
renderTest({}); | ||
expect(ref.current?.getWalletContextState().wallet?.adapter.name).toBe(undefined); | ||
}); | ||
it('loads no public key into state', () => { | ||
renderTest({}); | ||
expect(ref.current?.getWalletContextState().publicKey).toBeNull(); | ||
}); | ||
}); | ||
describe('when no wallet adapter is supplied in the adapters array', () => { | ||
beforeEach(() => { | ||
adapters = []; | ||
}); | ||
it('does load the mobile wallet adapter into state as the default', () => { | ||
renderTest({}); | ||
expect(ref.current?.getWalletContextState().wallet?.adapter.name).toBe(SolanaMobileWalletAdapterWalletName); | ||
}); | ||
it('loads no public key into state', () => { | ||
renderTest({}); | ||
expect(ref.current?.getWalletContextState().publicKey).toBeNull(); | ||
}); | ||
}); | ||
describe('when a custom mobile wallet adapter is supplied in the adapters array', () => { | ||
let customAdapter: Adapter; | ||
const CUSTOM_APP_IDENTITY = { | ||
|
@@ -219,28 +244,15 @@ describe('WalletProvider when the environment is `MOBILE_WEB`', () => { | |
adapters.push(customAdapter); | ||
jest.clearAllMocks(); | ||
}); | ||
it('loads the custom mobile wallet adapter into state as the default', () => { | ||
it('does not load the custom mobile wallet adapter into state as the default', () => { | ||
renderTest({}); | ||
expect(ref.current?.getWalletContextState().wallet?.adapter).toBe(customAdapter); | ||
expect(ref.current?.getWalletContextState().wallet?.adapter).toBe(undefined); | ||
}); | ||
it('does not construct any further mobile wallet adapters', () => { | ||
renderTest({}); | ||
expect(jest.mocked(SolanaMobileWalletAdapter).mock.calls.length).toBe(0); | ||
}); | ||
}); | ||
describe('when there exists no stored wallet name', () => { | ||
beforeEach(() => { | ||
localStorage.removeItem(WALLET_NAME_CACHE_KEY); | ||
}); | ||
it('loads the mobile wallet adapter into state as the default', () => { | ||
renderTest({}); | ||
expect(ref.current?.getWalletContextState().wallet?.adapter.name).toBe(SolanaMobileWalletAdapterWalletName); | ||
}); | ||
it('loads no public key into state', () => { | ||
renderTest({}); | ||
expect(ref.current?.getWalletContextState().publicKey).toBeNull(); | ||
}); | ||
}); | ||
describe('when there exists a stored wallet name', () => { | ||
beforeEach(() => { | ||
localStorage.setItem(WALLET_NAME_CACHE_KEY, JSON.stringify('FooWallet')); | ||
|
@@ -326,14 +338,18 @@ describe('WalletProvider when the environment is `MOBILE_WEB`', () => { | |
describe('onError', () => { | ||
let onError: jest.Mock; | ||
let errorThrown: WalletError; | ||
beforeEach(() => { | ||
beforeEach(async () => { | ||
errorThrown = new WalletError('o no'); | ||
onError = jest.fn(); | ||
renderTest({ onError }); | ||
await act(async () => { | ||
ref.current?.getWalletContextState().select(SolanaMobileWalletAdapterWalletName); | ||
await Promise.resolve(); // Flush all promises in effects after calling `select()`. | ||
}); | ||
}); | ||
describe('when the wallet emits an error', () => { | ||
let adapter: Adapter; | ||
beforeEach(() => { | ||
beforeEach(async () => { | ||
act(() => { | ||
adapter = ref.current?.getWalletContextState().wallet?.adapter as SolanaMobileWalletAdapter; | ||
adapter.emit('error', errorThrown); | ||
|
@@ -452,8 +468,8 @@ describe('WalletProvider when the environment is `MOBILE_WEB`', () => { | |
mobileWalletAdapter.disconnect(); | ||
}); | ||
}); | ||
it('should not clear the stored wallet name', () => { | ||
expect(localStorage.removeItem).not.toHaveBeenCalled(); | ||
it('should clear the stored wallet name', () => { | ||
expect(localStorage.removeItem).toHaveBeenCalled(); | ||
}); | ||
}); | ||
describe('when window beforeunload event fires', () => { | ||
|
@@ -470,8 +486,8 @@ describe('WalletProvider when the environment is `MOBILE_WEB`', () => { | |
mobileWalletAdapter.disconnect(); | ||
}); | ||
}); | ||
it('should not clear the stored wallet name', () => { | ||
expect(localStorage.removeItem).not.toHaveBeenCalled(); | ||
it('should clear the stored wallet name', () => { | ||
expect(localStorage.removeItem).toHaveBeenCalled(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. I think the original intent of the test is correct -- the wallet disconnecting should NOT deselect the wallet or remove it from LocalStorage, because then autoconnect will be broken on reload. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this true? AFAICT when using wallet adapter, autoconnect is not supposed to reload the last used wallet if disconnect was called |
||
}); | ||
it('should clear out the state', () => { | ||
expect(ref.current?.getWalletContextState()).toMatchObject({ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change doesn't make sense to me. MWA shouldn't be deselected after each test, given the comment following this one)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey sorry, not sure I totally follow – I don't think there's any selecting involved, the test is just to make sure that when the adapter emits an error, it expects
onError
to be called. or was the point of the test something different?