|
@@ -14,6 +14,17 @@ jest.mock('@/api/user', () => ({ fetchNetworkStats: jest.fn() }))
|
|
|
jest.mock('@/utils/request', () => jest.fn())
|
|
jest.mock('@/utils/request', () => jest.fn())
|
|
|
jest.mock('@/components/TreeChart/index.vue', () => ({}))
|
|
jest.mock('@/components/TreeChart/index.vue', () => ({}))
|
|
|
jest.mock('@/utils/usersInfo', () => ({}))
|
|
jest.mock('@/utils/usersInfo', () => ({}))
|
|
|
|
|
+jest.mock('echarts/core', () => ({
|
|
|
|
|
+ use: jest.fn(),
|
|
|
|
|
+ registerLayout: jest.fn(),
|
|
|
|
|
+ init: jest.fn(() => ({
|
|
|
|
|
+ on: jest.fn(), resize: jest.fn(), setOption: jest.fn(), dispose: jest.fn(), dispatchAction: jest.fn(),
|
|
|
|
|
+ getModel: () => ({ getSeriesByIndex: () => ({ getData: () => ({ each: () => {}, getItemGraphicEl: () => null }) }) })
|
|
|
|
|
+ }))
|
|
|
|
|
+}))
|
|
|
|
|
+jest.mock('echarts/charts', () => ({ TreeChart: {}}))
|
|
|
|
|
+jest.mock('echarts/components', () => ({ TooltipComponent: {}}))
|
|
|
|
|
+jest.mock('echarts/renderers', () => ({ CanvasRenderer: {}}))
|
|
|
Vue.use(ElementUI)
|
|
Vue.use(ElementUI)
|
|
|
Vue.prototype.$t = key => key
|
|
Vue.prototype.$t = key => key
|
|
|
Vue.prototype.$message = jest.fn()
|
|
Vue.prototype.$message = jest.fn()
|
|
@@ -44,6 +55,7 @@ function loadComponent(filename) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const SponsorNetwork = loadComponent(path.resolve(__dirname, '../components/network/SponsorNetwork.vue'))
|
|
const SponsorNetwork = loadComponent(path.resolve(__dirname, '../components/network/SponsorNetwork.vue'))
|
|
|
|
|
+const networkLayout = jest.requireMock('echarts/core').registerLayout.mock.calls[0][1]
|
|
|
const legacy = file => loadComponent(path.resolve(process.cwd(), 'src/views/atlas', file))
|
|
const legacy = file => loadComponent(path.resolve(process.cwd(), 'src/views/atlas', file))
|
|
|
const root = { USER_ID: 'root', USER_NAME: 'NG00001', REAL_NAME: '', DEC_LV_NAME: 'Silver', EMP_LV_NAME: 'Gold', PERIOD_AT: 173, TOP_NETWORK_DEEP: 3, listPeriodNum: [173], children: null, leaf: false }
|
|
const root = { USER_ID: 'root', USER_NAME: 'NG00001', REAL_NAME: '', DEC_LV_NAME: 'Silver', EMP_LV_NAME: 'Gold', PERIOD_AT: 173, TOP_NETWORK_DEEP: 3, listPeriodNum: [173], children: null, leaf: false }
|
|
|
const child = { ...root, USER_ID: 'child', USER_NAME: 'NG00002', REAL_NAME: 'Preview Member', PERIOD_AT: 164 }
|
|
const child = { ...root, USER_ID: 'child', USER_NAME: 'NG00002', REAL_NAME: 'Preview Member', PERIOD_AT: 164 }
|
|
@@ -68,6 +80,9 @@ function view(vm) {
|
|
|
function toggle(vm, id) {
|
|
function toggle(vm, id) {
|
|
|
return vm.$refs.tree.getNode(id)
|
|
return vm.$refs.tree.getNode(id)
|
|
|
}
|
|
}
|
|
|
|
|
+function diagram(vm) {
|
|
|
|
|
+ return vm.$children.find(child => child.$options.name === 'SponsorNetworkChart')
|
|
|
|
|
+}
|
|
|
function setInput(vm, id, value) {
|
|
function setInput(vm, id, value) {
|
|
|
const input = vm.$el.querySelector(id)
|
|
const input = vm.$el.querySelector(id)
|
|
|
input.value = value
|
|
input.value = value
|
|
@@ -96,6 +111,12 @@ describe('Sponsor Network UI reuses both original network scripts', () => {
|
|
|
expect(request).toHaveBeenCalledWith({ url: '/v1/user/network-stats', method: 'get' })
|
|
expect(request).toHaveBeenCalledWith({ url: '/v1/user/network-stats', method: 'get' })
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ it('leaves the original and other ECharts tree layouts untouched', () => {
|
|
|
|
|
+ const original = { id: 'original-tree', getData: jest.fn() }
|
|
|
|
|
+ networkLayout({ eachSeriesByType: (type, visit) => { expect(type).toBe('tree'); visit(original) } })
|
|
|
|
|
+ expect(original.getData).not.toHaveBeenCalled()
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
it('loads and maps the four backend statistics, keeping decimals and zero values', async() => {
|
|
it('loads and maps the four backend statistics, keeping decimals and zero values', async() => {
|
|
|
const vm = instance()
|
|
const vm = instance()
|
|
|
await settle()
|
|
await settle()
|
|
@@ -224,15 +245,17 @@ describe('Sponsor Network UI reuses both original network scripts', () => {
|
|
|
expect(atlasApi.fetchSponsorNetworkList).toHaveBeenCalledTimes(1)
|
|
expect(atlasApi.fetchSponsorNetworkList).toHaveBeenCalledTimes(1)
|
|
|
expect(atlasApi.fetchSponsorNetwork).toHaveBeenCalledTimes(1)
|
|
expect(atlasApi.fetchSponsorNetwork).toHaveBeenCalledTimes(1)
|
|
|
atlasApi.fetchSponsorNetwork.mockResolvedValue({ data: { allData: [{ ...leaf }], periodNum: 174 }})
|
|
atlasApi.fetchSponsorNetwork.mockResolvedValue({ data: { allData: [{ ...leaf }], periodNum: 174 }})
|
|
|
- const childNode = toggle(extended, 'child')
|
|
|
|
|
- extended.toggleNode(childNode.data, childNode)
|
|
|
|
|
|
|
+ expect(extended.$el.querySelector('.ng-network-tree')).toBeNull()
|
|
|
|
|
+ diagram(extended).handleClick({ componentType: 'series', data: extended.treeData.children[0], name: child.USER_NAME, collapsed: false })
|
|
|
await settle()
|
|
await settle()
|
|
|
expect(atlasApi.fetchSponsorNetwork).toHaveBeenLastCalledWith({ id: 'child', deep: 5, periodNum: null })
|
|
expect(atlasApi.fetchSponsorNetwork).toHaveBeenLastCalledWith({ id: 'child', deep: 5, periodNum: null })
|
|
|
expect(extended.treeData.children[0].children[0].USER_ID).toBe('leaf')
|
|
expect(extended.treeData.children[0].children[0].USER_ID).toBe('leaf')
|
|
|
expect(extended.listPeriodNum).toBe(174)
|
|
expect(extended.listPeriodNum).toBe(174)
|
|
|
- expect(extended.$el.textContent).toContain('Preview Leaf')
|
|
|
|
|
|
|
+ expect(diagram(extended).members.map(member => member.REAL_NAME)).toContain('Preview Leaf')
|
|
|
|
|
+ const renderer = diagram(extended).chart
|
|
|
vm.$el.querySelectorAll('input[type=radio]')[0].click()
|
|
vm.$el.querySelectorAll('input[type=radio]')[0].click()
|
|
|
await settle()
|
|
await settle()
|
|
|
|
|
+ expect(renderer.dispose).toHaveBeenCalledTimes(1)
|
|
|
expect(view(vm)).not.toBe(normal)
|
|
expect(view(vm)).not.toBe(normal)
|
|
|
expect(view(vm).mainUserName).toBe('')
|
|
expect(view(vm).mainUserName).toBe('')
|
|
|
expect(atlasApi.fetchMainUserInfo).toHaveBeenCalledTimes(3)
|
|
expect(atlasApi.fetchMainUserInfo).toHaveBeenCalledTimes(3)
|
|
@@ -244,4 +267,49 @@ describe('Sponsor Network UI reuses both original network scripts', () => {
|
|
|
expect(atlasApi.fetchSponsorNetwork).toHaveBeenCalledTimes(3)
|
|
expect(atlasApi.fetchSponsorNetwork).toHaveBeenCalledTimes(3)
|
|
|
expect(fetchNetworkStats).toHaveBeenCalledTimes(4)
|
|
expect(fetchNetworkStats).toHaveBeenCalledTimes(4)
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ it('renders Ex with ECharts top-down cards and keeps loaded-node toggles local to the chart', async() => {
|
|
|
|
|
+ atlasApi.fetchSponsorNetwork.mockResolvedValue({ data: { allData: [{ ...child, children: [{ ...leaf }] }], periodNum: 173 }})
|
|
|
|
|
+ const vm = instance()
|
|
|
|
|
+ await settle()
|
|
|
|
|
+ vm.$el.querySelectorAll('input[type=radio]')[1].click()
|
|
|
|
|
+ await settle()
|
|
|
|
|
+ const extended = view(vm)
|
|
|
|
|
+ const chart = diagram(extended)
|
|
|
|
|
+ const options = chart.chart.setOption.mock.calls.slice(-1)[0][0]
|
|
|
|
|
+ const series = options.series[0]
|
|
|
|
|
+ expect(series).toEqual(expect.objectContaining({ type: 'tree', orient: 'TB', edgeShape: 'polyline', roam: true, expandAndCollapse: true }))
|
|
|
|
|
+ expect(series.data[0].label.backgroundColor).toBe('#202259')
|
|
|
|
|
+ expect(series.data[0].children[0].children[0].USER_ID).toBe('leaf')
|
|
|
|
|
+ const label = series.label.formatter({ data: child, collapsed: false })
|
|
|
|
|
+ expect(label).toContain('Period: 164')
|
|
|
|
|
+ expect(label).not.toContain('PCV')
|
|
|
|
|
+ const count = atlasApi.fetchSponsorNetwork.mock.calls.length
|
|
|
|
|
+ const button = chart.$el.querySelector('button')
|
|
|
|
|
+ button.click()
|
|
|
|
|
+ await Vue.nextTick()
|
|
|
|
|
+ expect(chart.chart.dispatchAction).toHaveBeenLastCalledWith({ type: 'treeExpandAndCollapse', seriesIndex: 0, dataIndex: 1 })
|
|
|
|
|
+ button.click()
|
|
|
|
|
+ await Vue.nextTick()
|
|
|
|
|
+ expect(atlasApi.fetchSponsorNetwork).toHaveBeenCalledTimes(count)
|
|
|
|
|
+ chart.handleClick({ componentType: 'series', data: leaf })
|
|
|
|
|
+ expect(atlasApi.fetchSponsorNetwork).toHaveBeenCalledTimes(count)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('keeps Ex names as text and empty child lists non-fetching', async() => {
|
|
|
|
|
+ atlasApi.fetchSponsorNetwork.mockResolvedValue({ data: { allData: [{ ...child, REAL_NAME: '<img src=x onerror=alert(1)>', children: [] }], periodNum: 173 }})
|
|
|
|
|
+ const vm = instance()
|
|
|
|
|
+ await settle()
|
|
|
|
|
+ vm.$el.querySelectorAll('input[type=radio]')[1].click()
|
|
|
|
|
+ await settle()
|
|
|
|
|
+ const extended = view(vm)
|
|
|
|
|
+ const chart = diagram(extended)
|
|
|
|
|
+ const data = extended.treeData.children[0]
|
|
|
|
|
+ const tooltip = chart.tooltip({ data })
|
|
|
|
|
+ expect(tooltip.textContent).toContain('<img src=x onerror=alert(1)>')
|
|
|
|
|
+ expect(tooltip.querySelector('img')).toBeNull()
|
|
|
|
|
+ const count = atlasApi.fetchSponsorNetwork.mock.calls.length
|
|
|
|
|
+ chart.handleClick({ componentType: 'series', data })
|
|
|
|
|
+ expect(atlasApi.fetchSponsorNetwork).toHaveBeenCalledTimes(count)
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|