-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[explorer] task: hide hash lock section #1137
* [explorer] task: fix fetch hash lock logic in transaction info * [explorer] task: refactor isItemShown method, added unit test * [explorer] task: patch mixed-spaces-and-tabs fix * [explorer] task: refactor on hideEmptyData logic
- Loading branch information
1 parent
41638cb
commit a54dc05
Showing
5 changed files
with
188 additions
and
12 deletions.
There are no files selected for viewing
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,58 @@ | ||
import Constants from '../../src/config/constants'; | ||
import transaction from '../../src/store/transaction'; | ||
import { TransactionType } from 'symbol-sdk'; | ||
|
||
describe('store/transaction', () => { | ||
describe('action/getTransactionInfoByHash', () => { | ||
const runBasicFetchHashLockTests = (transactionType, transactionName) => { | ||
const context = { | ||
dispatch: jest.fn(), | ||
getters: { | ||
info: { | ||
setStore: jest.fn().mockReturnThis(), | ||
initialFetch: jest.fn() | ||
}, | ||
hashLock: { | ||
setStore: jest.fn().mockReturnThis(), | ||
initialFetch: jest.fn() | ||
}, | ||
transactionDetail: { | ||
transactionType | ||
} | ||
} | ||
}; | ||
|
||
const isAggregateBonded = transactionType === TransactionType.AGGREGATE_BONDED; | ||
|
||
it(`${isAggregateBonded ? '' : 'skips '}fetch hash lock when transaction type is ${transactionName}`, async () => { | ||
// Arrange: | ||
const payload = { | ||
transactionHash: '5E699B430581BE31A175952F88876166EAEE713FB05465F7CAC6B182F25B995F' | ||
}; | ||
|
||
// Act: | ||
await transaction.actions.getTransactionInfoByHash(context, payload); | ||
|
||
// Assert: | ||
const { info, hashLock } = context.getters; | ||
|
||
expect(context.dispatch).toHaveBeenNthCalledWith(1, 'uninitializeDetail'); | ||
|
||
expect(info.setStore).toHaveBeenNthCalledWith(1, context); | ||
expect(hashLock.setStore).toHaveBeenNthCalledWith(1, context); | ||
|
||
expect(info.initialFetch).toHaveBeenCalledWith(payload.transactionHash); | ||
|
||
if (isAggregateBonded) | ||
expect(hashLock.initialFetch).toHaveBeenCalledWith(payload.transactionHash); | ||
else | ||
expect(hashLock.initialFetch).not.toHaveBeenCalled(); | ||
}); | ||
}; | ||
|
||
// Arrange: | ||
Object.keys(Constants.TransactionType).forEach(type => { | ||
runBasicFetchHashLockTests(Number(type), Constants.TransactionType[type]); | ||
}); | ||
}); | ||
}); |
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,113 @@ | ||
import PageAssembler from '../../src/views/PageAssembler.vue'; | ||
import { createLocalVue, shallowMount } from '@vue/test-utils'; | ||
import Vuex from 'vuex'; | ||
|
||
const localVue = createLocalVue(); | ||
localVue.use(Vuex); | ||
|
||
describe('views/PageAssembler', () => { | ||
const createWrapper = () => { | ||
const propsData = { | ||
layout: 'flex', | ||
schema: [{ | ||
managerGetter: 'test/info' | ||
}] | ||
}; | ||
|
||
return shallowMount(PageAssembler, { | ||
localVue, | ||
propsData | ||
}); | ||
}; | ||
describe('method', () => { | ||
describe('isItemShown', () => { | ||
const runBasicHideEmptyDataTests = (data, expectedResult) => { | ||
const action = expectedResult ? 'renders' : 'hides'; | ||
const condition = expectedResult ? 'non empty' : 'empty'; | ||
const dataType = Array.isArray(data) ? 'array' : 'object'; | ||
|
||
it(`${action} item when hideEmptyData set true and data in ${dataType} is ${condition}`, () => { | ||
// Arrange: | ||
const wrapper = createWrapper(); | ||
|
||
const schemaConfig = { | ||
hideEmptyData: true | ||
}; | ||
|
||
jest.spyOn(wrapper.vm, 'getData').mockReturnValue(data); | ||
|
||
// Act: | ||
const result = wrapper.vm.isItemShown(schemaConfig); | ||
|
||
// Assert: | ||
expect(result).toBe(expectedResult); | ||
}); | ||
|
||
}; | ||
|
||
const runItemShownTests = (schemaConfig, getter, expectedResult) => { | ||
const action = expectedResult ? 'renders' : 'hides'; | ||
const condition = expectedResult ? 'non errors' : 'errors'; | ||
|
||
it(`${action} item when ${Object.keys(schemaConfig)[0]} is set and getters has ${condition}`, () => { | ||
// Arrange: | ||
const wrapper = createWrapper(); | ||
|
||
jest.spyOn(wrapper.vm, 'getter').mockReturnValue(getter); | ||
|
||
// Act: | ||
const result = wrapper.vm.isItemShown(schemaConfig); | ||
|
||
// Assert: | ||
expect(result).toBe(expectedResult); | ||
}); | ||
}; | ||
|
||
runBasicHideEmptyDataTests([], false); | ||
runBasicHideEmptyDataTests(['1'], true); | ||
|
||
runBasicHideEmptyDataTests({}, false); | ||
runBasicHideEmptyDataTests({ test: '1'}, true); | ||
|
||
runItemShownTests( | ||
{ | ||
hideDependOnGetter: 'test/info' | ||
}, | ||
{ | ||
error: true | ||
}, | ||
false | ||
); | ||
|
||
runItemShownTests( | ||
{ | ||
hideDependOnGetter: 'test/info' | ||
}, | ||
{ | ||
error: false | ||
}, | ||
true | ||
); | ||
|
||
runItemShownTests( | ||
{ | ||
hideOnError: true | ||
}, | ||
{ | ||
error: true | ||
}, | ||
false | ||
); | ||
|
||
runItemShownTests( | ||
{ | ||
hideOnError: true | ||
}, | ||
{ | ||
error: false | ||
}, | ||
true | ||
); | ||
}); | ||
}); | ||
}); |
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
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
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