This repository has been archived by the owner on Jan 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generation of transaction template based on user selection
Signed-off-by: Erin Hughes <Erin.Hughes@ibm.com>
- Loading branch information
1 parent
7cc22b5
commit f0d1e91
Showing
17 changed files
with
649 additions
and
149 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
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,122 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import App from '../../src/App'; | ||
import chai from 'chai'; | ||
import sinon from 'sinon'; | ||
import sinonChai from 'sinon-chai'; | ||
import ISmartContract from '../../src/interfaces/ISmartContract'; | ||
import ITransaction from '../../src/interfaces/ITransaction'; | ||
import Utils from '../../src/Utils'; | ||
chai.should(); | ||
chai.use(sinonChai); | ||
|
||
describe('App', () => { | ||
|
||
let mySandBox: sinon.SinonSandbox; | ||
|
||
const mockTxn: ITransaction = { | ||
name: 'mockTxn', | ||
parameters: [{ | ||
description: '', | ||
name: 'name', | ||
schema: {} | ||
}], | ||
returns: { | ||
type: '' | ||
}, | ||
tag: ['submit'] | ||
}; | ||
|
||
const greenContract: ISmartContract = { | ||
name: 'greenContract', | ||
version: '0.0.1', | ||
channel: 'mychannel', | ||
label: 'greenContract@0.0.1', | ||
transactions: [mockTxn], | ||
namespace: 'GreenContract' | ||
}; | ||
|
||
const blueContract: ISmartContract = { | ||
name: 'blueContract', | ||
version: '0.0.1', | ||
channel: 'mychannel', | ||
label: 'blueContract@0.0.1', | ||
transactions: [mockTxn], | ||
namespace: 'BlueContract' | ||
}; | ||
|
||
const mockState: { smartContracts: Array<ISmartContract>, activeSmartContract: ISmartContract } = { | ||
smartContracts: [greenContract, blueContract], | ||
activeSmartContract: greenContract | ||
}; | ||
|
||
beforeEach(async () => { | ||
mySandBox = sinon.createSandbox(); | ||
}); | ||
|
||
afterEach(async () => { | ||
mySandBox.restore(); | ||
}); | ||
|
||
it('should redirect to the transaction home view', async () => { | ||
const component: any = mount(<App/>); | ||
|
||
const msg: MessageEvent = new MessageEvent('message', { | ||
data: { | ||
path: '/transaction', | ||
state: mockState | ||
} | ||
}); | ||
dispatchEvent(msg); | ||
expect(component.state().redirectPath).toBe('/transaction'); | ||
}); | ||
|
||
it('should redirect to the transaction create view', async () => { | ||
const component: any = mount(<App/>); | ||
|
||
const msg: MessageEvent = new MessageEvent('message', { | ||
data: { | ||
path: '/transaction/create', | ||
state: { | ||
smartContracts: [greenContract, blueContract], | ||
activeSmartContract: greenContract | ||
} | ||
} | ||
}); | ||
dispatchEvent(msg); | ||
expect(component.state().redirectPath).toBe('/transaction/create'); | ||
}); | ||
|
||
it('does not overwrite state when redirecting to a different page', async () => { | ||
const component: any = mount(<App/>); | ||
|
||
const msg: MessageEvent = new MessageEvent('message', { | ||
data: { | ||
path: '/transaction', | ||
state: mockState | ||
} | ||
}); | ||
dispatchEvent(msg); | ||
expect(component.state().childState).toBe(mockState); | ||
|
||
Utils.changeRoute('/transaction/create'); | ||
expect(component.state().childState).toBe(mockState); | ||
}); | ||
|
||
it('updates the state correctly when switching smart contracts', async () => { | ||
const component: any = mount(<App/>); | ||
|
||
const msg: MessageEvent = new MessageEvent('message', { | ||
data: { | ||
path: '/transaction', | ||
state: mockState | ||
} | ||
}); | ||
dispatchEvent(msg); | ||
expect(component.state().childState.activeSmartContract).toBe(greenContract); | ||
|
||
component.instance().switchSmartContract('blueContract@0.0.1'); | ||
expect(component.state().childState.activeSmartContract).toBe(blueContract); | ||
}); | ||
|
||
}); |
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
Oops, something went wrong.