-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
22 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
64 changes: 64 additions & 0 deletions
64
packages/examples/packages/preinstalled/src/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { expect } from '@jest/globals'; | ||
import { installSnap } from '@metamask/snaps-jest'; | ||
|
||
import { Dialog, Result } from './components'; | ||
|
||
describe('onRpcRequest', () => { | ||
it('throws an error if the requested method does not exist', async () => { | ||
const { request } = await installSnap(); | ||
|
||
const response = await request({ | ||
method: 'foo', | ||
}); | ||
|
||
expect(response).toRespondWithError({ | ||
code: -32601, | ||
message: 'The method does not exist / is not available.', | ||
stack: expect.any(String), | ||
data: { | ||
method: 'foo', | ||
cause: null, | ||
}, | ||
}); | ||
}); | ||
|
||
describe('showDialog', () => { | ||
it('closes the dialog when clicking cancel, and resolves with `null`', async () => { | ||
const { request } = await installSnap(); | ||
|
||
const response = request({ | ||
method: 'showDialog', | ||
}); | ||
|
||
const formScreen = await response.getInterface(); | ||
expect(formScreen).toRender(<Dialog />); | ||
|
||
await formScreen.clickElement('cancel'); | ||
|
||
const result = await response; | ||
expect(result).toRespondWith(null); | ||
}); | ||
|
||
it('shows the result when clicking confirm, and resolves with the result', async () => { | ||
const { request } = await installSnap(); | ||
|
||
const response = request({ | ||
method: 'showDialog', | ||
}); | ||
|
||
const formScreen = await response.getInterface(); | ||
expect(formScreen).toRender(<Dialog />); | ||
|
||
await formScreen.typeInField('custom-input', 'foo bar'); | ||
await formScreen.clickElement('confirm'); | ||
|
||
const resultScreen = await response.getInterface(); | ||
expect(resultScreen).toRender(<Result value="foo bar" />); | ||
|
||
await resultScreen.clickElement('ok'); | ||
|
||
const result = await response; | ||
expect(result).toRespondWith('foo bar'); | ||
}); | ||
}); | ||
}); |