Changeset View
Changeset View
Standalone View
Standalone View
cashtab/src/components/Alias/__tests__/Alias.test.js
Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | afterEach(async () => { | ||||
await clearLocalForage(localforage); | await clearLocalForage(localforage); | ||||
}); | }); | ||||
it('Registered and Pending Aliases are correctly rendered', async () => { | it('Registered and Pending Aliases are correctly rendered', async () => { | ||||
const mockedChronik = await initializeCashtabStateForTests( | const mockedChronik = await initializeCashtabStateForTests( | ||||
walletWithXecAndTokens, | walletWithXecAndTokens, | ||||
localforage, | localforage, | ||||
); | ); | ||||
const defaultAddress = walletWithXecAndTokens.paths.find( | const defaultAddress = walletWithXecAndTokens.paths.get(1899).address; | ||||
pathInfo => pathInfo.path === 1899, | |||||
).address; | |||||
// Mock the fetch call to alias-server's '/prices' endpoint | // Mock the fetch call to alias-server's '/prices' endpoint | ||||
const aliasPricesFetchUrl = `${aliasSettings.aliasServerBaseUrl}/prices`; | const aliasPricesFetchUrl = `${aliasSettings.aliasServerBaseUrl}/prices`; | ||||
global.fetch = jest.fn(); | global.fetch = jest.fn(); | ||||
when(fetch) | when(fetch) | ||||
.calledWith(aliasPricesFetchUrl) | .calledWith(aliasPricesFetchUrl) | ||||
.mockResolvedValue({ | .mockResolvedValue({ | ||||
json: () => Promise.resolve(aliasPricesResp), | json: () => Promise.resolve(aliasPricesResp), | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | it('Registered and Pending Aliases are correctly rendered when pending list is empty', async () => { | ||||
const aliasPricesFetchUrl = `${aliasSettings.aliasServerBaseUrl}/prices`; | const aliasPricesFetchUrl = `${aliasSettings.aliasServerBaseUrl}/prices`; | ||||
global.fetch = jest.fn(); | global.fetch = jest.fn(); | ||||
when(fetch) | when(fetch) | ||||
.calledWith(aliasPricesFetchUrl) | .calledWith(aliasPricesFetchUrl) | ||||
.mockResolvedValue({ | .mockResolvedValue({ | ||||
json: () => Promise.resolve(aliasPricesResp), | json: () => Promise.resolve(aliasPricesResp), | ||||
}); | }); | ||||
const defaultAddress = walletWithXecAndTokens.paths.find( | const defaultAddress = walletWithXecAndTokens.paths.get(1899).address; | ||||
pathInfo => pathInfo.path === 1899, | |||||
).address; | |||||
// Mock the refreshAliases() call to alias-server's '/address' endpoint upon component load | // Mock the refreshAliases() call to alias-server's '/address' endpoint upon component load | ||||
const addressFetchUrl = `${aliasSettings.aliasServerBaseUrl}/address/${defaultAddress}`; | const addressFetchUrl = `${aliasSettings.aliasServerBaseUrl}/address/${defaultAddress}`; | ||||
global.fetch = jest.fn(); | global.fetch = jest.fn(); | ||||
when(fetch) | when(fetch) | ||||
.calledWith(addressFetchUrl) | .calledWith(addressFetchUrl) | ||||
.mockResolvedValue({ | .mockResolvedValue({ | ||||
json: () => Promise.resolve(aliasAddressOneRegisteredNoPending), | json: () => Promise.resolve(aliasAddressOneRegisteredNoPending), | ||||
Show All 34 Lines | it('Registered and Pending Aliases are correctly rendered when registered list is empty', async () => { | ||||
const aliasPricesFetchUrl = `${aliasSettings.aliasServerBaseUrl}/prices`; | const aliasPricesFetchUrl = `${aliasSettings.aliasServerBaseUrl}/prices`; | ||||
global.fetch = jest.fn(); | global.fetch = jest.fn(); | ||||
when(fetch) | when(fetch) | ||||
.calledWith(aliasPricesFetchUrl) | .calledWith(aliasPricesFetchUrl) | ||||
.mockResolvedValue({ | .mockResolvedValue({ | ||||
json: () => Promise.resolve(aliasPricesResp), | json: () => Promise.resolve(aliasPricesResp), | ||||
}); | }); | ||||
const defaultAddress = walletWithXecAndTokens.paths.find( | const defaultAddress = walletWithXecAndTokens.paths.get(1899).address; | ||||
pathInfo => pathInfo.path === 1899, | |||||
).address; | |||||
// Mock the refreshAliases() call to alias-server's '/address' endpoint upon component load | // Mock the refreshAliases() call to alias-server's '/address' endpoint upon component load | ||||
const addressFetchUrl = `${aliasSettings.aliasServerBaseUrl}/address/${defaultAddress}`; | const addressFetchUrl = `${aliasSettings.aliasServerBaseUrl}/address/${defaultAddress}`; | ||||
global.fetch = jest.fn(); | global.fetch = jest.fn(); | ||||
when(fetch) | when(fetch) | ||||
.calledWith(addressFetchUrl) | .calledWith(addressFetchUrl) | ||||
.mockResolvedValue({ | .mockResolvedValue({ | ||||
json: () => Promise.resolve(aliasAddressNoRegisteredOnePending), | json: () => Promise.resolve(aliasAddressNoRegisteredOnePending), | ||||
Show All 25 Lines | it('Registered and Pending Aliases are correctly rendered when registered list is empty', async () => { | ||||
}); | }); | ||||
}); | }); | ||||
it('Registered and Pending lists still renders when aliasValidationError is populated and aliasServerError is false', async () => { | it('Registered and Pending lists still renders when aliasValidationError is populated and aliasServerError is false', async () => { | ||||
const mockedChronik = await initializeCashtabStateForTests( | const mockedChronik = await initializeCashtabStateForTests( | ||||
walletWithXecAndTokens, | walletWithXecAndTokens, | ||||
localforage, | localforage, | ||||
); | ); | ||||
const defaultAddress = walletWithXecAndTokens.paths.find( | const defaultAddress = walletWithXecAndTokens.paths.get(1899).address; | ||||
pathInfo => pathInfo.path === 1899, | |||||
).address; | |||||
// Note: Not mocking the '/prices' API call here in order to populate aliasValidationError | // Note: Not mocking the '/prices' API call here in order to populate aliasValidationError | ||||
// Mock the refreshAliases() call to alias-server's '/address' endpoint upon component load | // Mock the refreshAliases() call to alias-server's '/address' endpoint upon component load | ||||
const addressFetchUrl = `${aliasSettings.aliasServerBaseUrl}/address/${defaultAddress}`; | const addressFetchUrl = `${aliasSettings.aliasServerBaseUrl}/address/${defaultAddress}`; | ||||
global.fetch = jest.fn(); | global.fetch = jest.fn(); | ||||
when(fetch) | when(fetch) | ||||
.calledWith(addressFetchUrl) | .calledWith(addressFetchUrl) | ||||
▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines |