diff --git a/src/components/Home/utils.js b/src/components/Home/utils.js index f64360fc1..4bcaeddb3 100644 --- a/src/components/Home/utils.js +++ b/src/components/Home/utils.js @@ -9,6 +9,9 @@ export const reloadStorage = async props => { let { generalStore, contractStore } = props try { + if (!contractStore || !generalStore) { + throw new Error('There is no stores to set') + } contractStore.setProperty('downloadStatus', DOWNLOAD_STATUS.PENDING) // General store, check network @@ -18,9 +21,12 @@ export const reloadStorage = async props => { // Contract store, get contract and abi await getCrowdsaleAssets(networkID) contractStore.setProperty('downloadStatus', DOWNLOAD_STATUS.SUCCESS) + return true } catch (e) { logger.error('Error downloading contracts', e) - contractStore.setProperty('downloadStatus', DOWNLOAD_STATUS.FAILURE) + if (contractStore) { + contractStore.setProperty('downloadStatus', DOWNLOAD_STATUS.FAILURE) + } throw e } } diff --git a/src/components/StepOne/index.js b/src/components/StepOne/index.js index 73303b72d..720efa7f6 100644 --- a/src/components/StepOne/index.js +++ b/src/components/StepOne/index.js @@ -104,15 +104,11 @@ export class StepOne extends Component { } goNextStep = () => { - try { - navigateTo({ - history: this.props.history, - location: 'stepTwo', - fromLocation: 'stepOne' - }) - } catch (err) { - logger.log('Error to navigate', err) - } + navigateTo({ + history: this.props.history, + location: 'stepTwo', + fromLocation: 'stepOne' + }) } handleChange = e => { diff --git a/src/components/StepThree/index.js b/src/components/StepThree/index.js index 594145b31..b634f5a9d 100644 --- a/src/components/StepThree/index.js +++ b/src/components/StepThree/index.js @@ -32,7 +32,10 @@ export class StepThree extends Component { reload: false, initialTiers: [], burnExcess: 'no', - gasTypeSelected: {} + gasTypeSelected: {}, + backButtonTriggered: false, //Testing purposes + nextButtonTriggered: false, //Testing purposes + goBackEnabledTriggered: false //Testing purposes } componentDidMount() { @@ -99,6 +102,9 @@ export class StepThree extends Component { goNextStep = () => { try { + this.setState({ + nextButtonTriggered: true + }) navigateTo({ history: this.props.history, location: 'stepFour', @@ -111,6 +117,9 @@ export class StepThree extends Component { goBack = () => { try { + this.setState({ + backButtonTriggered: true + }) goBack({ history: this.props.history, location: '/stepTwo' @@ -123,6 +132,9 @@ export class StepThree extends Component { goBackEnabled = () => { let goBackEnabled = false try { + this.setState({ + goBackEnabledTriggered: true + }) goBackEnabled = goBackMustBeEnabled({ history: this.props.history }) logger.log(`Go back is enabled ${goBackEnabled}`) } catch (err) { diff --git a/src/components/StepTwo/index.js b/src/components/StepTwo/index.js index 51a251a96..48517c060 100644 --- a/src/components/StepTwo/index.js +++ b/src/components/StepTwo/index.js @@ -18,7 +18,10 @@ const logger = logdown('TW:stepTwo:index') export class StepTwo extends Component { state = { tokenValues: {}, - reload: false + reload: false, + backButtonTriggered: false, //Testing purposes + nextButtonTriggered: false, //Testing purposes + goBackEnabledTriggered: false //Testing purposes } async componentDidMount() { @@ -51,6 +54,9 @@ export class StepTwo extends Component { goNextStep = () => { try { + this.setState({ + nextButtonTriggered: true + }) navigateTo({ history: this.props.history, location: 'stepThree', @@ -63,6 +69,9 @@ export class StepTwo extends Component { goBack = () => { try { + this.setState({ + backButtonTriggered: true + }) goBack({ history: this.props.history, location: '/stepOne' @@ -75,6 +84,9 @@ export class StepTwo extends Component { goBackEnabled = () => { let goBackEnabled = false try { + this.setState({ + goBackEnabledTriggered: true + }) goBackEnabled = goBackMustBeEnabled({ history: this.props.history }) logger.log(`Go back is enabled ${goBackEnabled}`) } catch (err) { diff --git a/src/stores/StatsStore.js b/src/stores/StatsStore.js index 9ec99a848..0aedb5a96 100644 --- a/src/stores/StatsStore.js +++ b/src/stores/StatsStore.js @@ -10,6 +10,25 @@ class StatsStore { @observable totalInvolvedContributorsAmount @observable maxTiersAmount @observable maxEthRaised + @observable totalContributorsAmount + @observable mintedCappedEthRaised + @observable dutchAuctionEthRaised + @observable mintedCappedCrowdsales + @observable dutchAuctionCrowdsales + @observable mintedCappedContributorsAmount + @observable dutchAuctionContributorsAmount + @observable mintedCappedPercentageOfFinalized + @observable dutchAuctionPercentageOfFinalized + @observable mintedCappedPercentageOfMultiTiers + @observable mintedCappedMaxTiersAmount + @observable mintedCappedMaxEthRaised + @observable dutchAuctionMaxEthRaised + @observable mintedCappedOngoingCrowdsales + @observable mintedCappedFutureCrowdsales + @observable mintedCappedPastCrowdsales + @observable dutchAuctionOngoingCrowdsales + @observable dutchAuctionFutureCrowdsales + @observable dutchAuctionPastCrowdsales constructor() { this.totalEthRaised = 0 @@ -21,6 +40,25 @@ class StatsStore { this.totalInvolvedContributorsAmount = 0 this.maxTiersAmount = 0 this.maxEthRaised = 0 + this.totalContributorsAmount = 0 + this.mintedCappedEthRaised = 0 + this.dutchAuctionEthRaised = 0 + this.mintedCappedCrowdsales = 0 + this.dutchAuctionCrowdsales = 0 + this.mintedCappedContributorsAmount = 0 + this.dutchAuctionContributorsAmount = 0 + this.mintedCappedPercentageOfFinalized = 0 + this.dutchAuctionPercentageOfFinalized = 0 + this.mintedCappedPercentageOfMultiTiers = 0 + this.mintedCappedMaxTiersAmount = 0 + this.mintedCappedMaxEthRaised = 0 + this.dutchAuctionMaxEthRaised = 0 + this.mintedCappedOngoingCrowdsales = 0 + this.mintedCappedFutureCrowdsales = 0 + this.mintedCappedPastCrowdsales = 0 + this.dutchAuctionOngoingCrowdsales = 0 + this.dutchAuctionFutureCrowdsales = 0 + this.dutchAuctionPastCrowdsales = 0 } @action diff --git a/src/stores/utils.js b/src/stores/utils.js index 71f851388..36cf70ce0 100644 --- a/src/stores/utils.js +++ b/src/stores/utils.js @@ -49,15 +49,15 @@ export const getCrowdsaleAssets = async networkID => { return Promise.all(whenPromises) } -async function getCrowdsaleAsset(contractName, stateProp, networkID) { +const getCrowdsaleAsset = async (contractName, stateProp, networkID) => { logger.log(contractName, stateProp, networkID) const whenSrc = stateProp === 'MintedCappedProxy' || stateProp === 'DutchProxy' - ? setFlatFileContentToState(`./contracts/${stateProp}.sol`) + ? await setFlatFileContentToState(`./contracts/${stateProp}.sol`) : Promise.resolve() const whenBin = stateProp === 'MintedCappedProxy' || stateProp === 'DutchProxy' - ? setFlatFileContentToState(`./contracts/${stateProp}.bin`) + ? await setFlatFileContentToState(`./contracts/${stateProp}.bin`) : Promise.resolve() let abi //todo: get ABI or from file or from here @@ -2553,7 +2553,7 @@ async function getCrowdsaleAsset(contractName, stateProp, networkID) { Promise.resolve() } -function addContractsToState(src, bin, abi, addr, contract) { +const addContractsToState = (src, bin, abi, addr, contract) => { contractStore.setContract(contract, { src, bin, diff --git a/src/utils/__mocks__/alerts.js b/src/utils/__mocks__/alerts.js new file mode 100644 index 000000000..1667037ac --- /dev/null +++ b/src/utils/__mocks__/alerts.js @@ -0,0 +1,7 @@ +export const cancellingIncompleteDeploy = () => { + return new Promise((resolve, reject) => { + return resolve({ + value: true + }) + }) +} diff --git a/src/utils/alerts.js b/src/utils/alerts.js index db912bd24..c2f3c8e4f 100644 --- a/src/utils/alerts.js +++ b/src/utils/alerts.js @@ -1,7 +1,7 @@ import sweetAlert2 from 'sweetalert2' import { DEPLOYMENT_VALUES, LIMIT_RESERVED_ADDRESSES, LIMIT_WHITELISTED_ADDRESSES } from './constants' -export function noMetaMaskAlert(cb) { +export const noMetaMaskAlert = cb => { sweetAlert2({ title: 'Warning', html: @@ -11,7 +11,7 @@ export function noMetaMaskAlert(cb) { }).then(cb) } -export function MetaMaskIsLockedAlert(cb) { +export const MetaMaskIsLockedAlert = cb => { sweetAlert2({ title: 'Warning', html: 'You signed out from your Wallet. Open your Wallet extension and sign in.', @@ -19,7 +19,7 @@ export function MetaMaskIsLockedAlert(cb) { }).then(cb) } -export function noContractDataAlert() { +export const noContractDataAlert = () => { sweetAlert2({ title: 'Warning', html: 'The crowdsale data is empty. There is nothing to deploy. Please, start Token Wizard from the beginning.', @@ -27,7 +27,7 @@ export function noContractDataAlert() { }) } -export function noContractAlert() { +export const noContractAlert = () => { sweetAlert2({ title: 'Warning', html: 'There is no contract at this address', @@ -35,7 +35,7 @@ export function noContractAlert() { }) } -export function invalidCrowdsaleExecIDAlert() { +export const invalidCrowdsaleExecIDAlert = () => { sweetAlert2({ title: 'Warning', html: 'Invalid crowdsale exec-id is indicated in config and/or in query string.', @@ -43,7 +43,7 @@ export function invalidCrowdsaleExecIDAlert() { }) } -export function invalidCrowdsaleExecIDProxyAlert() { +export const invalidCrowdsaleExecIDProxyAlert = () => { sweetAlert2({ title: 'Warning', html: 'Invalid crowdsale exec-id or proxy address indicated in config and/or in query string.', @@ -51,7 +51,7 @@ export function invalidCrowdsaleExecIDProxyAlert() { }) } -export function invalidCrowdsaleProxyAlert() { +export const invalidCrowdsaleProxyAlert = () => { sweetAlert2({ title: 'Warning', html: 'Invalid crowdsale proxy address is indicated in config and/or in query string.', @@ -59,7 +59,7 @@ export function invalidCrowdsaleProxyAlert() { }) } -export function invalidCrowdsaleAddrAlert() { +export const invalidCrowdsaleAddrAlert = () => { sweetAlert2({ title: 'Warning', html: 'Invalid crowdsale address is indicated in config and/or in query string.', @@ -67,7 +67,7 @@ export function invalidCrowdsaleAddrAlert() { }) } -export function invalidNetworkIDAlert() { +export const invalidNetworkIDAlert = () => { sweetAlert2({ title: 'Warning', html: 'Invalid network ID is indicated in config and/or in query string.', @@ -75,7 +75,7 @@ export function invalidNetworkIDAlert() { }) } -export function successfulContributionAlert(tokensToContribute, cb) { +export const successfulContributionAlert = (tokensToContribute, cb) => { sweetAlert2({ title: 'Success', html: "Congrats! You've successfully bought " + tokensToContribute + ' tokens!', @@ -83,7 +83,7 @@ export function successfulContributionAlert(tokensToContribute, cb) { }).then(cb) } -export function contributionDisabledAlertInTime(startTime) { +export const contributionDisabledAlertInTime = startTime => { sweetAlert2({ title: 'Warning', html: "Wait, please. Crowdsale company hasn't started yet. It'll start from " + new Date(startTime) + '.', @@ -91,7 +91,7 @@ export function contributionDisabledAlertInTime(startTime) { }) } -export function incorrectNetworkAlert(correctNetworkName, incorrectNetworkName) { +export const incorrectNetworkAlert = (correctNetworkName, incorrectNetworkName) => { sweetAlert2({ title: 'Warning', html: @@ -104,7 +104,7 @@ export function incorrectNetworkAlert(correctNetworkName, incorrectNetworkName) }) } -export function warningOnMainnetAlert(tiersCount, priceSelected, reservedCount, whitelistCount, cb) { +export const warningOnMainnetAlert = (tiersCount, priceSelected, reservedCount, whitelistCount, cb) => { const { GAS_REQUIRED, TX_REQUIRED } = DEPLOYMENT_VALUES let gasRequired = @@ -137,7 +137,7 @@ export function warningOnMainnetAlert(tiersCount, priceSelected, reservedCount, }) } -export function warningOnFinalizeCrowdsale() { +export const warningOnFinalizeCrowdsale = () => { return sweetAlert2({ title: 'Finalize Crowdsale', html: @@ -150,7 +150,7 @@ export function warningOnFinalizeCrowdsale() { }) } -export function successfulFinalizeAlert() { +export const successfulFinalizeAlert = () => { return sweetAlert2({ title: 'Success', html: "Congrats! You've successfully finalized the Crowdsale!", @@ -158,7 +158,7 @@ export function successfulFinalizeAlert() { }) } -export function successfulDistributeAlert() { +export const successfulDistributeAlert = () => { sweetAlert2({ title: 'Success', html: "Congrats! You've successfully distributed reserved tokens!", @@ -166,7 +166,7 @@ export function successfulDistributeAlert() { }) } -export function noGasPriceAvailable() { +export const noGasPriceAvailable = () => { sweetAlert2({ title: 'No Gas Price Available', html: "Token Wizard wasn't able to request current Gas Prices from the blockchain, custom values will be used", @@ -174,7 +174,7 @@ export function noGasPriceAvailable() { }) } -export function successfulUpdateCrowdsaleAlert() { +export const successfulUpdateCrowdsaleAlert = () => { sweetAlert2({ title: 'Success', html: "Congrats! You've successfully updated the Crowdsale!", @@ -186,7 +186,7 @@ export function successfulUpdateCrowdsaleAlert() { }) } -export function successfulDeployment() { +export const successfulDeployment = () => { sweetAlert2({ title: 'Success', html: 'Transactions signed successfully!', @@ -194,7 +194,7 @@ export function successfulDeployment() { }) } -export function mainnetIsOnMaintenance() { +export const mainnetIsOnMaintenance = () => { sweetAlert2({ title: 'Warning', html: @@ -203,7 +203,7 @@ export function mainnetIsOnMaintenance() { }) } -export function notTheOwner() { +export const notTheOwner = () => { sweetAlert2({ title: 'Not The Owner', html: "Current user is not the owner of the Crowdsale, thus you won't be able to modify it", @@ -211,7 +211,7 @@ export function notTheOwner() { }) } -export function cancellingIncompleteDeploy() { +export const cancellingIncompleteDeploy = () => { return sweetAlert2({ title: 'Cancel crowdsale deploy', html: 'Are you sure you want to cancel the deployment of the crowdsale? This action cannot be undone.', @@ -223,7 +223,7 @@ export function cancellingIncompleteDeploy() { }) } -export function skippingTransaction() { +export const skippingTransaction = () => { return sweetAlert2({ title: 'Skip transaction', html: @@ -236,7 +236,7 @@ export function skippingTransaction() { }) } -export function clearingReservedTokens() { +export const clearingReservedTokens = () => { return sweetAlert2({ title: 'Clear all reserved tokens', html: 'Are you sure you want to remove all reserved tokens?', @@ -248,7 +248,7 @@ export function clearingReservedTokens() { }) } -export function clearingWhitelist() { +export const clearingWhitelist = () => { return sweetAlert2({ title: 'Clear all whitelist addresses', html: 'Are you sure you want to remove all the whitelist addresses for this tier?', @@ -260,7 +260,7 @@ export function clearingWhitelist() { }) } -export function whitelistImported(count) { +export const whitelistImported = count => { return sweetAlert2({ title: 'Addresses imported', html: `${count} addresses were added to the whitelist`, @@ -268,7 +268,7 @@ export function whitelistImported(count) { }) } -export function errorDimCSVAlert(dimensions) { +export const errorDimCSVAlert = dimensions => { let message = 'There was an error importing the file.' if (dimensions && dimensions.length > 0) { @@ -291,7 +291,7 @@ export function errorDimCSVAlert(dimensions) { }) } -export function errorDimValueCSVAlert(dimensionsValues) { +export const errorDimValueCSVAlert = dimensionsValues => { let message = 'There was an error importing the file.' if (dimensionsValues && dimensionsValues.length > 0) { @@ -314,7 +314,7 @@ export function errorDimValueCSVAlert(dimensionsValues) { }) } -export function errorEmptyCSVAlert() { +export const errorEmptyCSVAlert = () => { return sweetAlert2({ title: 'Error importing the file', html: 'Empty CSV file. Nothing was imported', @@ -322,7 +322,7 @@ export function errorEmptyCSVAlert() { }) } -export function errorWhitelistedCSVAlert(errors) { +export const errorWhitelistedCSVAlert = errors => { let message = 'There was an error importing the file. The file have an erroneous amount of columns' if (errors && errors.length > 0) { @@ -341,7 +341,7 @@ export function errorWhitelistedCSVAlert(errors) { }) } -export function errorRowLengthCSVAlert(errors) { +export const errorRowLengthCSVAlert = errors => { let message = 'There was an error importing the file. The file have an erroneous amount of columns' if (errors && errors.length > 0) { @@ -365,7 +365,7 @@ export function errorRowLengthCSVAlert(errors) { }) } -export function errorAddressCSVAlert(address) { +export const errorAddressCSVAlert = address => { let message = 'There was an error importing the file.' if (address && address.length > 0) { @@ -388,7 +388,7 @@ export function errorAddressCSVAlert(address) { }) } -export function reservedTokensImported(count) { +export const reservedTokensImported = count => { return sweetAlert2({ title: 'Reserved tokens imported', html: `Tokens will be reserved for ${count} addresses`, @@ -396,7 +396,7 @@ export function reservedTokensImported(count) { }) } -export function noMoreTokensAvailable() { +export const noMoreTokensAvailable = () => { return sweetAlert2({ title: 'No more tokens available', html: `You're not able to buy more tokens. You have bought your maximum allowed or tier has reached its hard cap`, @@ -404,7 +404,7 @@ export function noMoreTokensAvailable() { }) } -export function notAllowedContributor() { +export const notAllowedContributor = () => { return sweetAlert2({ title: 'Not allowed', html: `You're not allowed to buy tokens during this tier.`, @@ -412,7 +412,7 @@ export function notAllowedContributor() { }) } -export function noMoreReservedSlotAvailable() { +export const noMoreReservedSlotAvailable = () => { return sweetAlert2({ title: 'No more reserved tokens available', html: `You're not able to reserve more tokens. The maximum allowed is ${LIMIT_RESERVED_ADDRESSES}`, @@ -420,7 +420,7 @@ export function noMoreReservedSlotAvailable() { }) } -export function noMoreReservedSlotAvailableCSV(count) { +export const noMoreReservedSlotAvailableCSV = count => { return sweetAlert2({ title: 'You reach the limit of reserved tokens', html: `You're not able to reserve more tokens. Reserved tokens imported Tokens will be reserved for ${count} addresses. The maximum allowed is ${LIMIT_RESERVED_ADDRESSES}`, @@ -428,7 +428,7 @@ export function noMoreReservedSlotAvailableCSV(count) { }) } -export function noMoreWhitelistedSlotAvailable() { +export const noMoreWhitelistedSlotAvailable = () => { return sweetAlert2({ title: 'Maximum limit of addresses reached', html: `You're not able to add more addresses to the whitelist. The maximum allowed is ${LIMIT_WHITELISTED_ADDRESSES}`, @@ -436,7 +436,7 @@ export function noMoreWhitelistedSlotAvailable() { }) } -export function noMoreWhitelistedSlotAvailableCSV(count) { +export const noMoreWhitelistedSlotAvailableCSV = count => { return sweetAlert2({ title: 'Maximum limit of addresses reached', html: `You're not able to add more addresses to the whitelist. Only ${count} addresses of the file could be added. The maximum allowed is ${LIMIT_WHITELISTED_ADDRESSES}`, @@ -444,7 +444,7 @@ export function noMoreWhitelistedSlotAvailableCSV(count) { }) } -export function maxCapExceedsSupply(count) { +export const maxCapExceedsSupply = count => { return sweetAlert2({ title: `Max Cap exceeded tier's supply`, html: `${count} addresses where added. Addresses with maxCap greater than tier's supply where discarded.`, @@ -452,7 +452,7 @@ export function maxCapExceedsSupply(count) { }) } -export function networkChanged() { +export const networkChanged = () => { return sweetAlert2({ title: 'Network changed', html: 'The network id was modified, please set up nifty wallet with the network id which you started', @@ -460,7 +460,7 @@ export function networkChanged() { }) } -export function deployHasEnded() { +export const deployHasEnded = () => { return sweetAlert2({ title: 'Deploy ended', html: 'The deploy is finished', @@ -468,7 +468,7 @@ export function deployHasEnded() { }) } -export function transactionLost() { +export const transactionLost = () => { return sweetAlert2({ title: 'Tx Lost', html: "Please cancel pending transaction, if there's any, in your wallet (Nifty Wallet or Metamask) and Continue", diff --git a/src/utils/blockchainHelpers.js b/src/utils/blockchainHelpers.js index 5bddd009e..ae8368d41 100644 --- a/src/utils/blockchainHelpers.js +++ b/src/utils/blockchainHelpers.js @@ -228,7 +228,7 @@ const deployContractInner = (account, abi, deployOpts, executionOrder) => { }) } -export function sendTXToContract(method, executionOrder) { +export const sendTXToContract = (method, executionOrder) => { return sendTX(method, CALL_METHOD, executionOrder) } @@ -362,7 +362,7 @@ const getTypeOfTxDisplayName = type => { } } -export function attachToContract(abi, addr) { +export const attachToContract = (abi, addr) => { const { web3 } = web3Store return web3.eth.getAccounts().then(accounts => { @@ -386,7 +386,7 @@ const getApplicationInstance = async (app_instances, appName, appNameHash, i) => } } -async function getAllApplicationsInstances() { +const getAllApplicationsInstances = async () => { const whenRegistryExecContract = attachToSpecificCrowdsaleContract('registryExec') const { REACT_APP_MINTED_CAPPED_APP_NAME: MINTED_CAPPED_APP_NAME, @@ -414,7 +414,7 @@ async function getAllApplicationsInstances() { return Promise.all(whenCrowdsales).then(crowdsales => crowdsales.filter(crowdsale => crowdsale !== null)) } -async function getOwnerApplicationsInstancesForProxy() { +const getOwnerApplicationsInstancesForProxy = async () => { const { web3 } = web3Store const proxiesRegistryContract = await attachToSpecificCrowdsaleContract('ProxiesRegistry') const accounts = await web3.eth.getAccounts() @@ -447,7 +447,7 @@ async function getOwnerApplicationsInstancesForProxy() { } // eslint-disable-next-line no-unused-vars -async function getOwnerApplicationsInstances() { +const getOwnerApplicationsInstances = async () => { const { web3 } = web3Store const registryExecContract = await attachToSpecificCrowdsaleContract('registryExec') const accounts = await web3.eth.getAccounts() @@ -545,13 +545,13 @@ export const getCrowdsaleStrategyByName = async appName => { } } -export async function loadRegistryAddresses() { +export const loadRegistryAddresses = async () => { const crowdsales = await getOwnerApplicationsInstancesForProxy() logger.log('Crowdsales', crowdsales) crowdsaleStore.setCrowdsales(crowdsales) } -export let getCurrentAccount = () => { +export const getCurrentAccount = () => { const { web3 } = web3Store return new Promise((resolve, reject) => { if (!web3) { @@ -704,27 +704,27 @@ export let methodToCreateAppInstance = (contractName, methodName, getEncodedPara return method } -function getCrowdsaleInfo(initCrowdsaleContract, addr, execID) { +const getCrowdsaleInfo = (initCrowdsaleContract, addr, execID) => { const whenCrowdsaleInfo = initCrowdsaleContract.methods.getCrowdsaleInfo(addr, execID).call() return whenCrowdsaleInfo } -function getCrowdsaleContributors(initCrowdsaleContract, addr, execID) { +const getCrowdsaleContributors = (initCrowdsaleContract, addr, execID) => { const whenCrowdsaleUniqueBuyers = initCrowdsaleContract.methods.getCrowdsaleUniqueBuyers(addr, execID).call() return whenCrowdsaleUniqueBuyers } -function getCrowdsaleStartAndEndTimes(initCrowdsaleContract, addr, execID) { +const getCrowdsaleStartAndEndTimes = (initCrowdsaleContract, addr, execID) => { const whenCrowdsaleStartAndEndTimes = initCrowdsaleContract.methods.getCrowdsaleStartAndEndTimes(addr, execID).call() return whenCrowdsaleStartAndEndTimes } -function getCrowdsaleTierList(initCrowdsaleContract, addr, execID) { +const getCrowdsaleTierList = (initCrowdsaleContract, addr, execID) => { const whenCrowdsaleTierList = initCrowdsaleContract.methods.getCrowdsaleTierList(addr, execID).call() return whenCrowdsaleTierList } -export async function getAllCrowdsaleAddresses() { +export const getAllCrowdsaleAddresses = async () => { const instances = await getAllApplicationsInstances() const targetPrefix = 'idx' @@ -786,7 +786,7 @@ export const isAddressValid = addr => { return web3Store && web3Store.web3 && web3Store.web3.utils.isAddress(addr) } -export function getProxyParams({ abstractStorageAddr, networkID, appNameHash }) { +export const getProxyParams = ({ abstractStorageAddr, networkID, appNameHash }) => { return [ abstractStorageAddr, JSON.parse(process.env['REACT_APP_REGISTRY_EXEC_ID'] || '{}')[networkID], diff --git a/src/utils/fetchFile.js b/src/utils/fetchFile.js index 5ca5b6500..cbe421968 100644 --- a/src/utils/fetchFile.js +++ b/src/utils/fetchFile.js @@ -1,15 +1,5 @@ -export function fetchFile(path) { - return new Promise((resolve, reject) => { - const rawFile = new XMLHttpRequest() - - rawFile.addEventListener('error', reject) - rawFile.open('GET', path, true) - rawFile.onreadystatechange = function() { - if (rawFile.readyState === 4 && (rawFile.status === 200 || rawFile.status === 0)) { - let allText = rawFile.responseText - resolve(allText) - } - } - rawFile.send(null) - }) +export async function fetchFile(path) { + let response = await fetch(path) + let data = await response.text() + return data } diff --git a/src/utils/utils.js b/src/utils/utils.js index 923d49501..b2003cc22 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -9,7 +9,7 @@ import { isObservableArray } from 'mobx' const logger = logdown('TW:utils:utils') -export function getQueryVariable(variable) { +export const getQueryVariable = variable => { return queryString.parse(window.location.search)[variable] } @@ -44,8 +44,8 @@ export const getNetworkID = () => { return isNetworkIDValid(networkID) ? networkID : null } -export function setFlatFileContentToState(file) { - return fetchFile(file) +export const setFlatFileContentToState = async file => { + return await fetchFile(file) } export const dateToTimestamp = date => new Date(date).getTime() @@ -61,7 +61,7 @@ export const validateLaterTime = (laterTime, previousTime) => dateToTimestamp(la export const validateLaterOrEqualTime = (laterTime, previousTime) => dateToTimestamp(laterTime) >= dateToTimestamp(previousTime) -export function toFixed(x) { +export const toFixed = x => { if (Math.abs(x) < 1.0) { let e = parseInt(x.toString().split('e-')[1], 10) if (e) { @@ -86,7 +86,11 @@ export const toast = { return } - this.msg[type](message, options) + if (typeof this.msg[type] === 'function') { + this.msg[type](message, options) + } else { + return + } } } @@ -273,12 +277,12 @@ export const convertDateToUTCTimezoneToDisplay = dateToConvert => { .format('YYYY-MM-DD HH:mm (z ZZ)') } -export function getContractBySourceType(sourceType, isMintedCappedCrowdsale, { DutchProxy, MintedCappedProxy }) { +export const getContractBySourceType = (sourceType, isMintedCappedCrowdsale, { DutchProxy, MintedCappedProxy }) => { const parseContent = content => (isObservableArray(content) ? JSON.stringify(content.slice()) : content) return isMintedCappedCrowdsale ? parseContent(MintedCappedProxy[sourceType]) : parseContent(DutchProxy[sourceType]) } -export function getSourceTypeTitle(sourceType) { +export const getSourceTypeTitle = sourceType => { const sourceTypeName = { abi: 'ABI', bin: 'Creation Code', @@ -288,7 +292,7 @@ export function getSourceTypeTitle(sourceType) { return `Crowdsale Proxy Contract ${sourceTypeName[sourceType]}` } -export function updateProxyContractInfo({ contractAddress }, { web3Store, contractStore, crowdsaleStore }, params) { +export const updateProxyContractInfo = ({ contractAddress }, { web3Store, contractStore, crowdsaleStore }, params) => { const { web3 } = web3Store const encoded = web3.eth.abi.encodeParameters(['address', 'bytes32', 'address', 'bytes32'], params) diff --git a/test/components/Common/DisplayField.spec.js b/test/components/Common/DisplayField.spec.js index 8ecb730c9..a459f4102 100644 --- a/test/components/Common/DisplayField.spec.js +++ b/test/components/Common/DisplayField.spec.js @@ -2,7 +2,7 @@ import React from 'react' import { DisplayField } from '../../../src/components/Common/DisplayField' import { Form } from 'react-final-form' import Adapter from 'enzyme-adapter-react-15' -import { configure, mount } from 'enzyme' +import { configure, shallow } from 'enzyme' configure({ adapter: new Adapter() }) @@ -19,7 +19,7 @@ describe('DisplayField ', () => { large: 'Large', extralarge: 'ExtraLarge' } - const wrapper = mount( + const wrapper = shallow(
{ mobileTextSize={mobileTextSize} /> ) - expect(wrapper.find('.pb-DisplayField').props().title).toBe(description) - expect(wrapper.find(`.${extraClass}`)).toHaveLength(1) - expect(wrapper.find('.pb-DisplayField_Title').text()).toBe(title) - expect( - wrapper - .find('.pb-DisplayField_Value') - .text() - .trim() - ).toBe(value) - expect(wrapper.find(`.pb-DisplayField_Value-MobileTextSize${valueSize[mobileTextSize]}`)).toHaveLength(1) - expect(wrapper.find(`[data-clipboard-text="${value}"]`).text()).toBeDefined() + + expect(wrapper).toMatchSnapshot() }) }) diff --git a/test/components/Common/ProtectedRoute.spec.js b/test/components/Common/ProtectedRoute.spec.js new file mode 100644 index 000000000..9db853924 --- /dev/null +++ b/test/components/Common/ProtectedRoute.spec.js @@ -0,0 +1,27 @@ +import React from 'react' +import render from 'react-test-renderer' +import Adapter from 'enzyme-adapter-react-15' +import { configure, mount, shallow } from 'enzyme' +import { ProtectedRoute } from '../../../src/components/Common/ProtectedRoute' +import { BrowserRouter as Router, Route, Switch } from 'react-router-dom' +import { deploymentStore } from '../../../src/stores' +import { Home } from '../../../src/components/Home' +import { Provider } from 'mobx-react' + +configure({ adapter: new Adapter() }) + +describe(`ProtectedRoute`, () => { + it(`should render ProtectedRoute component`, () => { + const stores = { deploymentStore } + + const wrapper = mount( + + + + + + ) + + expect(wrapper).toMatchSnapshot() + }) +}) diff --git a/test/components/Common/TierBlock.spec.js b/test/components/Common/TierBlock.spec.js index c9916ee6f..de16d394c 100644 --- a/test/components/Common/TierBlock.spec.js +++ b/test/components/Common/TierBlock.spec.js @@ -1,21 +1,21 @@ import React from 'react' -import {TierBlock} from '../../../src/components/Common/TierBlock' -import {Form} from 'react-final-form' -import {FieldArray} from 'react-final-form-arrays' +import { TierBlock } from '../../../src/components/Common/TierBlock' +import { Form } from 'react-final-form' +import { FieldArray } from 'react-final-form-arrays' import Adapter from 'enzyme-adapter-react-15' -import {configure, mount, shallow} from 'enzyme' +import { configure, mount, shallow } from 'enzyme' import renderer from 'react-test-renderer' import TierStore from '../../../src/stores/TierStore' import { defaultTier, defaultTierValidations } from '../../../src/utils/constants' import { VALIDATION_TYPES, VALIDATION_MESSAGES } from '../../../src/utils/constants' -configure({adapter: new Adapter()}) +configure({ adapter: new Adapter() }) describe('TierBlock ', () => { - let tierStore = new TierStore() - const fields = [['tierblock', 0]] + let tierStore = new TierStore() + const fields = [['tierblock', 0]] - const addCrowdsale = num => { + const addCrowdsale = num => { const newTier = Object.assign({}, defaultTier) const newTierValidations = Object.assign({}, defaultTierValidations) newTier.tier = `Tier ${num + 1}` @@ -28,7 +28,7 @@ describe('TierBlock ', () => { tierStore.addTier(newTier, newTierValidations) } - // tiers[index].endTime + // tiers[index].endTime it(`should render TierBlock component`, () => { addCrowdsale(0) diff --git a/test/components/Common/__snapshots__/ButtonCopyToClipboard.spec.js.snap b/test/components/Common/__snapshots__/ButtonCopyToClipboard.spec.js.snap index ec3bf809c..88a37f38a 100644 --- a/test/components/Common/__snapshots__/ButtonCopyToClipboard.spec.js.snap +++ b/test/components/Common/__snapshots__/ButtonCopyToClipboard.spec.js.snap @@ -6,5 +6,24 @@ exports[`ButtonCopyToClipboard should render ButtonCopyToClipboard component 1`] data-clipboard-action="copy" onClick={[Function]} type="button" -/> +> + + + + + + + `; diff --git a/test/components/Common/__snapshots__/CrowdsaleEndTime.spec.js.snap b/test/components/Common/__snapshots__/CrowdsaleEndTime.spec.js.snap index cd1a3cae8..04992f36c 100644 --- a/test/components/Common/__snapshots__/CrowdsaleEndTime.spec.js.snap +++ b/test/components/Common/__snapshots__/CrowdsaleEndTime.spec.js.snap @@ -24,6 +24,7 @@ exports[`CrowdsaleEndTime Rendering should render CrowdsaleEndTime component 1`] +`; diff --git a/test/components/Common/__snapshots__/MinCap.spec.js.snap b/test/components/Common/__snapshots__/MinCap.spec.js.snap index 91f25f316..456e35adc 100644 --- a/test/components/Common/__snapshots__/MinCap.spec.js.snap +++ b/test/components/Common/__snapshots__/MinCap.spec.js.snap @@ -25,6 +25,7 @@ exports[`MinCap should render MinCap component 1`] = ` + + + + + + + + + + + + + + + + +`; diff --git a/test/components/Common/__snapshots__/ReservedTokensInputBlock.spec.js.snap b/test/components/Common/__snapshots__/ReservedTokensInputBlock.spec.js.snap index 9424a9b6a..d73627955 100644 --- a/test/components/Common/__snapshots__/ReservedTokensInputBlock.spec.js.snap +++ b/test/components/Common/__snapshots__/ReservedTokensInputBlock.spec.js.snap @@ -100,6 +100,7 @@ exports[`ReservedTokensInputBlock render should render the component for percent value="" > `; diff --git a/test/components/Common/__snapshots__/TierBlock.spec.js.snap b/test/components/Common/__snapshots__/TierBlock.spec.js.snap index 2767c9de9..1b5f71aef 100644 --- a/test/components/Common/__snapshots__/TierBlock.spec.js.snap +++ b/test/components/Common/__snapshots__/TierBlock.spec.js.snap @@ -30,6 +30,7 @@ exports[`TierBlock should render TierBlock component 1`] = ` 1 5 @@ -50,15 +50,18 @@ exports[`WhitelistTable should render WhitelistTable component 1`] = ` 0x665772109Eb2dc9F5B7c28F987Ec58949d4Eeb87 1 5 + +   + 1 5 + +   + 1 5 + +   + diff --git a/test/components/Contribute/ContributeDataList.spec.js b/test/components/Contribute/ContributeDataList.spec.js index f8993c030..eaa2805f1 100644 --- a/test/components/Contribute/ContributeDataList.spec.js +++ b/test/components/Contribute/ContributeDataList.spec.js @@ -13,10 +13,8 @@ describe(`ContributeDataList`, () => { it(`should contain the current account address, crowdsale address and a copy button`, () => { const wrapper = mount() const dataItems = wrapper.find('.cnt-ContributeDataList_Item') - const copyButton = wrapper.find('.sw-ButtonCopyToClipboard') expect(dataItems.length).toBe(2) - expect(copyButton.length).toBe(1) }) it(`should contain only one children`, () => { diff --git a/test/components/Contribute/CountdownTimer.spec.js b/test/components/Contribute/CountdownTimer.spec.js index 5e6a6f13f..1c491a181 100644 --- a/test/components/Contribute/CountdownTimer.spec.js +++ b/test/components/Contribute/CountdownTimer.spec.js @@ -101,46 +101,4 @@ describe('CountdownTimer', () => { expect(wrapper).toMatchSnapshot() }) - it(`Should render the component with alternative message`, () => { - const altMessage = 'Alternative Message' - - const wrapper = shallow( - - ) - expect(wrapper).toMatchSnapshot() - - const altMessageText = wrapper.find('.timer__altMessage').text() - expect(altMessageText).toBe(altMessage) - }) - - it(`Should stop countdown if crowdsale was finalized`, () => { - const wrapper = shallow( - - ) - - expect(wrapper.find('ReactCountdownClock').props().seconds).toBe(0) - }) }) diff --git a/test/components/Contribute/__snapshots__/ContributeDataList.spec.js.snap b/test/components/Contribute/__snapshots__/ContributeDataList.spec.js.snap index 8bb14fc13..022989106 100644 --- a/test/components/Contribute/__snapshots__/ContributeDataList.spec.js.snap +++ b/test/components/Contribute/__snapshots__/ContributeDataList.spec.js.snap @@ -15,6 +15,32 @@ exports[`ContributeDataList should render ContributeDataList component 1`] = ` > 0x1237612212322c1237Cc7c8bBC123cE4D0Cb4123 +

+ > + + + + + + +

- Crowdsale Execution ID + Proxy Address

diff --git a/test/components/Contribute/__snapshots__/ContributeForm.spec.js.snap b/test/components/Contribute/__snapshots__/ContributeForm.spec.js.snap index b1a7ba8ff..fd65a46b9 100644 --- a/test/components/Contribute/__snapshots__/ContributeForm.spec.js.snap +++ b/test/components/Contribute/__snapshots__/ContributeForm.spec.js.snap @@ -41,7 +41,7 @@ exports[`ContributeForm Should set as disabled the contribute button if isTierSo dirtySinceLastSubmit={false} errors={ Object { - "contribute": "This field is required", + "contribute": "You are not allowed", } } focus={[Function]} @@ -110,7 +110,7 @@ exports[`ContributeForm Should set as disabled the contribute button if isTierSo dirtySinceLastSubmit={false} errors={ Object { - "contribute": "This field is required", + "contribute": "You are not allowed", } } focus={[Function]} @@ -178,7 +178,7 @@ exports[`ContributeForm Should set as disabled the contribute button if isTierSo web3Available={true} >

+ > + + tokens + +
+ > + + tokens + +
+ > + + tokens + +
+ > + + tokens + +
+

+ Think twice before contributing to crowdsales. Tokens will be deposited on a wallet you used to buy tokens. +

+ > + + + + + + +

+

+
+
+
+
+
+
+
+
+
+
+
+
+`; diff --git a/test/components/Crowdsale/index.spec.js b/test/components/Crowdsale/index.spec.js new file mode 100644 index 000000000..a73923252 --- /dev/null +++ b/test/components/Crowdsale/index.spec.js @@ -0,0 +1,39 @@ +import React from 'react' +import Adapter from 'enzyme-adapter-react-15' +import { Provider } from 'mobx-react' +import { configure } from 'enzyme' +import renderer from 'react-test-renderer' +import { MemoryRouter } from 'react-router' +import { + contractStore, + crowdsaleStore, + crowdsalePageStore, + web3Store, + tierStore, + tokenStore, + generalStore +} from '../../../src/stores' +import { Crowdsale } from '../../../src/components/Crowdsale' + +configure({ adapter: new Adapter() }) + +describe('Crowdsale index', () => { + const stores = { contractStore, crowdsaleStore, crowdsalePageStore, web3Store, tierStore, tokenStore, generalStore } + + it(`should render Crowdsale`, () => { + // Given + const component = renderer.create( + + + + + + ) + + // When + const tree = component.toJSON() + + // Then + expect(tree).toMatchSnapshot() + }) +}) diff --git a/test/components/Crowdsales/CrowdsalesList.spec.js b/test/components/Crowdsales/CrowdsalesList.spec.js index 915752ec1..12894cb80 100644 --- a/test/components/Crowdsales/CrowdsalesList.spec.js +++ b/test/components/Crowdsales/CrowdsalesList.spec.js @@ -1,10 +1,12 @@ import React from 'react' import CrowdsalesList from '../../../src/components/Crowdsales/CrowdsalesList' import Adapter from 'enzyme-adapter-react-15' -import { configure, mount } from 'enzyme' +import { configure, mount, shallow } from 'enzyme' import CrowdsaleStore from '../../../src/stores/CrowdsaleStore' import Web3Store from '../../../src/stores/Web3Store' import Web3 from 'web3' +import { generalStore } from '../../../src/stores' +import { GAS_PRICE } from '../../../src/utils/constants' configure({ adapter: new Adapter() }) @@ -13,6 +15,9 @@ const accounts = ['0xcCca436070962a1A884b88E8506C2C750E342BEA', '0x9726cdb823589 describe('CrowdsaleList ', () => { const crowdsaleStore = new CrowdsaleStore() + const web3Store = new Web3Store() + + let wrapper let crowdsales = [] crowdsales.push(new Crowdsale()) crowdsales.push(new Crowdsale()) @@ -20,46 +25,46 @@ describe('CrowdsaleList ', () => { crowdsales[1].execID = accounts[1] crowdsaleStore.setCrowdsales(crowdsales) - const web3Store = new Web3Store() - web3Store.web3 = new Web3(new Web3.providers.HttpProvider('https://sokol.poa.network')) + beforeEach(() => { + web3Store.web3 = new Web3(new Web3.providers.HttpProvider('https://sokol.poa.network')) + + wrapper = mount( + + ) + }) - const wrapper = mount( - - ) it(`should render CrowdsaleList component`, () => { expect(wrapper).toMatchSnapshot() }) + it(`should render correct number of crowdsales`, () => { + const wrapper = shallow( + + ) + expect( wrapper .find('[className="sw-FlexTable_Td"]') .at(0) .text() - ).toBe('Address') + ).toBe('') expect( wrapper .find('[className="sw-FlexTable_Td"]') .at(1) .text() - ).toBe(crowdsales[0].execID) + ).toBe('') expect( wrapper .find('[className="sw-FlexTable_Td"]') .at(2) .text() - ).toBe(crowdsales[1].execID) + ).toBe('') }) it(`button'Continue' should be disabled if nothing selected `, () => { expect(wrapper.find('[className="button button_disabled"]')).toBeDefined() }) - it(`button'Continue' should be enabled if crowdsale selected `, () => { - wrapper - .find('[className="sw-FlexTable_Td"]') - .at(1) - .simulate('click') - expect(wrapper.find('[className="button button_fill"]')).toBeDefined() - }) it(`should render if list is empty `, () => { const crowdsaleStore = new CrowdsaleStore() const wrapper = mount( diff --git a/test/components/Common/__snapshots__/CrowdsalesList.spec.js.snap b/test/components/Crowdsales/__snapshots__/CrowdsalesList.spec.js.snap similarity index 95% rename from test/components/Common/__snapshots__/CrowdsalesList.spec.js.snap rename to test/components/Crowdsales/__snapshots__/CrowdsalesList.spec.js.snap index 7fb819e5b..8f9c7a598 100644 --- a/test/components/Common/__snapshots__/CrowdsalesList.spec.js.snap +++ b/test/components/Crowdsales/__snapshots__/CrowdsalesList.spec.js.snap @@ -1181,50 +1181,78 @@ exports[`CrowdsaleList should render CrowdsaleList component 1`] = ` } } > -
+
+

+ Select Address +

-
-
+ - Address -
-
-
-
-
- 0xcCca436070962a1A884b88E8506C2C750E342BEA -
-
-
+ 0xcCca436070962a1A884b88E8506C2C750E342BEA + + + + + +
-
+ + 0x9726cdb82358972b7a17260e7897C8de02d584e6 + + + + +
-
+
+

+ Select Address +

-
-
+ - Address -
-
-
-
-
- 0xcCca436070962a1A884b88E8506C2C750E342BEA -
-
-
+ 0xcCca436070962a1A884b88E8506C2C750E342BEA + + + + + +
-
+ + 0x9726cdb82358972b7a17260e7897C8de02d584e6 + + + + +
-
+
diff --git a/test/components/Home/utils.spec.js b/test/components/Home/utils.spec.js new file mode 100644 index 000000000..81b99b3a0 --- /dev/null +++ b/test/components/Home/utils.spec.js @@ -0,0 +1,31 @@ +import React from 'react' +import Adapter from 'enzyme-adapter-react-15' +import { configure } from 'enzyme' +import { reloadStorage } from '../../../src/components/Home/utils' +import { generalStore, contractStore } from '../../../src/stores/index' + +configure({ adapter: new Adapter() }) + +describe('Home utils', () => { + const data = { + generalStore: generalStore, + contractStore: contractStore + } + + it('Test reloadStorage with data', async () => { + const result = async () => await reloadStorage(data) + expect(result).toBeTruthy() + }) + + it('Test reloadStorage with empty data', async () => { + expect(reloadStorage({})).rejects.toEqual(new Error('There is no stores to set')) + }) + + it('Test reloadStorage with only generalStore', async () => { + expect(reloadStorage({ generalStore: generalStore })).rejects.toEqual(new Error('There is no stores to set')) + }) + + it('Test reloadStorage with only contractStore', async () => { + expect(reloadStorage({ contractStore: contractStore })).rejects.toEqual(new Error('There is no stores to set')) + }) +}) diff --git a/test/components/manage/FinalizeCrowdsaleStep.spec.js b/test/components/Manage/FinalizeCrowdsaleStep.spec.js similarity index 53% rename from test/components/manage/FinalizeCrowdsaleStep.spec.js rename to test/components/Manage/FinalizeCrowdsaleStep.spec.js index 6a00111e8..f2e36f53e 100644 --- a/test/components/manage/FinalizeCrowdsaleStep.spec.js +++ b/test/components/Manage/FinalizeCrowdsaleStep.spec.js @@ -1,6 +1,6 @@ import React from 'react' import { StaticRouter } from 'react-router' -import { FinalizeCrowdsaleStep } from '../../../src/components/manage/FinalizeCrowdsaleStep' +import { FinalizeCrowdsaleStep } from '../../../src/components/Manage/FinalizeCrowdsaleStep' import renderer from 'react-test-renderer' import Adapter from 'enzyme-adapter-react-15' import { configure, mount } from 'enzyme' @@ -41,42 +41,4 @@ describe('FinalizeCrowdsaleStep', () => { .toJSON() ).toMatchSnapshot() }) - - it('should call handleClick', () => { - const finalizeCrowdsaleStateParams = { - disabled: false, - handleClick: jest.fn() - } - - const wrapper = mount( - - - - ) - - const button = wrapper.find('Link').at(0) - - button.simulate('click') - - expect(finalizeCrowdsaleStateParams.handleClick).toHaveBeenCalled() - }) - - it('should not call handleClick', () => { - const finalizeCrowdsaleStateParams = { - disabled: true, - handleClick: jest.fn() - } - - const wrapper = mount( - - - - ) - - const button = wrapper.find('Link').at(0) - - button.simulate('click') - - expect(finalizeCrowdsaleStateParams.handleClick).toHaveBeenCalledTimes(0) - }) }) diff --git a/test/components/manage/ManageForm.spec.js b/test/components/Manage/ManageForm.spec.js similarity index 99% rename from test/components/manage/ManageForm.spec.js rename to test/components/Manage/ManageForm.spec.js index 79e3ce4a1..5c94c7c1c 100644 --- a/test/components/manage/ManageForm.spec.js +++ b/test/components/Manage/ManageForm.spec.js @@ -2,7 +2,7 @@ import React from 'react' import { BrowserRouter } from 'react-router-dom' import { Form } from 'react-final-form' import arrayMutators from 'final-form-arrays' -import { ManageForm } from '../../../src/components/manage/ManageForm' +import { ManageForm } from '../../../src/components/Manage/ManageForm' import Adapter from 'enzyme-adapter-react-15' import { configure, mount } from 'enzyme' import MockDate from 'mockdate' diff --git a/test/components/manage/ManageTierBlock.spec.js b/test/components/Manage/ManageTierBlock.spec.js similarity index 59% rename from test/components/manage/ManageTierBlock.spec.js rename to test/components/Manage/ManageTierBlock.spec.js index c93e699fd..f41c73076 100644 --- a/test/components/manage/ManageTierBlock.spec.js +++ b/test/components/Manage/ManageTierBlock.spec.js @@ -5,10 +5,14 @@ import renderer from 'react-test-renderer' import Adapter from 'enzyme-adapter-react-15' import { configure } from 'enzyme' import MockDate from 'mockdate' -import { ManageTierBlock } from '../../../src/components/manage/ManageTierBlock' +import { ManageTierBlock } from '../../../src/components/Manage/ManageTierBlock' import CrowdsaleStore from '../../../src/stores/CrowdsaleStore' import TokenStore from '../../../src/stores/TokenStore' -import { CROWDSALE_STRATEGIES } from '../../../src/utils/constants' +import TierStore from '../../../src/stores/TierStore' +import { Provider } from 'mobx-react' +import { CROWDSALE_STRATEGIES, VALIDATION_TYPES } from '../../../src/utils/constants' + +const { VALID } = VALIDATION_TYPES const DATE = { TIER_0: { @@ -23,7 +27,7 @@ const DATE = { } } -const initialTiers = [ +const tiers = [ { whitelist: [ { addr: '0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b', min: 1234, max: 50505, stored: true }, @@ -58,18 +62,85 @@ const initialTiers = [ endTime: '2018-04-21T00:00', updatable: false, tier: 'Tier 2', + whitelistEnabled: 'yes', supply: '156', rate: '55', minCap: '0' } ] +const initialTiers = [ + { + whitelist: [ + { addr: '0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b', min: 1234, max: 50505, stored: true }, + { addr: '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1', min: 1234, max: 50505, stored: true }, + { addr: '0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d', min: 1234, max: 50505, stored: true }, + { addr: '0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0', min: 1234, max: 50505, stored: true } + ], + startTime: '2018-04-13T16:07', + endTime: '2018-04-17T00:00', + duration: '1528827423500', + updatable: true, + tier: 'Tier 1', + isWhitelisted: 'yes', + supply: '132', + rate: '123', + index: '0', + addresses: { + crowdsaleAddress: '0x42a7b7dd785cd69714a189dffb3fd7d7174edc9ece837694ce50f7078f7c31ae' + }, + minCap: '0' + }, + { + whitelist: [ + { addr: '0x1dF62f291b2E969fB0849d99D9Ce41e2F137006e', min: 1234, max: 50505, stored: true }, + { addr: '0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b', min: 1234, max: 50505, stored: true }, + { addr: '0x3E5e9111Ae8eB78Fe1CC3bb8915d5D461F3Ef9A9', min: 1234, max: 50505, stored: true }, + { addr: '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1', min: 1234, max: 50505, stored: true }, + { addr: '0x95cED938F7991cd0dFcb48F0a06a40FA1aF46EBC', min: 1234, max: 50505, stored: true }, + { addr: '0xACa94ef8bD5ffEE41947b4585a84BdA5a3d3DA6E', min: 1234, max: 50505, stored: true }, + { addr: '0xd03ea8624C8C5987235048901fB614fDcA89b117', min: 1234, max: 50505, stored: true }, + { addr: '0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d', min: 1234, max: 50505, stored: true }, + { addr: '0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0', min: 1234, max: 50505, stored: true } + ], + startTime: '2018-04-17T00:00', + endTime: '2018-04-21T00:00', + duration: '1528827423500', + updatable: false, + tier: 'Tier 2', + isWhitelisted: 'yes', + supply: '156', + rate: '55', + index: '1', + addresses: { + crowdsaleAddress: '0x42a7b7dd785cd69714a189dffb3fd7d7174edc9ece837694ce50f7078f7c31ae' + }, + minCap: '0' + } +] + +const validations = { + tier: VALID, + walletAddress: VALID, + rate: VALID, + supply: VALID, + startTime: VALID, + endTime: VALID, + updatable: VALID +} + configure({ adapter: new Adapter() }) describe('ManageTierBlock', () => { it('should render the ManageTierBlock component with tiers for Minted Capped Crowdsale', () => { const crowdsaleStore = new CrowdsaleStore() const tokenStore = new TokenStore() + const tierStore = new TierStore() + + tierStore.addTier(tiers[0], validations) + tierStore.addTier(tiers[1], validations) + + const stores = { crowdsaleStore, tokenStore, tierStore } crowdsaleStore.setProperty('strategy', CROWDSALE_STRATEGIES.MINTED_CAPPED_CROWDSALE) MockDate.set(DATE.TIER_0.ACTIVE) @@ -87,15 +158,18 @@ describe('ManageTierBlock', () => { canEditTiers: false, aboutTier:
About Tier
, crowdsaleStore: crowdsaleStore, - tokenStore: tokenStore + tokenStore: tokenStore, + tierStore: tierStore } expect( renderer .create( - -
} /> - + + + } /> + + ) .toJSON() ).toMatchSnapshot() diff --git a/test/components/manage/ReservedTokensList.spec.js b/test/components/Manage/ReservedTokensList.spec.js similarity index 76% rename from test/components/manage/ReservedTokensList.spec.js rename to test/components/Manage/ReservedTokensList.spec.js index 4d25169ae..23a64e50d 100644 --- a/test/components/manage/ReservedTokensList.spec.js +++ b/test/components/Manage/ReservedTokensList.spec.js @@ -1,6 +1,6 @@ import React from 'react' import { StaticRouter } from 'react-router' -import { ReservedTokensList } from '../../../src/components/manage/ReservedTokensList' +import { ReservedTokensList } from '../../../src/components/Manage/ReservedTokensList' import Adapter from 'enzyme-adapter-react-15' import { configure, mount } from 'enzyme' import ReservedTokenStore from '../../../src/stores/ReservedTokenStore' @@ -41,25 +41,6 @@ describe('DistributeTokensStep', () => { reservedTokenStore.clearAll() }) - it(`should render reserved token addresses if it's the owner`, () => { - tokenList.forEach(token => reservedTokenStore.addToken(token)) - - const distributeTokensStateParams = { - disabled: false, - handleClick: jest.fn(), - reservedTokenStore, - owner: true - } - - const wrapper = mount( - - - - ) - - expect(wrapper.find('.read-only')).toHaveLength(1) - }) - it(`should not render reserved token addresses if not the owner`, () => { tokenList.forEach(token => reservedTokenStore.addToken(token)) diff --git a/test/components/Manage/__snapshots__/FinalizeCrowdsaleStep.spec.js.snap b/test/components/Manage/__snapshots__/FinalizeCrowdsaleStep.spec.js.snap new file mode 100644 index 000000000..bdf4ff43e --- /dev/null +++ b/test/components/Manage/__snapshots__/FinalizeCrowdsaleStep.spec.js.snap @@ -0,0 +1,41 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`FinalizeCrowdsaleStep should render the component with active button 1`] = ` +
+
+ After finalization, it’s not possible to update tiers or buy tokens. All tokens will be movable and reserved tokens will be issued. +
+ +
+`; + +exports[`FinalizeCrowdsaleStep should render the component with disabled button 1`] = ` +
+
+ After finalization, it’s not possible to update tiers or buy tokens. All tokens will be movable and reserved tokens will be issued. +
+ +
+`; diff --git a/test/components/manage/__snapshots__/ManageForm.spec.js.snap b/test/components/Manage/__snapshots__/ManageForm.spec.js.snap similarity index 77% rename from test/components/manage/__snapshots__/ManageForm.spec.js.snap rename to test/components/Manage/__snapshots__/ManageForm.spec.js.snap index 1d0f3acca..9a559267f 100644 --- a/test/components/manage/__snapshots__/ManageForm.spec.js.snap +++ b/test/components/Manage/__snapshots__/ManageForm.spec.js.snap @@ -2038,745 +2038,121 @@ exports[`ManageForm should render the component with tiers 1`] = ` } > -
- - - + + + ( + ) + + Settings + +
+
+
+ +
+ +
+ +
+
+ + + +
+
+
+
+ +
+ +
+ +
+
+ + + +
+
+
+
+ - <_class + + <_class + __versions={ + Object { + "final-form": "4.6.1", + "react-final-form": "3.4.0", + } + } + batch={[Function]} + blur={[Function]} + canEditTiers={true} + change={[Function]} + crowdsaleStore={ + CrowdsaleStore { + "crowdsales": Array [], + "endTime": undefined, + "maximumSellableTokens": undefined, + "maximumSellableTokensInWei": undefined, + "selected": Object { + "initialTiersValues": Array [], + "updatable": false, + }, + "strategy": "white-list-with-cap", + "supply": undefined, + } + } + decorators={ + Array [ + [MockFunction] { + "calls": Array [ + Array [ + Object { + "batch": [Function], + "blur": [Function], + "change": [Function], + "focus": [Function], + "getFieldState": [Function], + "getRegisteredFields": [Function], + "getState": [Function], + "initialize": [Function], + "isValidationPaused": [Function], + "mutators": Object { + "insert": [Function], + "move": [Function], + "pop": [Function], + "push": [Function], + "remove": [Function], + "shift": [Function], + "swap": [Function], + "unshift": [Function], + }, + "pauseValidation": [Function], + "registerField": [Function], + "reset": [Function], + "resumeValidation": [Function], + "setConfig": [Function], + "submit": [Function], + "subscribe": [Function], + }, + ], + ], + "results": Array [ + Object { + "isThrow": false, + "value": undefined, + }, + ], + }, + ] + } + dirty={false} + dirtySinceLastSubmit={false} + errors={ + Object { + "tiers": Array [ + Object { + "minCap": Array [ + "Decimals should not exceed the amount of decimals specified", + ], + }, + Object { + "minCap": Array [ + "Decimals should not exceed the amount of decimals specified", + ], + }, + ], + } + } + fields={ + Object { + "active": false, + "blur": [Function], + "change": [Function], + "data": Object {}, + "dirty": false, + "dirtySinceLastSubmit": false, + "error": undefined, + "focus": [Function], + "forEach": [Function], + "initial": Array [ + Object { + "addresses": Object { + "crowdsaleAddress": "0x42a7b7dd785cd69714a189dffb3fd7d7174edc9ece837694ce50f7078f7c31ae", + }, + "duration": "1528827423500", + "endTime": "2018-04-17T00:00", + "index": "0", + "isWhitelisted": "yes", + "minCap": "0", + "rate": "123", + "startTime": "2018-04-13T16:07", + "supply": "132", + "tier": "Tier 1", + "updatable": true, + "whitelist": Array [ + Object { + "addr": "0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", + "max": 50505, + "min": 1234, + "stored": true, + }, + ], + }, + Object { + "addresses": Object { + "crowdsaleAddress": "0x42a7b7dd785cd69714a189dffb3fd7d7174edc9ece837694ce50f7078f7c31ae", + }, + "duration": "1528827423500", + "endTime": "2018-04-21T00:00", + "index": "1", + "isWhitelisted": "yes", + "minCap": "0", + "rate": "55", + "startTime": "2018-04-17T00:00", + "supply": "156", + "tier": "Tier 2", + "updatable": false, + "whitelist": Array [ + Object { + "addr": "0x1dF62f291b2E969fB0849d99D9Ce41e2F137006e", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x3E5e9111Ae8eB78Fe1CC3bb8915d5D461F3Ef9A9", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x95cED938F7991cd0dFcb48F0a06a40FA1aF46EBC", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xACa94ef8bD5ffEE41947b4585a84BdA5a3d3DA6E", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xd03ea8624C8C5987235048901fB614fDcA89b117", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", + "max": 50505, + "min": 1234, + "stored": true, + }, + ], + }, + ], + "insert": [Function], + "invalid": false, + "length": 2, + "map": [Function], + "move": [Function], + "name": "tiers", + "pop": [Function], + "pristine": true, + "push": [Function], + "remove": [Function], + "shift": [Function], + "submitError": undefined, + "submitFailed": false, + "submitSucceeded": false, + "swap": [Function], + "touched": false, + "unshift": [Function], + "valid": true, + "value": Array [ + Object { + "addresses": Object { + "crowdsaleAddress": "0x42a7b7dd785cd69714a189dffb3fd7d7174edc9ece837694ce50f7078f7c31ae", + }, + "duration": "1528827423500", + "endTime": "2018-04-17T00:00", + "index": "0", + "isWhitelisted": "yes", + "minCap": "0", + "rate": "123", + "startTime": "2018-04-13T16:07", + "supply": "132", + "tier": "Tier 1", + "updatable": true, + "whitelist": Array [ + Object { + "addr": "0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", + "max": 50505, + "min": 1234, + "stored": true, + }, + ], + }, + Object { + "addresses": Object { + "crowdsaleAddress": "0x42a7b7dd785cd69714a189dffb3fd7d7174edc9ece837694ce50f7078f7c31ae", + }, + "duration": "1528827423500", + "endTime": "2018-04-21T00:00", + "index": "1", + "isWhitelisted": "yes", + "minCap": "0", + "rate": "55", + "startTime": "2018-04-17T00:00", + "supply": "156", + "tier": "Tier 2", + "updatable": false, + "whitelist": Array [ + Object { + "addr": "0x1dF62f291b2E969fB0849d99D9Ce41e2F137006e", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x3E5e9111Ae8eB78Fe1CC3bb8915d5D461F3Ef9A9", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x95cED938F7991cd0dFcb48F0a06a40FA1aF46EBC", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xACa94ef8bD5ffEE41947b4585a84BdA5a3d3DA6E", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xd03ea8624C8C5987235048901fB614fDcA89b117", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", + "max": 50505, + "min": 1234, + "stored": true, + }, + ], + }, + ], + "visited": false, + } + } + focus={[Function]} + form={ + Object { + "batch": [Function], + "blur": [Function], + "change": [Function], + "focus": [Function], + "getFieldState": [Function], + "getRegisteredFields": [Function], + "getState": [Function], + "initialize": [Function], + "isValidationPaused": [Function], + "mutators": Object { + "insert": [Function], + "move": [Function], + "pop": [Function], + "push": [Function], + "remove": [Function], + "shift": [Function], + "swap": [Function], + "unshift": [Function], + }, + "pauseValidation": [Function], + "registerField": [Function], + "reset": [Function], + "resumeValidation": [Function], + "setConfig": [Function], + "submit": [Function], + "subscribe": [Function], + } + } + hasSubmitErrors={false} + hasValidationErrors={true} + initialValues={ + Object { + "tiers": Array [ + Object { + "addresses": Object { + "crowdsaleAddress": "0x42a7b7dd785cd69714a189dffb3fd7d7174edc9ece837694ce50f7078f7c31ae", + }, + "duration": "1528827423500", + "endTime": "2018-04-17T00:00", + "index": "0", + "isWhitelisted": "yes", + "minCap": "0", + "rate": "123", + "startTime": "2018-04-13T16:07", + "supply": "132", + "tier": "Tier 1", + "updatable": true, + "whitelist": Array [ + Object { + "addr": "0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", + "max": 50505, + "min": 1234, + "stored": true, + }, + ], + }, + Object { + "addresses": Object { + "crowdsaleAddress": "0x42a7b7dd785cd69714a189dffb3fd7d7174edc9ece837694ce50f7078f7c31ae", }, - ], + "duration": "1528827423500", + "endTime": "2018-04-21T00:00", + "index": "1", + "isWhitelisted": "yes", + "minCap": "0", + "rate": "55", + "startTime": "2018-04-17T00:00", + "supply": "156", + "tier": "Tier 2", + "updatable": false, + "whitelist": Array [ + Object { + "addr": "0x1dF62f291b2E969fB0849d99D9Ce41e2F137006e", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x3E5e9111Ae8eB78Fe1CC3bb8915d5D461F3Ef9A9", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x95cED938F7991cd0dFcb48F0a06a40FA1aF46EBC", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xACa94ef8bD5ffEE41947b4585a84BdA5a3d3DA6E", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xd03ea8624C8C5987235048901fB614fDcA89b117", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", + "max": 50505, + "min": 1234, + "stored": true, + }, + ], + }, + ], + } + } + initialize={[Function]} + mutators={ + Object { + "insert": [Function], + "move": [Function], + "pop": [Function], + "push": [Function], + "remove": [Function], + "shift": [Function], + "swap": [Function], + "unshift": [Function], + } + } + reset={[Function]} + submitFailed={false} + submitSucceeded={false} + tokenStore={ + TokenStore { + "decimals": undefined, + "name": undefined, + "reservedTokensInput": Object {}, + "supply": 0, + "ticker": undefined, + "validToken": Object { + "decimals": "EMPTY", + "name": "EMPTY", + "ticker": "EMPTY", }, - ], + } } - } - visited={ - Object { - "tiers": false, - "tiers[0].endTime": false, - "tiers[0].minCap": false, - "tiers[0].rate": false, - "tiers[0].startTime": false, - "tiers[0].supply": false, - "tiers[1].endTime": false, - "tiers[1].minCap": false, - "tiers[1].rate": false, - "tiers[1].startTime": false, - "tiers[1].supply": false, + touched={ + Object { + "tiers": false, + "tiers[0].endTime": false, + "tiers[0].minCap": false, + "tiers[0].rate": false, + "tiers[0].startTime": false, + "tiers[0].supply": false, + "tiers[1].endTime": false, + "tiers[1].minCap": false, + "tiers[1].rate": false, + "tiers[1].startTime": false, + "tiers[1].supply": false, + } } - } - > -
+ valid={false} + validating={false} + values={ + Object { + "tiers": Array [ + Object { + "addresses": Object { + "crowdsaleAddress": "0x42a7b7dd785cd69714a189dffb3fd7d7174edc9ece837694ce50f7078f7c31ae", + }, + "duration": "1528827423500", + "endTime": "2018-04-17T00:00", + "index": "0", + "isWhitelisted": "yes", + "minCap": "0", + "rate": "123", + "startTime": "2018-04-13T16:07", + "supply": "132", + "tier": "Tier 1", + "updatable": true, + "whitelist": Array [ + Object { + "addr": "0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", + "max": 50505, + "min": 1234, + "stored": true, + }, + ], + }, + Object { + "addresses": Object { + "crowdsaleAddress": "0x42a7b7dd785cd69714a189dffb3fd7d7174edc9ece837694ce50f7078f7c31ae", + }, + "duration": "1528827423500", + "endTime": "2018-04-21T00:00", + "index": "1", + "isWhitelisted": "yes", + "minCap": "0", + "rate": "55", + "startTime": "2018-04-17T00:00", + "supply": "156", + "tier": "Tier 2", + "updatable": false, + "whitelist": Array [ + Object { + "addr": "0x1dF62f291b2E969fB0849d99D9Ce41e2F137006e", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x3E5e9111Ae8eB78Fe1CC3bb8915d5D461F3Ef9A9", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0x95cED938F7991cd0dFcb48F0a06a40FA1aF46EBC", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xACa94ef8bD5ffEE41947b4585a84BdA5a3d3DA6E", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xd03ea8624C8C5987235048901fB614fDcA89b117", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d", + "max": 50505, + "min": 1234, + "stored": true, + }, + Object { + "addr": "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", + "max": 50505, + "min": 1234, + "stored": true, + }, + ], + }, + ], + } + } + visited={ + Object { + "tiers": false, + "tiers[0].endTime": false, + "tiers[0].minCap": false, + "tiers[0].rate": false, + "tiers[0].startTime": false, + "tiers[0].supply": false, + "tiers[1].endTime": false, + "tiers[1].minCap": false, + "tiers[1].rate": false, + "tiers[1].startTime": false, + "tiers[1].supply": false, + } + } + >
+

+ Tier Name: + Tier 1 +

- -
- -
- -
-
- - - -
-
-
-
@@ -3661,54 +3625,31 @@ exports[`ManageForm should render the component with tiers 1`] = ` +
+
@@ -3813,55 +3756,28 @@ exports[`ManageForm should render the component with tiers 1`] = `
@@ -3967,54 +3885,31 @@ exports[`ManageForm should render the component with tiers 1`] = ` +
+
@@ -4076,7 +3971,6 @@ exports[`ManageForm should render the component with tiers 1`] = `
@@ -4123,39 +4020,21 @@ exports[`ManageForm should render the component with tiers 1`] = `
@@ -4251,110 +4132,42 @@ exports[`ManageForm should render the component with tiers 1`] = `
-
-
+

+ Tier Name: + Tier 2 +

- -
- -
- -
-
- - - -
-
-
-
@@ -4457,53 +4272,30 @@ exports[`ManageForm should render the component with tiers 1`] = ` +
+
@@ -4608,55 +4402,28 @@ exports[`ManageForm should render the component with tiers 1`] = `
@@ -4762,54 +4531,31 @@ exports[`ManageForm should render the component with tiers 1`] = ` +
+
@@ -4871,7 +4617,6 @@ exports[`ManageForm should render the component with tiers 1`] = `
@@ -4918,39 +4666,21 @@ exports[`ManageForm should render the component with tiers 1`] = `
@@ -5047,162 +4779,164 @@ exports[`ManageForm should render the component with tiers 1`] = `
-
- - - - + + + -
+ />
- + +
diff --git a/test/components/Manage/__snapshots__/ManageTierBlock.spec.js.snap b/test/components/Manage/__snapshots__/ManageTierBlock.spec.js.snap new file mode 100644 index 000000000..8d3095b55 --- /dev/null +++ b/test/components/Manage/__snapshots__/ManageTierBlock.spec.js.snap @@ -0,0 +1,839 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ManageTierBlock should render the ManageTierBlock component with tiers for Dutch Auction Crowdsale 1`] = ` +
+
+

+ Tier Name: + Tier 1 +

+
+
+
+
+ +
+ + Date and time when the tier starts. Can't be in the past from the current moment. + +
+
+ +
+
+
+
+
+ +
+ + Date and time when the tier ends. Can be only in the future. + +
+
+ +
+
+
+
+
+ +
+ + Exchange rate Ethereum to Tokens. If it's 100, then for 1 Ether you can buy 100 tokens + +
+
+ +
+
+
+
+
+ +
+ + How many tokens will be sold on this tier. Cap of crowdsale equals to sum of supply of all tiers + +
+
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+

+ Tier Name: + Tier 2 +

+
+
+
+
+ +
+ + Date and time when the tier starts. Can't be in the past from the current moment. + +
+
+ +
+
+
+
+
+ +
+ + Date and time when the tier ends. Can be only in the future. + +
+
+ +
+
+
+
+
+ +
+ + Exchange rate Ethereum to Tokens. If it's 100, then for 1 Ether you can buy 100 tokens + +
+
+ +
+
+
+
+
+ +
+ + How many tokens will be sold on this tier. Cap of crowdsale equals to sum of supply of all tiers + +
+
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+`; + +exports[`ManageTierBlock should render the ManageTierBlock component with tiers for Minted Capped Crowdsale 1`] = ` +
+
+

+ Tier Name: + Tier 1 +

+
+
+
+
+ +
+ + Date and time when the tier starts. Can't be in the past from the current moment. + +
+
+ +
+
+
+
+
+ +
+ + Date and time when the tier ends. Can be only in the future. + +
+
+ +
+
+
+
+
+ +
+ + Exchange rate Ethereum to Tokens. If it's 100, then for 1 Ether you can buy 100 tokens + +
+
+ +
+
+
+
+
+ +
+ + How many tokens will be sold on this tier. Cap of crowdsale equals to sum of supply of all tiers + +
+
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+

+ Tier Name: + Tier 2 +

+
+
+
+
+ +
+ + Date and time when the tier starts. Can't be in the past from the current moment. + +
+
+ +
+
+
+
+
+ +
+ + Date and time when the tier ends. Can be only in the future. + +
+
+ +
+
+
+
+
+ +
+ + Exchange rate Ethereum to Tokens. If it's 100, then for 1 Ether you can buy 100 tokens + +
+
+ +
+
+
+
+
+ +
+ + How many tokens will be sold on this tier. Cap of crowdsale equals to sum of supply of all tiers + +
+
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+`; diff --git a/test/components/Manage/__snapshots__/index.spec.js.snap b/test/components/Manage/__snapshots__/index.spec.js.snap new file mode 100644 index 000000000..da7f98f3f --- /dev/null +++ b/test/components/Manage/__snapshots__/index.spec.js.snap @@ -0,0 +1,145 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Manage index should render Manage 1`] = ` +
+
+
+ +
+
+
+
+ + Crowdsale List + +
+
+
+ + Manage Crowdsale + +
+
+
+
+
+
+
+

+ Manage Crowdsale +

+

+

+
+

+ + Crowdsale Page + +

+
+
+ After finalization, it’s not possible to update tiers or buy tokens. All tokens will be movable and reserved tokens will be issued. +
+ +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+`; diff --git a/test/components/Manage/index.spec.js b/test/components/Manage/index.spec.js new file mode 100644 index 000000000..5574c6c5d --- /dev/null +++ b/test/components/Manage/index.spec.js @@ -0,0 +1,57 @@ +import React from 'react' +import Adapter from 'enzyme-adapter-react-15' +import { Provider } from 'mobx-react' +import { configure } from 'enzyme' +import renderer from 'react-test-renderer' +import { MemoryRouter } from 'react-router' +import { Manage } from '../../../src/components/Manage/index' +import { + crowdsaleStore, + web3Store, + tierStore, + contractStore, + reservedTokenStore, + stepTwoValidationStore, + generalStore, + tokenStore, + gasPriceStore, + deploymentStore +} from '../../../src/stores' + +configure({ adapter: new Adapter() }) + +describe('Manage index', () => { + const stores = { + crowdsaleStore, + web3Store, + tierStore, + contractStore, + reservedTokenStore, + stepTwoValidationStore, + generalStore, + tokenStore, + gasPriceStore, + deploymentStore + } + + it(`should render Manage`, () => { + // Given + const data = { + params: { crowdsalePointer: 'test' } + } + + const component = renderer.create( + + + + + + ) + + // When + const tree = component.toJSON() + + // Then + expect(tree).toMatchSnapshot() + }) +}) diff --git a/test/components/manage/utils.spec.js b/test/components/Manage/utils.spec.js similarity index 97% rename from test/components/manage/utils.spec.js rename to test/components/Manage/utils.spec.js index d9e4b7bee..1b7d7083d 100644 --- a/test/components/manage/utils.spec.js +++ b/test/components/Manage/utils.spec.js @@ -1,4 +1,4 @@ -import { getFieldsToUpdate } from '../../../src/components/manage/utils' +import { getFieldsToUpdate } from '../../../src/components/Manage/utils' describe('getFieldsToUpdate', () => { it('should include only fields that have changed', () => { diff --git a/test/components/Stats/__snapshots__/index.spec.js.snap b/test/components/Stats/__snapshots__/index.spec.js.snap new file mode 100644 index 000000000..1a6bd7c63 --- /dev/null +++ b/test/components/Stats/__snapshots__/index.spec.js.snap @@ -0,0 +1,481 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Stats index should render Stats 1`] = ` +
+
+
+ +
+
+
+ + Statistics + +
+
+
+
+
+
+
+

+ Statistics +

+

+

+
+
+
+
+
+

+ 0 +

+

+ Total crowdsales amount +

+
+
+
+
+
+
+

+ 0 +

+

+ Total amount of eth raised +

+
+
+
+
+
+
+

+ 0 +

+

+ Total contributors amount +

+
+
+
+
+
+
+

+ 0 +

+

+ Max amount of eth raised in one crowdsale +

+
+
+
+
+

+ Minted capped crowdsales statistics +

+
+
+
+
+

+ 0 +

+

+ Crowdsales amount +

+
+
+

+ 0 +

+

+ Total amount of eth raised +

+
+
+

+ 0 +

+

+ Total contributors amount +

+
+
+
+
+
+
+

+ 0 +

+

+ Ongoing crowdsales amount +

+
+
+

+ 0 +

+

+ Future crowdsales amount +

+
+
+

+ 0 +

+

+ Past crowdsales amount +

+
+
+
+
+
+
+

+ 0 +

+

+ Max amount of eth raised in one crowdsale +

+
+
+

+ 0 +

+

+ % of finalized crowdsales from ended +

+
+
+

+ 0 +

+

+ % of crowdsales with multiple tiers +

+
+
+
+
+
+
+

+ 0 +

+

+ Max tiers amount in one crowdsale +

+
+
+
+
+

+ Dutch auction crowdsales statistics +

+
+
+
+
+

+ 0 +

+

+ Crowdsales amount +

+
+
+

+ 0 +

+

+ Total amount of eth raised +

+
+
+

+ 0 +

+

+ Total contributors amount +

+
+
+
+
+
+
+

+ 0 +

+

+ Ongoing crowdsales amount +

+
+
+

+ 0 +

+

+ Future crowdsales amount +

+
+
+

+ 0 +

+

+ Past crowdsales amount +

+
+
+
+
+
+
+

+ 0 +

+

+ Max amount of eth raised in one crowdsale +

+
+
+

+ 0 +

+

+ % of finalized crowdsales from ended +

+
+
+
+
+
+
+
+`; diff --git a/test/components/Stats/index.spec.js b/test/components/Stats/index.spec.js new file mode 100644 index 000000000..c496d05fa --- /dev/null +++ b/test/components/Stats/index.spec.js @@ -0,0 +1,34 @@ +import React from 'react' +import Adapter from 'enzyme-adapter-react-15' +import { Provider } from 'mobx-react' +import { configure } from 'enzyme' +import renderer from 'react-test-renderer' +import { MemoryRouter } from 'react-router' +import { Stats } from '../../../src/components/Stats/index' +import { web3Store, statsStore } from '../../../src/stores' + +configure({ adapter: new Adapter() }) + +describe('Stats index', () => { + const stores = { + web3Store, + statsStore + } + + it(`should render Stats`, () => { + // Given + const component = renderer.create( + + + + + + ) + + // When + const tree = component.toJSON() + + // Then + expect(tree).toMatchSnapshot() + }) +}) diff --git a/test/components/StepFour/BorderedSection.spec.js b/test/components/StepFour/BorderedSection.spec.js new file mode 100644 index 000000000..787beb83b --- /dev/null +++ b/test/components/StepFour/BorderedSection.spec.js @@ -0,0 +1,18 @@ +import React from 'react' +import Adapter from 'enzyme-adapter-react-15' +import { configure, mount, shallow } from 'enzyme' +import { BorderedSection } from '../../../src/components/StepFour/BorderedSection' +import renderer from 'react-test-renderer' +import { NAVIGATION_STEPS } from '../../../src/utils/constants' + +configure({ adapter: new Adapter() }) + +describe('BorderedSection', () => { + it(`should render the component `, () => { + const { CROWDSALE_STRATEGY } = NAVIGATION_STEPS + + const wrapper = shallow() + + expect(wrapper).toMatchSnapshot() + }) +}) diff --git a/test/components/StepFour/ConfigurationBlock.spec.js b/test/components/StepFour/ConfigurationBlock.spec.js new file mode 100644 index 000000000..a394cfee6 --- /dev/null +++ b/test/components/StepFour/ConfigurationBlock.spec.js @@ -0,0 +1,21 @@ +import React from 'react' +import Adapter from 'enzyme-adapter-react-15' +import { configure, mount, shallow } from 'enzyme' +import { ConfigurationBlock } from '../../../src/components/StepFour/ConfigurationBlock' +import { crowdsaleStore } from '../../../src/stores' +import { CROWDSALE_STRATEGIES } from '../../../src/utils/constants' + +configure({ adapter: new Adapter() }) + +describe('Configuration block', () => { + it(`should render the component `, () => { + crowdsaleStore.strategy = CROWDSALE_STRATEGIES.MINTED_CAPPED_CROWDSALE + + const stores = { + store: { crowdsaleStore: crowdsaleStore } + } + const wrapper = shallow() + + expect(wrapper).toMatchSnapshot() + }) +}) diff --git a/test/components/StepFour/CrowdsaleSetupBlockDutchAuction.spec.js b/test/components/StepFour/CrowdsaleSetupBlockDutchAuction.spec.js new file mode 100644 index 000000000..04ec4f4a1 --- /dev/null +++ b/test/components/StepFour/CrowdsaleSetupBlockDutchAuction.spec.js @@ -0,0 +1,35 @@ +import React from 'react' +import Adapter from 'enzyme-adapter-react-15' +import { configure, shallow } from 'enzyme' +import { CrowdsaleSetupBlockDutchAuction } from '../../../src/components/StepFour/CrowdsaleSetupBlockDutchAuction' +import { tierStore } from '../../../src/stores' +import { defaultTier, defaultTierValidations } from '../../../src/utils/constants' + +configure({ adapter: new Adapter() }) + +describe('CrowdsalSetupBlockDutchAuction', () => { + it(`should render the component `, () => { + const addCrowdsale = num => { + const newTier = Object.assign({}, defaultTier) + const newTierValidations = Object.assign({}, defaultTierValidations) + newTier.tier = `Tier ${num + 1}` + if (0 === num) { + newTier.whitelistEnabled = 'no' + newTier.burnExcess = 'no' + newTier.walletAddress = '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1' + newTier.endTime = 1234 + } + + tierStore.addTier(newTier, newTierValidations) + } + + addCrowdsale(0) + + const stores = { + tierStore: tierStore + } + const wrapper = shallow() + + expect(wrapper).toMatchSnapshot() + }) +}) diff --git a/test/components/StepFour/CrowdsaleSetupBlockWhitelistWithCap.spec.js b/test/components/StepFour/CrowdsaleSetupBlockWhitelistWithCap.spec.js new file mode 100644 index 000000000..c0ba045fd --- /dev/null +++ b/test/components/StepFour/CrowdsaleSetupBlockWhitelistWithCap.spec.js @@ -0,0 +1,35 @@ +import React from 'react' +import Adapter from 'enzyme-adapter-react-15' +import { configure, shallow } from 'enzyme' +import { CrowdsaleSetupBlockWhitelistWithCap } from '../../../src/components/StepFour/CrowdsaleSetupBlockWhitelistWithCap' +import { tierStore } from '../../../src/stores' +import { defaultTier, defaultTierValidations } from '../../../src/utils/constants' + +configure({ adapter: new Adapter() }) + +describe('CrowdsaleSetupBlockWhitelistWithCap', () => { + it(`should render the component `, () => { + const addCrowdsale = num => { + const newTier = Object.assign({}, defaultTier) + const newTierValidations = Object.assign({}, defaultTierValidations) + newTier.tier = `Tier ${num + 1}` + if (0 === num) { + newTier.whitelistEnabled = 'no' + newTier.burnExcess = 'no' + newTier.walletAddress = '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1' + newTier.endTime = 1234 + } + + tierStore.addTier(newTier, newTierValidations) + } + + addCrowdsale(0) + + const stores = { + tierStore: tierStore + } + const wrapper = shallow() + + expect(wrapper).toMatchSnapshot() + }) +}) diff --git a/test/components/StepFour/TierSetupDutchAuction.spec.js b/test/components/StepFour/TierSetupDutchAuction.spec.js new file mode 100644 index 000000000..5b4400e10 --- /dev/null +++ b/test/components/StepFour/TierSetupDutchAuction.spec.js @@ -0,0 +1,35 @@ +import React from 'react' +import Adapter from 'enzyme-adapter-react-15' +import { configure, shallow } from 'enzyme' +import { TierSetupDutchAuction } from '../../../src/components/StepFour/TierSetupDutchAuction' +import { tierStore } from '../../../src/stores' +import { defaultTier, defaultTierValidations } from '../../../src/utils/constants' + +configure({ adapter: new Adapter() }) + +describe('TierSetupDutchAuction', () => { + it(`should render the component `, () => { + const addCrowdsale = num => { + const newTier = Object.assign({}, defaultTier) + const newTierValidations = Object.assign({}, defaultTierValidations) + newTier.tier = `Tier ${num + 1}` + if (0 === num) { + newTier.whitelistEnabled = 'no' + newTier.burnExcess = 'no' + newTier.walletAddress = '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1' + newTier.endTime = 1234 + } + + tierStore.addTier(newTier, newTierValidations) + } + + addCrowdsale(0) + + const stores = { + tier: tierStore.tiers[0] + } + const wrapper = shallow() + + expect(wrapper).toMatchSnapshot() + }) +}) diff --git a/test/components/StepFour/TierSetupWhitelistWithCap.spec.js b/test/components/StepFour/TierSetupWhitelistWithCap.spec.js new file mode 100644 index 000000000..1a444d487 --- /dev/null +++ b/test/components/StepFour/TierSetupWhitelistWithCap.spec.js @@ -0,0 +1,35 @@ +import React from 'react' +import Adapter from 'enzyme-adapter-react-15' +import { configure, shallow } from 'enzyme' +import { TierSetupWhitelistWithCap } from '../../../src/components/StepFour/TierSetupWhitelistWithCap' +import { tierStore } from '../../../src/stores' +import { defaultTier, defaultTierValidations } from '../../../src/utils/constants' + +configure({ adapter: new Adapter() }) + +describe('TierSetupWhitelistWithCap', () => { + it(`should render the component `, () => { + const addCrowdsale = num => { + const newTier = Object.assign({}, defaultTier) + const newTierValidations = Object.assign({}, defaultTierValidations) + newTier.tier = `Tier ${num + 1}` + if (0 === num) { + newTier.whitelistEnabled = 'no' + newTier.burnExcess = 'no' + newTier.walletAddress = '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1' + newTier.endTime = 1234 + } + + tierStore.addTier(newTier, newTierValidations) + } + + addCrowdsale(0) + + const stores = { + tier: tierStore.tiers[0] + } + const wrapper = shallow() + + expect(wrapper).toMatchSnapshot() + }) +}) diff --git a/test/components/StepFour/TokenSetupBlock.spec.js b/test/components/StepFour/TokenSetupBlock.spec.js new file mode 100644 index 000000000..596d80c8a --- /dev/null +++ b/test/components/StepFour/TokenSetupBlock.spec.js @@ -0,0 +1,22 @@ +import React from 'react' +import Adapter from 'enzyme-adapter-react-15' +import { configure, shallow } from 'enzyme' +import { TokenSetupBlock } from '../../../src/components/StepFour/TokenSetupBlock' + +configure({ adapter: new Adapter() }) + +describe('TokenSetupBlock', () => { + it(`should render the component `, () => { + const data = { + tokenStore: { + name: 'This is a valid name', + ticker: 'TTK', + decimals: '14', + supply: '0' + } + } + const wrapper = shallow() + + expect(wrapper).toMatchSnapshot() + }) +}) diff --git a/test/components/StepFour/__snapshots__/BorderedSection.spec.js.snap b/test/components/StepFour/__snapshots__/BorderedSection.spec.js.snap new file mode 100644 index 000000000..b41af0972 --- /dev/null +++ b/test/components/StepFour/__snapshots__/BorderedSection.spec.js.snap @@ -0,0 +1,19 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`BorderedSection should render the component 1`] = ` +
+

+ Crowdsale Strategy +

+

+ Minted Capped +

+
+`; diff --git a/test/components/StepFour/__snapshots__/ConfigurationBlock.spec.js.snap b/test/components/StepFour/__snapshots__/ConfigurationBlock.spec.js.snap new file mode 100644 index 000000000..1f9f47c4b --- /dev/null +++ b/test/components/StepFour/__snapshots__/ConfigurationBlock.spec.js.snap @@ -0,0 +1,23 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Configuration block should render the component 1`] = ` +
+ + + +
+`; diff --git a/test/components/StepFour/__snapshots__/CrowdsaleSetupBlockDutchAuction.spec.js.snap b/test/components/StepFour/__snapshots__/CrowdsaleSetupBlockDutchAuction.spec.js.snap new file mode 100644 index 000000000..ae0f01a24 --- /dev/null +++ b/test/components/StepFour/__snapshots__/CrowdsaleSetupBlockDutchAuction.spec.js.snap @@ -0,0 +1,34 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CrowdsalSetupBlockDutchAuction should render the component 1`] = ` +
+ + + + +
+`; diff --git a/test/components/StepFour/__snapshots__/CrowdsaleSetupBlockWhitelistWithCap.spec.js.snap b/test/components/StepFour/__snapshots__/CrowdsaleSetupBlockWhitelistWithCap.spec.js.snap new file mode 100644 index 000000000..6e100cc15 --- /dev/null +++ b/test/components/StepFour/__snapshots__/CrowdsaleSetupBlockWhitelistWithCap.spec.js.snap @@ -0,0 +1,28 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CrowdsaleSetupBlockWhitelistWithCap should render the component 1`] = ` +
+ + + +
+`; diff --git a/test/components/StepFour/__snapshots__/TierSetupDutchAuction.spec.js.snap b/test/components/StepFour/__snapshots__/TierSetupDutchAuction.spec.js.snap new file mode 100644 index 000000000..b9367281b --- /dev/null +++ b/test/components/StepFour/__snapshots__/TierSetupDutchAuction.spec.js.snap @@ -0,0 +1,45 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`TierSetupDutchAuction should render the component 1`] = ` +
+ + + + + + + +
+`; diff --git a/test/components/StepFour/__snapshots__/TierSetupWhitelistWithCap.spec.js.snap b/test/components/StepFour/__snapshots__/TierSetupWhitelistWithCap.spec.js.snap new file mode 100644 index 000000000..1db5a957a --- /dev/null +++ b/test/components/StepFour/__snapshots__/TierSetupWhitelistWithCap.spec.js.snap @@ -0,0 +1,45 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`TierSetupWhitelistWithCap should render the component 1`] = ` +
+ + + + + + + +
+`; diff --git a/test/components/StepFour/__snapshots__/TokenSetupBlock.spec.js.snap b/test/components/StepFour/__snapshots__/TokenSetupBlock.spec.js.snap new file mode 100644 index 000000000..56de2a522 --- /dev/null +++ b/test/components/StepFour/__snapshots__/TokenSetupBlock.spec.js.snap @@ -0,0 +1,29 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`TokenSetupBlock should render the component 1`] = ` +
+ + + + +
+`; diff --git a/test/components/StepFour/utils.spec.js b/test/components/StepFour/utils.spec.js new file mode 100644 index 000000000..73ae155c5 --- /dev/null +++ b/test/components/StepFour/utils.spec.js @@ -0,0 +1,84 @@ +import React from 'react' +import Adapter from 'enzyme-adapter-react-15' +import { configure, shallow } from 'enzyme' +import { + getVersionFlagByStore, + getOptimizationFlagByStore, + getPragmaVersion +} from '../../../src/components/StepFour/utils' +import { crowdsaleStore } from '../../../src/stores' +import { CROWDSALE_STRATEGIES } from '../../../src/utils/constants' + +configure({ adapter: new Adapter() }) + +describe('StepFourUtils', () => { + it(`should getVersionFlagByStore by Minted Capped `, () => { + crowdsaleStore.strategy = CROWDSALE_STRATEGIES.MINTED_CAPPED_CROWDSALE + + const result = getVersionFlagByStore(crowdsaleStore) + + expect(result).toBe('0.4.24') + }) + + it(`should getVersionFlagByStore by Dutch `, () => { + crowdsaleStore.strategy = CROWDSALE_STRATEGIES.DUTCH_AUCTION + + const result = getVersionFlagByStore(crowdsaleStore) + + expect(result).toBe('0.4.24') + }) + + it(`should getVersionFlagByStore throw an error `, () => { + crowdsaleStore.strategy = 'Throw Error!' + + const result = () => getVersionFlagByStore(crowdsaleStore) + + expect(result).toThrow() + }) + + it(`should getOptimizationFlagByStore by Minted Capped `, () => { + crowdsaleStore.strategy = CROWDSALE_STRATEGIES.MINTED_CAPPED_CROWDSALE + + const result = getOptimizationFlagByStore(crowdsaleStore) + + expect(result).toBe('Yes') + }) + + it(`should getOptimizationFlagByStore by Dutch `, () => { + crowdsaleStore.strategy = CROWDSALE_STRATEGIES.DUTCH_AUCTION + + const result = getOptimizationFlagByStore(crowdsaleStore) + + expect(result).toBe('Yes') + }) + + it(`should getOptimizationFlagByStore throw an error `, () => { + crowdsaleStore.strategy = 'Throw Error!' + + const result = () => getOptimizationFlagByStore(crowdsaleStore) + + expect(result).toThrow() + }) + + it(`should getPragmaVersionby by Minted Capped`, async () => { + const result = await getPragmaVersion('MintedCapped') + + expect(result).toBe('0.4.24') + }) + + it(`should getPragmaVersionby by Dutch`, async () => { + const result = await getPragmaVersion('Dutch') + + expect(result).toBe('0.4.24') + }) + + it(`should getPragmaVersionby throw an error `, async () => { + let error + try { + await getPragmaVersion('Throw Error!') + } catch (e) { + error = e + } + expect(error).toEqual(new Error('Strategy not exist')) + }) +}) diff --git a/test/components/StepOne/__snapshots__/StrategyItem.spec.js.snap b/test/components/StepOne/__snapshots__/StrategyItem.spec.js.snap index 71da650e0..4f34f7ff7 100644 --- a/test/components/StepOne/__snapshots__/StrategyItem.spec.js.snap +++ b/test/components/StepOne/__snapshots__/StrategyItem.spec.js.snap @@ -1,36 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`StrategyItem should render screen with mount without throwing an error 1`] = ` - -`; +exports[`StrategyItem should render screen with mount without throwing an error 1`] = `null`; -exports[`StrategyItem should render screen with render without throwing an error 1`] = ` - -`; +exports[`StrategyItem should render screen with render without throwing an error 1`] = `null`; -exports[`StrategyItem should render screen with shallow without throwing an error 1`] = ` - -`; +exports[`StrategyItem should render screen with shallow without throwing an error 1`] = `null`; diff --git a/test/components/StepOne/__snapshots__/index.spec.js.snap b/test/components/StepOne/__snapshots__/index.spec.js.snap index e1cb6aa45..07e7def80 100644 --- a/test/components/StepOne/__snapshots__/index.spec.js.snap +++ b/test/components/StepOne/__snapshots__/index.spec.js.snap @@ -125,11 +125,11 @@ exports[`StepOne should render StepOne screen 1`] = ` className="sw-RadioItems" > diff --git a/test/components/StepOne/index.spec.js b/test/components/StepOne/index.spec.js index 15e1fea1c..1af944a68 100644 --- a/test/components/StepOne/index.spec.js +++ b/test/components/StepOne/index.spec.js @@ -1,6 +1,6 @@ import React from 'react' import Adapter from 'enzyme-adapter-react-15' -import { configure, mount } from 'enzyme' +import { configure, mount, shallow } from 'enzyme' import renderer from 'react-test-renderer' import { MemoryRouter } from 'react-router' import { StepOne } from '../../../src/components/StepOne/index' @@ -17,6 +17,7 @@ import { tokenStore } from '../../../src/stores' import { CROWDSALE_STRATEGIES } from '../../../src/utils/constants' +import GasPriceInput from '../../../src/components/StepThree/GasPriceInput' configure({ adapter: new Adapter() }) @@ -106,4 +107,54 @@ describe('StepOne', () => { // Then expect(stepOneComponent.instance().state.strategy).toBe(MINTED_CAPPED_CROWDSALE) }) + + it(`should render StepOne screen and test load method`, async () => { + // Given + const wrapper = shallow() + // When + const result = await wrapper + .dive() + .instance() + .load() + // Then + expect(result).toEqual({ strategy: 'white-list-with-cap' }) + }) + + it(`should render StepOne screen and test load method with clearStorage`, async () => { + // Given + global.localStorage.clearStorage = true + const wrapper = shallow() + // When + const result = await wrapper + .dive() + .instance() + .load() + // Then + setTimeout(() => { + expect(result).toEqual({ strategy: 'white-list-with-cap' }) + }, 2000) + }) + + it(`should render StepOne screen and test reload`, async () => { + // Given + global.localStorage.reload = true + global.location = jest.fn() + global.location.assign = jest.fn() + const wrapper = mount() + + // When + setTimeout(() => { + // Then + expect(global.localStorage.reload).toBe(undefined) + expect(global.localStorage.clearStorage).toBeTruthy() + }, 2000) + }) + + it(`should render StepOne screen and test beforeUnloadSpy`, async () => { + const wrapper = mount() + window.location.reload() + setTimeout(() => { + expect(global.localStorage.reload).toBe(undefined) + }, 2000) + }) }) diff --git a/test/components/StepThree/StepThreeFormDutchAuction.spec.js b/test/components/StepThree/StepThreeFormDutchAuction.spec.js index 70382c03f..01dbae6ea 100644 --- a/test/components/StepThree/StepThreeFormDutchAuction.spec.js +++ b/test/components/StepThree/StepThreeFormDutchAuction.spec.js @@ -7,7 +7,7 @@ import Adapter from 'enzyme-adapter-react-15' import { configure, mount } from 'enzyme' import setFieldTouched from 'final-form-set-field-touched' import arrayMutators from 'final-form-arrays' -import { GAS_PRICE } from '../../../src/utils/constants' +import { CONTRIBUTION_OPTIONS, GAS_PRICE } from '../../../src/utils/constants' import { crowdsaleStore, gasPriceStore, @@ -15,9 +15,10 @@ import { reservedTokenStore, tierStore, tokenStore -} from '../../../src/stores/index' +} from '../../../src/stores' import MockDate from 'mockdate' import { weiToGwei } from '../../../src/utils/utils' +import { ReservedTokensInputBlock } from '../../../src/components/Common/ReservedTokensInputBlock' configure({ adapter: new Adapter() }) jest.mock('react-dropzone', () => () => Dropzone) @@ -39,34 +40,212 @@ describe('StepThreeFormDutchAuction', () => { generalStore.reset() }) - it(`should render StepThreeFormDutchAuction`, () => { - // Given - const component = renderer.create( + it(`should render StepThreeFormDutchAuction- test snapshots`, () => { + const component = renderer + .create( + +
+ + ) + .toJSON() + + expect(component).toMatchSnapshot() + }) + + it(`should render StepThreeFormDutchAuction- test snapshot form`, () => { + const props = { + onSubmit: jest.fn(), + decorators: jest.fn(), + values: { + burnExcess: false, + gasPrice: GAS_PRICE.SLOW, + tiers: tierStore.tiers.slice(), + walletAddress: walletAddress, + whitelistEnabled: 'no' + }, + generalStore: generalStore, + crowdsaleStore: crowdsaleStore, + gasPriceStore: gasPriceStore, + reservedTokenStore: reservedTokenStore, + tierStore: tierStore, + tokenStore: tokenStore, + form: { mutators: {} } + } + const FormComponent = mount( + + + + ) + + expect(FormComponent).toMatchSnapshot() + }) + + it(`should render StepThreeFormDutchAuction- test props I`, () => { + const props = { + onSubmit: jest.fn(), + decorators: jest.fn(), + values: { + burnExcess: false, + gasPrice: GAS_PRICE.SLOW, + tiers: tierStore.tiers.slice(), + walletAddress: walletAddress, + whitelistEnabled: 'no' + }, + generalStore: generalStore, + crowdsaleStore: crowdsaleStore, + gasPriceStore: gasPriceStore, + reservedTokenStore: reservedTokenStore, + tierStore: tierStore, + tokenStore: tokenStore, + form: { mutators: {} } + } + const FormComponent = mount( + + + + ) + + const componentInstance = FormComponent.instance() + + FormComponent.find('input[name="burnExcessRadioButtons"]') + .at(0) + .simulate('click') + + expect( + FormComponent.find('input[name="burnExcessRadioButtons"]') + .find(`[value="yes"]`) + .props('checked') + ).toBeTruthy() + }) + + it(`should render StepThreeFormDutchAuction- test props II`, () => { + const props = { + onSubmit: jest.fn(), + decorators: jest.fn(), + values: { + burnExcess: false, + gasPrice: GAS_PRICE.SLOW, + tiers: tierStore.tiers.slice(), + walletAddress: walletAddress, + whitelistEnabled: 'no' + }, + generalStore: generalStore, + crowdsaleStore: crowdsaleStore, + gasPriceStore: gasPriceStore, + reservedTokenStore: reservedTokenStore, + tierStore: tierStore, + tokenStore: tokenStore, + form: { mutators: {} } + } + const FormComponent = mount( + + + + ) + + const componentInstance = FormComponent.instance() + + FormComponent.find('input[name="burnExcessRadioButtons"]') + .at(1) + .simulate('click') + + expect( + FormComponent.find('input[name="burnExcessRadioButtons"]') + .find(`[value="no"]`) + .props('checked') + ).toBeTruthy() + }) + + it(`should render StepThreeFormDutchAuction- test props III`, () => { + const props = { + onSubmit: jest.fn(), + decorators: jest.fn(), + values: { + burnExcess: false, + gasPrice: GAS_PRICE.SLOW, + tiers: tierStore.tiers.slice(), + walletAddress: walletAddress, + whitelistEnabled: 'no' + }, + generalStore: generalStore, + crowdsaleStore: crowdsaleStore, + gasPriceStore: gasPriceStore, + reservedTokenStore: reservedTokenStore, + tierStore: tierStore, + tokenStore: tokenStore, + form: { mutators: {} } + } + const FormComponent = mount( + + + + ) + + const componentInstance = FormComponent.instance() + + FormComponent.find('input[name="burnExcessRadioButtons"]') + .at(1) + .simulate('change', { target: { value: 'yes' } }) + + expect( + FormComponent.find('input[name="burnExcessRadioButtons"]') + .find(`[value="yes"]`) + .props('checked') + ).toBeTruthy() + }) + + it(`should render StepThreeFormDutchAuction- test submit`, () => { + const onSubmit = jest.fn() + + const props = { + handleSubmit: onSubmit, + decorators: jest.fn(), + values: { + burnExcess: false, + gasPrice: GAS_PRICE.SLOW, + tiers: tierStore.tiers.slice(), + walletAddress: walletAddress, + whitelistEnabled: 'no' + }, + generalStore: generalStore, + crowdsaleStore: crowdsaleStore, + gasPriceStore: gasPriceStore, + reservedTokenStore: reservedTokenStore, + tierStore: tierStore, + tokenStore: tokenStore, + form: { mutators: {} } + } + const FormComponent = mount( - + ) - // When - const tree = component.toJSON() + const form = FormComponent.find('form').at(0) + const children = form + .render() + .children() + .children() + form.simulate('submit', { target: { children } }) - // Then - expect(tree).toMatchSnapshot() + expect(onSubmit).toHaveBeenCalledTimes(1) }) }) diff --git a/test/components/StepThree/__snapshots__/GasPriceInput.spec.js.snap b/test/components/StepThree/__snapshots__/GasPriceInput.spec.js.snap index f74dda8f4..91bb2ac8e 100644 --- a/test/components/StepThree/__snapshots__/GasPriceInput.spec.js.snap +++ b/test/components/StepThree/__snapshots__/GasPriceInput.spec.js.snap @@ -422,6 +422,7 @@ exports[`GasPriceInput should render GasPriceInput component with custom gasType value={0.1} > + + + + + + + + + + + +

+ Global settings +

+
+ + +
+ +
+ +
+ + Where the money goes after contributors transactions. Immediately after each transaction. We + recommend to setup a multisig wallet with hardware based signers. + +
+
+
+ + + + + + +
+
+
+ + + +
+ +
+ +
+ + Slow is cheap, fast is expensive. + +
+
+
+
+ +
+ + + + +
+
+ + + +
+
+
+
+ + +
+ +
+ +
+ + Whether the unsold tokens will be burnt on finalization, or be sent to the team wallet + +
+
+
+
+ + +
+
+
+
+ + +
+ + +
+
+ + + + + + +
+ + + + +`; + +exports[`StepThreeFormDutchAuction should render StepThreeFormDutchAuction- test snapshots 1`] = `
{ tokenStore, crowdsaleStore } + const history = { + push: jest.fn() + } describe('StepThree - renders', () => { strategies.forEach(strategy => { @@ -65,35 +69,94 @@ describe('StepThree', () => { }) }) + it(`should execute goBack`, () => { + const wrapper = mount( + + + + + + ) + // Then + const stepThreeComponent = wrapper.find('StepThree') + const stepThreeComponentInstance = stepThreeComponent.instance() + stepThreeComponentInstance.goBack() + + // When + expect(stepThreeComponentInstance.state.backButtonTriggered).toBeTruthy() + }) + + it(`should execute goNextStep`, () => { + const wrapper = mount( + + + + + + ) + // Then + const stepThreeComponent = wrapper.find('StepThree') + const stepThreeComponentInstance = stepThreeComponent.instance() + stepThreeComponentInstance.goNextStep() + + // When + expect(stepThreeComponentInstance.state.nextButtonTriggered).toBeTruthy() + }) + + it(`should execute goBackEnabled`, () => { + const wrapper = mount( + + + + + + ) + // Then + const stepThreeComponent = wrapper.find('StepThree') + const stepThreeComponentInstance = stepThreeComponent.instance() + stepThreeComponentInstance.goBackEnabled() + + // When + expect(stepThreeComponentInstance.state.goBackEnabledTriggered).toBeTruthy() + }) // This tests is expected to trigger 'handleOnSubmit' method... but up to this point it wasn't working - // describe('StepThree - methods', () => { - // it(`should call onSubmit handler if form is valid`, () => { - // // Given - // const walletAddress = '0xAC7022d55dA6C8BB229b1Ba3Ce8A16724FF79c4A' - // const [{ type: strategy }] = strategies - // stores.crowdsaleStore.setProperty('strategy', strategy) - // stores.tierStore.addCrowdsale(walletAddress) - // stores.tokenStore.setProperty('decimals', 18) - // - // const wrapper = mount( - // - // - // - // - // - // ) - // const handleOnSubmit = jest.spyOn(wrapper.find('StepThree').instance(), 'handleOnSubmit') - // // wrapper.update() - // - // // When - // wrapper.find('input[name="walletAddress"]').simulate('change', { target: { value: walletAddress } }) - // wrapper.find('input[name="tiers[0].endTime"]').simulate('change', { target: { value: '2018-03-14T12:00:00' } }) - // wrapper.find('input[name="tiers[0].rate"]').simulate('change', { target: { value: '100000' } }) - // wrapper.find('input[name="tiers[0].supply"]').simulate('change', { target: { value: '100' } }) - // wrapper.find('ButtonContinue').simulate('submit') - // - // // Then - // expect(handleOnSubmit).toHaveBeenCalledTimes(1) - // }) - // }) + + it(`should call onSubmit handler if form is valid`, () => { + // Given + process.NODE_ENV = 'test' + const walletAddress = '0xAC7022d55dA6C8BB229b1Ba3Ce8A16724FF79c4A' + const [{ type: strategy }] = strategies + stores.crowdsaleStore.setProperty('strategy', strategy) + stores.tierStore.addCrowdsale(walletAddress) + stores.tokenStore.setProperty('decimals', 18) + + const wrapper = mount( + + + + + + ) + const handleOnSubmit = jest.spyOn(wrapper.find('StepThree').instance(), 'handleOnSubmit') + + // When + wrapper.find('input[name="walletAddress"]').simulate('change', { target: { value: walletAddress } }) + wrapper.find('input[name="tiers[0].endTime"]').simulate('change', { target: { value: '2018-03-14T12:00:00' } }) + wrapper.find('input[name="tiers[0].rate"]').simulate('change', { target: { value: '100000' } }) + wrapper.find('input[name="tiers[0].supply"]').simulate('change', { target: { value: '100' } }) + + // Then + + const form = wrapper.find('form').at(0) + const children = form + .render() + .children() + .children() + form.simulate('submit', { target: { children } }) + + setTimeout(() => { + wrapper.update() + expect(handleOnSubmit).toHaveBeenCalledTimes(1) + }, 2000) + }) }) diff --git a/test/components/StepTwo/StepTwoForm.spec.js b/test/components/StepTwo/StepTwoForm.spec.js index 3d062c484..1ec75064f 100644 --- a/test/components/StepTwo/StepTwoForm.spec.js +++ b/test/components/StepTwo/StepTwoForm.spec.js @@ -34,6 +34,8 @@ describe('StepTwoForm', () => { component={StepTwoForm} id="tokenData" reload={true} + goBack={jest.fn()} + goBackEnabled={jest.fn()} /> ) @@ -59,6 +61,8 @@ describe('StepTwoForm', () => { component={StepTwoForm} id="tokenData" reload={false} + goBack={jest.fn()} + goBackEnabled={jest.fn()} /> ) @@ -81,6 +85,9 @@ describe('StepTwoForm', () => { }} component={StepTwoForm} id="tokenData" + reload={false} + goBack={jest.fn()} + goBackEnabled={jest.fn()} /> ) @@ -103,6 +110,9 @@ describe('StepTwoForm', () => { }} component={StepTwoForm} id="tokenData" + reload={false} + goBack={jest.fn()} + goBackEnabled={jest.fn()} /> ) diff --git a/test/components/StepTwo/__snapshots__/StepTwoForm.spec.js.snap b/test/components/StepTwo/__snapshots__/StepTwoForm.spec.js.snap index c5af858f6..6159a4964 100644 --- a/test/components/StepTwo/__snapshots__/StepTwoForm.spec.js.snap +++ b/test/components/StepTwo/__snapshots__/StepTwoForm.spec.js.snap @@ -32,6 +32,7 @@ exports[`StepTwoForm should render StepTwoForm for Dutch Auction Crowdsale 1`] =