-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[explorer] fix: Restriction display issue #1116
* [explorer] task: refactor and fix for restriction service and field component * [explorer] feat: added unit test * [explorer] task: patch description update
- Loading branch information
1 parent
4b223fe
commit c6340d5
Showing
4 changed files
with
292 additions
and
24 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,105 @@ | ||
import RestrictionField from '../../../src/components/fields/RestrictionField.vue'; | ||
import UI from '../../../src/store/ui'; | ||
import { createLocalVue, shallowMount } from '@vue/test-utils'; | ||
import Vuex from 'vuex'; | ||
|
||
const localVue = createLocalVue(); | ||
localVue.use(Vuex); | ||
|
||
describe('RestrictionField component', () => { | ||
const setupStoreMount = restrictions => { | ||
const uiModule = { | ||
namespaced: true, | ||
getters: { | ||
getNameByKey: UI.getters.getNameByKey | ||
} | ||
}; | ||
|
||
const store = new Vuex.Store({ | ||
modules: { | ||
ui:uiModule | ||
} | ||
}); | ||
|
||
const propsData = { | ||
value: restrictions | ||
}; | ||
|
||
return shallowMount(RestrictionField, { | ||
store, | ||
localVue, | ||
propsData | ||
}); | ||
}; | ||
|
||
describe('mosaic address restriction', () => { | ||
it('renders restriction field', () => { | ||
// Arrange: | ||
const restrictions = [ | ||
{ | ||
restrictionKey: '12345', | ||
restrictionValue: '10' | ||
}, | ||
{ | ||
restrictionKey: '67890', | ||
restrictionValue: '15' | ||
} | ||
]; | ||
|
||
const wrapper = setupStoreMount(restrictions); | ||
|
||
// Act: | ||
const titles = wrapper.findAll('.restriction'); | ||
const contents = wrapper.findAll('.restriction-content'); | ||
|
||
//Assert: | ||
expect(titles.length).toBe(2); | ||
expect(contents.length).toBe(2); | ||
|
||
expect(titles.at(0).attributes().title).toBe('Value: 10'); | ||
expect(contents.at(0).text()).toBe('Key 12345 : 10'); | ||
|
||
expect(titles.at(1).attributes().title).toBe('Value: 15'); | ||
expect(contents.at(1).text()).toBe('Key 67890 : 15'); | ||
}); | ||
}); | ||
|
||
describe('mosaic global restriction', () => { | ||
it('renders restriction field with different restriction type', () => { | ||
// Arrange: | ||
const restrictionTypes = ['EQ', 'GE', 'GT', 'LE', 'LT', 'NE', 'NONE']; | ||
|
||
const restrictions = restrictionTypes.map(type => ({ | ||
restrictionKey: '567890', | ||
restrictionType: 'mosaicRestrictionType.' + type, | ||
restrictionValue: '10', | ||
referenceMosaicId: '1788BA84888894EB' | ||
})); | ||
|
||
const wrapper = setupStoreMount(restrictions); | ||
|
||
// Act: | ||
const titles = wrapper.findAll('.restriction'); | ||
const contents = wrapper.findAll('.restriction-content'); | ||
|
||
//Assert: | ||
expect(titles.length).toBe(7); | ||
expect(contents.length).toBe(7); | ||
|
||
const expectedResult = [ | ||
'Equal', | ||
'Greater Than Or Equal', | ||
'Greater Than', | ||
'Less Than Or Equal', | ||
'Less Than', | ||
'Not Equal', | ||
'No Restriction' | ||
]; | ||
|
||
expectedResult.forEach((result, index) => { | ||
expect(titles.at(index).attributes().title).toBe(`Restriction Type: ${result} | Value: 10`); | ||
expect(contents.at(index).text()).toBe(`1788BA84888894EB Key 567890 ${result} 10`); | ||
}); | ||
}); | ||
}); | ||
}); |
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,161 @@ | ||
import { RestrictionService } from '../../src/infrastructure'; | ||
import TestHelper from '../TestHelper'; | ||
import { restore, stub } from 'sinon'; | ||
import { MosaicId, UInt64, MosaicRestrictionType, Address } from 'symbol-sdk'; | ||
|
||
describe('RestrictionService', () => { | ||
describe('formatMosaicGlobalRestriction', () => { | ||
const runBasicMosaicGlobalRestrictionTests = (restrictionType, expectedResult) => { | ||
const createMosaicGlobalRestriction = referenceMosaicId => { | ||
return { | ||
compositeHash: 'E040D414A6F2E083EC4EBC5060461385E71392F292D6D25ADF7F1CBD0C24CE99', | ||
entryType: 1, | ||
mosaicId: new MosaicId('1788BA84888894EB'), | ||
restrictions: [{ | ||
key: UInt64.fromUint(790526), | ||
referenceMosaicId, | ||
restrictionType: restrictionType.type, | ||
restrictionValue: UInt64.fromUint(10) | ||
}], | ||
version: 1 | ||
}; | ||
}; | ||
|
||
it(`returns mosaic global restriction dto with type ${restrictionType.name} and with self reference mosaic`, () => { | ||
// Arrange: | ||
const mosaicGlobalRestriction = createMosaicGlobalRestriction(new MosaicId('0'.repeat(16))); | ||
|
||
// Act: | ||
const result = RestrictionService.formatMosaicGlobalRestriction(mosaicGlobalRestriction); | ||
|
||
// Assert: | ||
expect(result).toEqual({ | ||
compositeHash: mosaicGlobalRestriction.compositeHash, | ||
version: 1, | ||
entryType: 'Mosaic global restriction', | ||
mosaicId: '1788BA84888894EB', | ||
restrictions: [{ | ||
restrictionKey: '790526', | ||
restrictionType: expectedResult, | ||
restrictionValue: '10', | ||
referenceMosaicId: '1788BA84888894EB' | ||
}] | ||
}); | ||
}); | ||
|
||
it(`returns mosaic global restriction dto with type ${restrictionType.name} and reference mosaic`, () => { | ||
// Arrange: | ||
const mosaicGlobalRestriction = createMosaicGlobalRestriction(new MosaicId('0845619DCCC7C163')); | ||
|
||
// Act: | ||
const result = RestrictionService.formatMosaicGlobalRestriction(mosaicGlobalRestriction); | ||
|
||
// Assert: | ||
expect(result).toEqual({ | ||
compositeHash: mosaicGlobalRestriction.compositeHash, | ||
version: 1, | ||
entryType: 'Mosaic global restriction', | ||
mosaicId: '1788BA84888894EB', | ||
restrictions: [{ | ||
restrictionKey: '790526', | ||
restrictionType: expectedResult, | ||
restrictionValue: '10', | ||
referenceMosaicId: '0845619DCCC7C163' | ||
}] | ||
}); | ||
}); | ||
}; | ||
|
||
// Arrange: | ||
const data = [ | ||
{ | ||
restrictionType: { | ||
type: MosaicRestrictionType.EQ, | ||
name: 'equal' | ||
}, | ||
expectedResult: 'mosaicRestrictionType.EQ' | ||
}, | ||
{ | ||
restrictionType: { | ||
type: MosaicRestrictionType.GE, | ||
name: 'great equal' | ||
}, | ||
expectedResult: 'mosaicRestrictionType.GE' | ||
}, | ||
{ | ||
restrictionType: { | ||
type: MosaicRestrictionType.GT, | ||
name: 'greater than' | ||
}, | ||
expectedResult: 'mosaicRestrictionType.GT' | ||
}, | ||
{ | ||
restrictionType: { | ||
type: MosaicRestrictionType.LE, | ||
name: 'less equal' | ||
}, | ||
expectedResult: 'mosaicRestrictionType.LE' | ||
}, | ||
{ | ||
restrictionType: { | ||
type: MosaicRestrictionType.LT, | ||
name: 'less than' | ||
}, | ||
expectedResult: 'mosaicRestrictionType.LT' | ||
}, | ||
{ | ||
restrictionType: { | ||
type: MosaicRestrictionType.NE, | ||
name: 'not equal' | ||
}, | ||
expectedResult: 'mosaicRestrictionType.NE' | ||
}, | ||
{ | ||
restrictionType: { | ||
type: MosaicRestrictionType.NONE, | ||
name: 'no restriction' | ||
}, | ||
expectedResult: 'mosaicRestrictionType.NONE' | ||
} | ||
]; | ||
|
||
data.forEach(info => { | ||
runBasicMosaicGlobalRestrictionTests(info.restrictionType, info.expectedResult); | ||
}); | ||
}); | ||
|
||
describe('formatMosaicAddressRestriction', () => { | ||
it('returns mosaic address restriction dto', () => { | ||
// Arrange: | ||
const targetAddress = TestHelper.generateAccount(1)[0].address; | ||
|
||
const mosaicGlobalRestriction = { | ||
compositeHash: 'E040D414A6F2E083EC4EBC5060461385E71392F292D6D25ADF7F1CBD0C24CE99', | ||
entryType: 0, | ||
mosaicId: new MosaicId('1788BA84888894EB'), | ||
restrictions: [{ | ||
key: UInt64.fromUint(790526), | ||
restrictionValue: UInt64.fromUint(10) | ||
}], | ||
targetAddress, | ||
version: 1 | ||
}; | ||
|
||
// Act: | ||
const result = RestrictionService.formatMosaicAddressRestriction(mosaicGlobalRestriction); | ||
|
||
// Assert: | ||
expect(result).toEqual({ | ||
compositeHash: mosaicGlobalRestriction.compositeHash, | ||
version: 1, | ||
entryType: 'Mosaic address restriction', | ||
mosaicId: '1788BA84888894EB', | ||
restrictions: [{ | ||
restrictionKey: '790526', | ||
restrictionValue: '10' | ||
}], | ||
targetAddress: targetAddress.plain() | ||
}); | ||
}); | ||
}); | ||
}); |
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