1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 16:18:07 +01:00
metamask-extension/ui/app/selectors/tests/selectors.test.js
Whymarrh Whitby d131014b5e
Fix Connected Sites data selector (#8310)
This change replaces `getRenderablePermissionsDomains` with a new selector `getConnectedDomainsForSelectedAddress` that works better. The data returned from this selector is used to populated the _Connected Sites_ modal, which (as of #8262) didn't use most of the data returned from the old selector.

The old selector only looked at the first address that was exposed, making it not work for anything other than the first account connected to a particular origin.
2020-04-08 20:38:48 -02:30

175 lines
5.6 KiB
JavaScript

import assert from 'assert'
import { getAddressBook, getConnectedDomainsForSelectedAddress } from '../selectors.js'
import mockState from './selectors-test-data'
describe('selectors', function () {
describe('getAddressBook()', function () {
it('should return the address book', function () {
assert.deepEqual(
getAddressBook(mockState),
[
{
'address': '0x06195827297c7a80a443b6894d3bdb8824b43896',
'chainId': '3',
'isEns': false,
'memo': '',
'name': 'Address Book Account 1',
},
],
)
})
})
describe('getConnectedDomainsForSelectedAddress', function () {
it('should return the list of connected domains when there is 1 connected account', function () {
const mockState = {
metamask: {
selectedAddress: '0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
domainMetadata: {
'peepeth.com': {
'icon': 'https://peepeth.com/favicon-32x32.png',
'name': 'Peepeth',
},
'remix.ethereum.org': {
'icon': 'https://remix.ethereum.org/icon.png',
'name': 'Remix - Ethereum IDE',
},
},
domains: {
'peepeth.com': {
'permissions': [
{
'@context': [
'https://github.com/MetaMask/rpc-cap',
],
'caveats': [
{
'name': 'exposedAccounts',
'type': 'filterResponse',
'value': [
'0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
],
},
],
'date': 1585676177970,
'id': '840d72a0-925f-449f-830a-1aa1dd5ce151',
'invoker': 'peepeth.com',
'parentCapability': 'eth_accounts',
},
],
},
'remix.ethereum.org': {
'permissions': [
{
'@context': [
'https://github.com/MetaMask/rpc-cap',
],
'caveats': [
{
'type': 'filterResponse',
'value': [
'0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
],
'name': 'exposedAccounts',
},
],
'date': 1585685128948,
'id': '6b9615cc-64e4-4317-afab-3c4f8ee0244a',
'invoker': 'remix.ethereum.org',
'parentCapability': 'eth_accounts',
},
],
},
},
},
}
const extensionId = undefined
assert.deepEqual(getConnectedDomainsForSelectedAddress(mockState), [{
extensionId,
icon: 'https://peepeth.com/favicon-32x32.png',
key: 'peepeth.com',
name: 'Peepeth',
}, {
extensionId,
name: 'Remix - Ethereum IDE',
icon: 'https://remix.ethereum.org/icon.png',
key: 'remix.ethereum.org',
}])
})
it('should return the list of connected domains when there are 2 connected accounts', function () {
const mockState = {
metamask: {
selectedAddress: '0x7250739de134d33ec7ab1ee592711e15098c9d2d',
domainMetadata: {
'peepeth.com': {
'icon': 'https://peepeth.com/favicon-32x32.png',
'name': 'Peepeth',
},
'remix.ethereum.org': {
'icon': 'https://remix.ethereum.org/icon.png',
'name': 'Remix - Ethereum IDE',
},
},
domains: {
'peepeth.com': {
'permissions': [
{
'@context': [
'https://github.com/MetaMask/rpc-cap',
],
'caveats': [
{
'name': 'exposedAccounts',
'type': 'filterResponse',
'value': [
'0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
],
},
],
'date': 1585676177970,
'id': '840d72a0-925f-449f-830a-1aa1dd5ce151',
'invoker': 'peepeth.com',
'parentCapability': 'eth_accounts',
},
],
},
'remix.ethereum.org': {
'permissions': [
{
'@context': [
'https://github.com/MetaMask/rpc-cap',
],
'caveats': [
{
'type': 'filterResponse',
'value': [
'0x8e5d75d60224ea0c33d0041e75de68b1c3cb6dd5',
'0x7250739de134d33ec7ab1ee592711e15098c9d2d',
],
'name': 'exposedAccounts',
},
],
'date': 1585685128948,
'id': '6b9615cc-64e4-4317-afab-3c4f8ee0244a',
'invoker': 'remix.ethereum.org',
'parentCapability': 'eth_accounts',
},
],
},
},
},
}
const extensionId = undefined
assert.deepEqual(getConnectedDomainsForSelectedAddress(mockState), [{
extensionId,
name: 'Remix - Ethereum IDE',
icon: 'https://remix.ethereum.org/icon.png',
key: 'remix.ethereum.org',
}])
})
})
})