Best JavaScript code snippet using storybook-root
NegativeTests.js
Source:NegativeTests.js
1var tokenUtils = require('./TokenTestUtils');2var BigNumber = require('bignumber.js');3var assertDiff = require('assert-diff');4assertDiff.options.strict = true;56var bigZero = tokenUtils.bigZero;7var bigHundred = tokenUtils.bigHundred;8var mint = tokenUtils.mint;9var checkVariables = tokenUtils.checkVariables;10var expectRevert = tokenUtils.expectRevert;11var name = tokenUtils.name;12var symbol = tokenUtils.symbol;13var currency = tokenUtils.currency;14var decimals = tokenUtils.decimals;15var deployerAccount = tokenUtils.deployerAccount;16var arbitraryAccount = tokenUtils.arbitraryAccount;17var arbitraryAccount2 = tokenUtils.arbitraryAccount2;18var tokenOwnerAccount = tokenUtils.tokenOwnerAccount;19var tokenOwnerAccount = tokenUtils.tokenOwnerAccount;20var blacklisterAccount = tokenUtils.blacklisterAccount;21var masterMinterAccount = tokenUtils.masterMinterAccount;22var minterAccount = tokenUtils.minterAccount;23var pauserAccount = tokenUtils.pauserAccount;24var proxyOwnerAccount = tokenUtils.proxyOwnerAccount;25var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy;26var customInitializeTokenWithProxy = tokenUtils.customInitializeTokenWithProxy;27var upgradeTo = tokenUtils.upgradeTo;28var UpgradedFiatToken = tokenUtils.UpgradedFiatToken;29var FiatToken = tokenUtils.FiatToken;3031var amount = 100;32let longZero = 0x0000000000000000000000000000000000000000;33let shortZero = 0x00;3435async function run_tests(newToken, accounts) {3637 beforeEach('Make fresh token contract', async function () {38 rawToken = await newToken();39 var tokenConfig = await initializeTokenWithProxy(rawToken);40 proxy = tokenConfig.proxy;41 token = tokenConfig.token;42 assert.equal(proxy.address, token.address);43 });444546 // Mint4748 it('nt001 should fail to mint when paused', async function () {49 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});50 await token.pause({from: pauserAccount});51 var customVars = [52 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},53 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)},54 {'variable': 'paused', 'expectedValue': true}55 ]56 await expectRevert(token.mint(arbitraryAccount, 50, {from: minterAccount}));57 await checkVariables([token], [customVars]);58 });5960 it('nt002 should fail to mint when msg.sender is not a minter', async function () {61 //Note: minterAccount has not yet been configured as a minter62 await expectRevert(token.mint(arbitraryAccount, 50, {from: minterAccount}));63 await checkVariables([token], [[]]);64 });6566 it('nt003 should fail to mint when msg.sender is blacklisted', async function () {67 await token.blacklist(minterAccount, {from: blacklisterAccount});68 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});69 var customVars = [70 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},71 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)},72 {'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true}73 ]74 await expectRevert(token.mint(arbitraryAccount, 50, {from: minterAccount}));75 await checkVariables([token], [customVars]);76 });7778 it('nt004 should fail to mint when recipient is blacklisted', async function () {79 await token.blacklist(arbitraryAccount, {from: blacklisterAccount});80 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});81 var customVars = [82 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},83 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)},84 {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true}85 ]86 await expectRevert(token.mint(arbitraryAccount, 50, {from: minterAccount}));87 await checkVariables([token], [customVars]);88 });8990 it('nt005 should fail to mint when allowance of minter is less than amount', async function () {91 await token.configureMinter(minterAccount, amount - 1, {from: masterMinterAccount});92 var customVars = [93 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},94 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 1)}95 ]96 await expectRevert(token.mint(arbitraryAccount, amount, {from: minterAccount}));97 await checkVariables([token], [customVars]);98 });99100 it('nt006 should fail to mint to 0x0 address', async function () {101 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});102 var customVars = [103 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},104 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}105 ]106 await expectRevert(token.mint("0x0", amount, {from: minterAccount}));107 await expectRevert(token.mint("0x0000000000000000000000000000000000000000", amount, {from: minterAccount}));108 await expectRevert(token.mint(0x0000000000000000000000000000000000000000, amount, {from: minterAccount}));109 await checkVariables([token], [customVars]);110 });111112 // Approve113114 it('nt008 should fail to approve when spender is blacklisted', async function () {115 await token.blacklist(minterAccount, {from: blacklisterAccount});116 var customVars = [117 {'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true},118 ]119 await expectRevert(token.approve(minterAccount, 100, {from: arbitraryAccount}));120 await checkVariables([token], [customVars]);121 });122123 it('nt009 should fail to approve when msg.sender is blacklisted', async function () {124 await token.blacklist(arbitraryAccount, {from: blacklisterAccount});125 var customVars = [126 {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true},127 ]128 await expectRevert(token.approve(minterAccount, 100, {from: arbitraryAccount}));129 await checkVariables([token], [customVars]);130 });131132 it('nt010 should fail to approve when contract is paused', async function () {133 await token.pause({from: pauserAccount});134 var customVars = [135 {'variable': 'paused', 'expectedValue': true},136 ]137 await expectRevert(token.approve(minterAccount, 100, {from: arbitraryAccount}));138 await checkVariables([token], [customVars]);139 });140141 // TransferFrom142143 it('nt012 should fail to transferFrom to 0x0 address', async function () {144 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});145 var customVars = [146 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},147 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}148 ]149 await checkVariables([token], [customVars]);150151 await token.mint(arbitraryAccount, 50, {from: minterAccount});152 await token.approve(pauserAccount, 50, {from: arbitraryAccount});153 customVars = [154 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},155 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},156 {'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(50)},157 {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)},158 {'variable': 'allowance.arbitraryAccount.pauserAccount', 'expectedValue': new BigNumber(50)}159 ]160 await expectRevert(token.transferFrom(arbitraryAccount, "0x0", 50, {from: pauserAccount}));161 await checkVariables([token], [customVars]);162 });163164 it('nt013 should fail to transferFrom an amount greater than balance', async function () {165 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});166 customVars = [167 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},168 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}169 ]170 await checkVariables([token], [customVars]);171172 await token.mint(arbitraryAccount, 50, {from: minterAccount});173 await token.approve(blacklisterAccount, amount, {from: arbitraryAccount});174 customVars = [175 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},176 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},177 {'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(50)},178 {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)},179 {'variable': 'allowance.arbitraryAccount.blacklisterAccount', 'expectedValue': new BigNumber(amount)},180 ]181 await expectRevert(token.transferFrom(arbitraryAccount, pauserAccount, amount, {from: blacklisterAccount}));182 await checkVariables([token], [customVars]);183 });184185 it('nt014 should fail to transferFrom to blacklisted recipient', async function () {186 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});187 customVars = [188 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},189 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}190 ]191 await checkVariables([token], [customVars]);192193 await token.mint(blacklisterAccount, 50, {from: minterAccount});194 await token.approve(pauserAccount, 50, {from: blacklisterAccount});195 await token.blacklist(arbitraryAccount, {from: blacklisterAccount});196 customVars = [197 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},198 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},199 {'variable': 'balances.blacklisterAccount', 'expectedValue': new BigNumber(50)},200 {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)},201 {'variable': 'allowance.blacklisterAccount.pauserAccount', 'expectedValue': new BigNumber(50)},202 {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true}203 ]204 await expectRevert(token.transferFrom(blacklisterAccount, arbitraryAccount, 50, {from: pauserAccount}));205 await checkVariables([token], [customVars]);206 });207208 it('nt015 should fail to transferFrom from blacklisted msg.sender', async function () {209 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});210 customVars = [211 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},212 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}213 ]214 await checkVariables([token], [customVars]);215216 await token.mint(tokenOwnerAccount, 50, {from: minterAccount});217 await token.approve(arbitraryAccount, 50, {from: tokenOwnerAccount});218 await token.blacklist(arbitraryAccount, {from: blacklisterAccount});219 customVars = [220 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},221 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},222 {'variable': 'balances.tokenOwnerAccount', 'expectedValue': new BigNumber(50)},223 {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)},224 {'variable': 'allowance.tokenOwnerAccount.arbitraryAccount', 'expectedValue': new BigNumber(50)},225 {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true}226 ]227 await expectRevert(token.transferFrom(tokenOwnerAccount, pauserAccount, 50, {from: arbitraryAccount}));228 await checkVariables([token], [customVars]);229 });230231 it('nt016 should fail to transferFrom when from is blacklisted', async function () {232 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});233 customVars = [234 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},235 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}236 ]237 await checkVariables([token], [customVars]);238239 await token.mint(arbitraryAccount, 50, {from: minterAccount});240 await token.approve(tokenOwnerAccount, 50, {from: arbitraryAccount});241 await token.blacklist(arbitraryAccount, {from: blacklisterAccount});242 customVars = [243 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},244 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},245 {'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(50)},246 {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)},247 {'variable': 'allowance.arbitraryAccount.tokenOwnerAccount', 'expectedValue': new BigNumber(50)},248 {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true}249 ]250 await expectRevert(token.transferFrom(arbitraryAccount, pauserAccount, 50, {from: tokenOwnerAccount}));251 await checkVariables([token], [customVars]);252 });253254 it('nt017 should fail to transferFrom an amount greater than allowed for msg.sender', async function () {255 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});256 customVars = [257 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},258 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}259 ]260 await checkVariables([token], [customVars]);261262 await token.mint(arbitraryAccount, 50, {from: minterAccount});263 await token.approve(tokenOwnerAccount, 50, {from: arbitraryAccount});264 customVars = [265 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},266 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},267 {'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(50)},268 {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)},269 {'variable': 'allowance.arbitraryAccount.tokenOwnerAccount', 'expectedValue': new BigNumber(50)},270 ]271 await expectRevert(token.transferFrom(arbitraryAccount, pauserAccount, 60, {from: tokenOwnerAccount}));272 await checkVariables([token], [customVars]);273 });274275 it('nt018 should fail to transferFrom when paused', async function () {276 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});277 var customVars = [278 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},279 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}280 ]281 await checkVariables([token], [customVars]);282283 await token.mint(arbitraryAccount, 50, {from: minterAccount});284 await token.approve(tokenOwnerAccount, 50, {from: arbitraryAccount});285 await token.pause({from: pauserAccount});286 customVars = [287 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},288 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},289 {'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(50)},290 {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)},291 {'variable': 'allowance.arbitraryAccount.tokenOwnerAccount', 'expectedValue': new BigNumber(50)},292 {'variable': 'paused', 'expectedValue': true}293 ]294 await expectRevert(token.transferFrom(arbitraryAccount, pauserAccount, 50, {from: tokenOwnerAccount}));295 await checkVariables([token], [customVars]);296 });297298 // Transfer299300 it('nt020 should fail to transfer to 0x0 address', async function () {301 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});302 var customVars = [303 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},304 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}305 ]306 await checkVariables([token], [customVars]);307308 await token.mint(arbitraryAccount, 50, {from: minterAccount});309 customVars = [310 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},311 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},312 {'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(50)},313 {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)}314 ]315 await expectRevert(token.transfer("0x0", 50, {from: arbitraryAccount}));316 await checkVariables([token], [customVars]);317 });318319 it('nt021 should fail to transfer an amount greater than balance', async function () {320 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});321 customVars = [322 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},323 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}324 ]325 await checkVariables([token], [customVars]);326327 await token.mint(arbitraryAccount, 50, {from: minterAccount});328 var customVars = [329 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},330 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},331 {'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(50)},332 {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)}333 ]334 await expectRevert(token.transfer(pauserAccount, amount, {from: arbitraryAccount}));335 await checkVariables([token], [customVars]);336 });337338 it('nt022 should fail to transfer to blacklisted recipient', async function () {339 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});340 customVars = [341 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},342 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}343 ]344 await checkVariables([token], [customVars]);345346 await token.mint(tokenOwnerAccount, 50, {from: minterAccount});347 await token.blacklist(arbitraryAccount, {from: blacklisterAccount});348 customVars = [349 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},350 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},351 {'variable': 'balances.tokenOwnerAccount', 'expectedValue': new BigNumber(50)},352 {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)},353 {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true}354 ]355 await expectRevert(token.transfer(arbitraryAccount, 50, {from: tokenOwnerAccount}));356 await checkVariables([token], [customVars]);357 });358359 it('nt023 should fail to transfer when sender is blacklisted', async function () {360 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});361 customVars = [362 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},363 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}364 ]365 await checkVariables([token], [customVars]);366367 await token.mint(arbitraryAccount, 50, {from: minterAccount});368 await token.blacklist(arbitraryAccount, {from: blacklisterAccount});369 customVars = [370 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},371 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},372 {'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(50)},373 {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)},374 {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true}375 ]376 await expectRevert(token.transfer(tokenOwnerAccount, 50, {from: arbitraryAccount}));377 await checkVariables([token], [customVars]);378 });379380 it('nt024 should fail to transfer when paused', async function () {381 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});382 var customVars = [383 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},384 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}385 ]386 await checkVariables([token], [customVars]);387388 await token.mint(arbitraryAccount, 50, {from: minterAccount});389 await token.pause({from: pauserAccount});390 customVars = [391 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},392 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},393 {'variable': 'balances.arbitraryAccount', 'expectedValue': new BigNumber(50)},394 {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)},395 {'variable': 'paused', 'expectedValue': true}396 ]397 await expectRevert(token.transfer(tokenOwnerAccount, 50, {from: arbitraryAccount}));398 await checkVariables([token], [customVars]);399 });400401 // ConfigureMinter402403 it('nt026 should fail to configureMinter when sender is not masterMinter', async function () {404 assert.isFalse(arbitraryAccount == masterMinterAccount);405 await expectRevert(token.configureMinter(minterAccount, amount, {from: arbitraryAccount}));406 await checkVariables([token], [[]]);407 });408409410 it('nt028 should fail to configureMinter when paused', async function () {411 await token.pause({from: pauserAccount});412 customVars = [413 {'variable': 'paused', 'expectedValue': true}414 ]415 await expectRevert(token.configureMinter(minterAccount, amount, {from: masterMinterAccount}));416 await checkVariables([token], [customVars]);417 });418419 // RemoveMinter420421 it('nt029 should fail to removeMinter when sender is not masterMinter', async function () {422 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});423 var customVars = [424 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},425 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}426 ]427 await expectRevert(token.removeMinter(minterAccount, {from: arbitraryAccount}));428 await checkVariables([token], [customVars]);429 });430431 // Burn432433 it('nt031 should fail to burn when balance is less than amount', async function () {434 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});435 var customVars = [436 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},437 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}438 ]439 await expectRevert(token.burn(amount, {from: minterAccount}));440 await checkVariables([token], [customVars]);441 });442443 it('nt032 should fail to burn when amount is -1', async function () {444 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});445 await token.mint(minterAccount, amount, {from: minterAccount});446 var customVars = [447 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},448 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0)},449 {'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(amount)},450 {'variable': 'totalSupply', 'expectedValue': new BigNumber(amount)}451 ]452 await expectRevert(token.burn(-1, {from: minterAccount}));453 await checkVariables([token], [customVars]);454 });455456 it('nt033 should fail to burn when sender is blacklisted', async function () {457 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});458 var customVars = [459 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},460 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}461 ]462 await checkVariables([token], [customVars]);463464 await token.mint(minterAccount, 50, {from: minterAccount});465 await token.blacklist(minterAccount, {from: blacklisterAccount});466 customVars = [467 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},468 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},469 {'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(50)},470 {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)},471 {'variable': 'isAccountBlacklisted.minterAccount', 'expectedValue': true}472 ]473 await expectRevert(token.burn(50, {from: minterAccount}));474 await checkVariables([token], [customVars]);475 });476477 it('nt034 should fail to burn when paused', async function () {478 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});479 var customVars = [480 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},481 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}482 ]483 await checkVariables([token], [customVars]);484485 await token.mint(minterAccount, 50, {from: minterAccount});486 await token.pause({from: pauserAccount});487 customVars = [488 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},489 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},490 {'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(50)},491 {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)},492 {'variable': 'paused', 'expectedValue': true}493 ]494 await expectRevert(token.burn(50, {from: minterAccount}));495 await checkVariables([token], [customVars]);496 });497498 it('nt035 should fail to burn when sender is not minter', async function () {499 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});500 var customVars = [501 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},502 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}503 ]504 await checkVariables([token], [customVars]);505506 await token.mint(minterAccount, 50, {from: minterAccount});507 customVars = [508 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},509 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},510 {'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(50)},511 {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)}512 ]513 await expectRevert(token.burn(50, {from: arbitraryAccount}));514 await checkVariables([token], [customVars]);515 });516517 it('nt036 should fail to burn after removeMinter', async function () {518 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});519 var customVars = [520 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},521 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}522 ]523 await checkVariables([token], [customVars]);524525 await token.mint(minterAccount, 50, {from: minterAccount});526 customVars = [527 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},528 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount - 50)},529 {'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(50)},530 {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)}531 ]532 await checkVariables([token], [customVars]);533534 await token.removeMinter(minterAccount, {from: masterMinterAccount});535 customVars = [536 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': false},537 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(0)},538 {'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(50)},539 {'variable': 'totalSupply', 'expectedValue': new BigNumber(50)}540 ]541 await expectRevert(token.burn(50, {from: minterAccount}));542 await checkVariables([token], [customVars]);543 });544545 // Update functions546547 it('nt050 should fail to updatePauser when sender is not owner', async function () {548 await expectRevert(token.updatePauser(arbitraryAccount, {from: pauserAccount}));549 await checkVariables([token], [[]]);550 });551552 it('nt049 should fail to updateMasterMinter when sender is not owner', async function () {553 await expectRevert(token.updateMasterMinter(arbitraryAccount, {from: pauserAccount}));554 await checkVariables([token], [[]]);555 });556557 it('nt048 should fail to updateBlacklister when sender is not owner', async function () {558 await expectRevert(token.updateBlacklister(arbitraryAccount, {from: pauserAccount}));559 await checkVariables([token], [[]]);560 });561562 // Pause and Unpause563564 it('nt040 should fail to pause when sender is not pauser', async function () {565 await expectRevert(token.pause({from: arbitraryAccount}));566 await checkVariables([token], [[]]);567 });568569 it('nt041 should fail to unpause when sender is not pauser', async function () {570 await token.pause({from: pauserAccount});571 customVars = [572 {'variable': 'paused', 'expectedValue': true}573 ]574 await expectRevert(token.unpause({from: arbitraryAccount}));575 await checkVariables([token], [customVars]);576 });577578 // Blacklist and Unblacklist579580 it('nt042 should fail to blacklist when sender is not blacklister', async function () {581 await expectRevert(token.blacklist(tokenOwnerAccount, {from: arbitraryAccount}));582 await checkVariables([token], [[]]);583 });584585 it('nt043 should fail to unblacklist when sender is not blacklister', async function () {586 await token.blacklist(arbitraryAccount, {from: blacklisterAccount});587 customVars = [588 {'variable': 'isAccountBlacklisted.arbitraryAccount', 'expectedValue': true}589 ]590 await expectRevert(token.unBlacklist(arbitraryAccount, {from: tokenOwnerAccount}));591 await checkVariables([token], [customVars]);592 });593594 // Upgrade595596 it('nt054 should fail to transferOwnership when sender is not owner', async function() {597 // Create upgraded token598 var newRawToken = await UpgradedFiatToken.new();599 var tokenConfig = await upgradeTo(proxy, newRawToken);600 var newProxiedToken = tokenConfig.token;601 var newToken = newProxiedToken;602603 var newToken_result = [604 { 'variable': 'proxiedTokenAddress', 'expectedValue': newRawToken.address }605 ];606607 // expectRevert on transferOwnership with wrong sender608 await expectRevert(newToken.transferOwnership(arbitraryAccount, {from: arbitraryAccount2}));609 await checkVariables([newToken], [newToken_result]);610 });611612 it('nt055 should fail to mint when amount = 0', async function() {613 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});614 await expectRevert(token.mint(pauserAccount, 0, {from: minterAccount}));615616 var customVars = [617 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},618 {'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount)}619 ]620 await checkVariables([token], [customVars]);621 });622623 it('nt056 should fail to burn when amount = 0', async function() {624 await token.configureMinter(minterAccount, amount, {from: masterMinterAccount});625 await token.mint(minterAccount, amount, {from: minterAccount});626 await expectRevert(token.burn(0, {from: minterAccount}));627 var customVars = [628 {'variable': 'isAccountMinter.minterAccount', 'expectedValue': true},629 {'variable': 'balances.minterAccount', 'expectedValue': new BigNumber(amount)},630 {'variable': 'totalSupply', 'expectedValue': new BigNumber(amount)}631 ]632 await checkVariables([token], [customVars]);633 });634635 it('nt064 transferOwnership should fail on 0x0', async function () {636 await expectRevert(token.transferOwnership(longZero, { from: tokenOwnerAccount }));637 await expectRevert(token.transferOwnership(shortZero, { from: tokenOwnerAccount }));638 });639640 it('nt057 updateMasterMinter should fail on 0x0', async function () {641 await expectRevert(token.updateMasterMinter(longZero, { from: tokenOwnerAccount }));642 await expectRevert(token.updateMasterMinter(shortZero, { from: tokenOwnerAccount }));643 });644645 it('nt058 updatePauser should fail on 0x0', async function () {646 await expectRevert(token.updatePauser(longZero, { from: tokenOwnerAccount }));647 await expectRevert(token.updatePauser(shortZero, { from: tokenOwnerAccount }));648 });649650 it('nt059 updateBlacklister should fail on 0x0', async function () {651 await expectRevert(token.updateBlacklister(longZero, { from: tokenOwnerAccount }));652 await expectRevert(token.updateBlacklister(shortZero, { from: tokenOwnerAccount }));653 });654655 it('nt060 initialize should fail when _masterMinter is 0x0', async function () {656 rawToken = await newToken();657 await expectRevert(customInitializeTokenWithProxy(rawToken, longZero, pauserAccount, blacklisterAccount, tokenOwnerAccount));658 await expectRevert(customInitializeTokenWithProxy(rawToken, shortZero, pauserAccount, blacklisterAccount, tokenOwnerAccount));659 });660661 it('nt061 initialize should fail when _pauser is 0x0', async function () {662 rawToken = await newToken();663 await expectRevert(customInitializeTokenWithProxy(rawToken, masterMinterAccount, longZero, blacklisterAccount, tokenOwnerAccount));664 await expectRevert(customInitializeTokenWithProxy(rawToken, masterMinterAccount, shortZero, blacklisterAccount, tokenOwnerAccount));665 });666667 it('nt062 initialize should fail when _blacklister is 0x0', async function () {668 rawToken = await newToken();669 await expectRevert(customInitializeTokenWithProxy(rawToken, masterMinterAccount, pauserAccount, longZero, tokenOwnerAccount));670 await expectRevert(customInitializeTokenWithProxy(rawToken, masterMinterAccount, pauserAccount, shortZero, tokenOwnerAccount));671 });672673 it('nt063 initialize should fail when _owner is 0x0', async function () {674 rawToken = await newToken();675 await expectRevert(customInitializeTokenWithProxy(rawToken, masterMinterAccount, pauserAccount, blacklisterAccount, longZero));676 await expectRevert(customInitializeTokenWithProxy(rawToken, masterMinterAccount, pauserAccount, blacklisterAccount, shortZero));677 });678}679680var testWrapper = require('./TestWrapper');681testWrapper.execute('FiatToken_NegativeTests', run_tests);682683module.exports = {684 run_tests: run_tests,
...
at-internet-download.js
Source:at-internet-download.js
1/**2 * Script que envÃa los datos de la analÃtica web al proveedor de AT-Internet. 3 * 4 * @author Jonatan Jumbert5 * @contact hola@jonatanjumbert.com - http://jonatanjumbert.com6 * @version 0.8.47 */8/*9 * Variables globales de la configuración AT-Internet10 * y de los datos de la propia página para poder utilizar desde el callback del player.11 */ 12var current_url = null;13var debugData = null;14var level2 = null;15var producer = "";16$(function() {17 var url_segments = null;18 var siteID = null;19 var lang = "es";20 var debugEnabled = true;21 22 // Comprobamos si existe console, para debugar23 if(!window.console) console = { log: function(){} };24 25 /**26 * Funcion para debugar variables por consola.27 * Siempre que la variable debugEnabled sea true.28 */29 debugData = function(obj) {30 if(debugEnabled) {31 if(typeof obj.action !== "undefined" && obj.action != "") {32 console.log('[INI]:::[AT-INTERNET]::: ' + obj.action + '::::');33 }34 35 for(var property in obj) {36 if(obj.hasOwnProperty(property) && property != "action") {37 console.log(obj[property]);38 }39 }40 41 if(typeof obj.action !== "undefined" && obj.action != "") {42 console.log('[FIN]:::[AT-INTERNET]::: ' + obj.action + '::::');43 }44 }45 };46 47 /**48 * Devuelve el último segmento de la URL pasada por parámetro.49 */50 var getLastSegmentFromURL = function(url) {51 var segments = url.split("/");52 return segments.pop();53 };54 55 /**56 * Recupera el nombre del programa que estamos descargando.57 */58 var getProgramTitle = function() {59 if($('h1.regular-text').length > 0) {60 var data_slug = $('h1.regular-text').attr('data-slug');61 62 if(data_slug !== "undefined" && data_slug != "") {63 return data_slug;64 } else {65 return false;66 }67 } else {68 return "";69 }70 };71 72 /**73 * Recupera el idioma de la página actual.74 * @FIXME Importante que Balidea incluya en el código fuente de todas las páginas 75 */76 var getLanguage = (function() {77 lang = $('html').attr('lang');78 if(typeof lang !== "undefined" && lang != "") {79 lang_split = lang.split("-");80 if(lang_split.length > 1) {81 lang = lang_split[0].toUpperCase();82 }83 } else {84 lang = "EN";85 }86 })();87 88 /**89 * Guarda en url_segments un array con los segmentos de la URL actual.90 * Incluye como primer segmento el Idioma aunque se trate del Inglés y por defecto no aparezca en la URL.91 */92 var getURLSegments = (function() {93 var url_segments_cleaned = [];94 var segments = location.pathname.split("/");95 for(var i = 0; i < segments.length; i++) {96 if(segments[i] != "") {97 url_segments_cleaned.push(segments[i]);98 }99 }100 url_segments = url_segments_cleaned;101 if(lang == "EN" && url_segments[0] != "EN") {102 url_segments.unshift('EN');103 } 104 if(url_segments.length == 0) {105 url_segments.unshift('EN');106 }107 108 return url_segments;109 })();110 111 /**112 * Recupera los parámetros del Query String. Por ejemplo: ?foo=lorem&bar=&baz113 * var foo = getParameterByName('foo'); // "lorem"114 * var bar = getParameterByName('bar'); // "" (present with empty value)115 * var baz = getParameterByName('baz'); // "" (present with no value)116 * var qux = getParameterByName('qux'); // null (absent)117 *118 * @see http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript119 */120 var getParameterByName = function(name, url) {121 if(!url) {122 url = window.location.href;123 }124 name = name.replace(/[\[\]]/g, "\\$&");125 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url);126 if(!results) return null;127 if(!results[2]) return '';128 return decodeURIComponent(results[2].replace(/\+/g, " "));129 };130 131 /**132 * Desactiva el modo debug para el entorno de PRODUCCION a excepcion133 * si se pasa por parámetro en la URL ?debugEnabled=true 134 */135 var configureDebugMode = (function() {136 if(window.location.hostname != "www.europarltv.europa.eu") {137 debugEnabled = true;138 } else {139 var debugParam = getParameterByName("debugEnabled");140 if(debugParam != null && debugParam == "true") {141 debugEnabled = true;142 } else {143 debugEnabled = false;144 }145 }146 })();147 148 /**149 * Comprueba si la página actual es la home login.150 */ 151 var checkLoginPage = function() {152 if(window.location.href.indexOf("login") === -1 ) {153 if(url_segments.length == 1 && url_segments[0].length == 2) {154 return true155 } else {156 return false;157 }158 } else {159 return true;160 }161 };162 163 /**164 * Comprueba si la página actual es la de descarga de un programa.165 */166 var checkVideoPage = function() {167 if(window.location.href.indexOf("programmeId") === -1 ) {168 return false;169 } else {170 return true;171 }172 }173 174 /**175 * Objeto que contiene los datos de los segmentos de la URL actual, idioma y determina que tipo de página estamos visitando.176 */ 177 var initURLObject = (function() {178 var instance;179 180 function createInstance() {181 var is_login_page = checkLoginPage();182 var is_video_page = checkVideoPage();183 184 return {185 'url_path' : url_segments,186 'previous_page' : (typeof(Storage) !== "undefined" && localStorage.previous_page_download != "") ? localStorage.previous_page_download : "",187 'previous_chapter' : (typeof(Storage) !== "undefined" && localStorage.previous_chapter_download != "") ? localStorage.previous_chapter_download : "",188 'lang' : lang,189 'login' : is_login_page,190 'home' : (!is_login_page && !is_video_page && $('.search-video-form').length > 0) ? true : false,191 'video' : is_video_page,192 };193 }194 195 return {196 // Método Singleton, instanciamos únicamente una vez este objeto.197 getInstance: function() {198 if(!instance) {199 instance = createInstance();200 }201 return instance;202 },203 // Guardamos los datos de la página actual204 setCurrentPageData : function() {205 if(typeof(Storage) !== "undefined") {206 // Guardar datos que corresponda a cada página.207 if(current_url.home) {208 localStorage.previous_chapter_download = "download";209 localStorage.previous_page_download = "hompage";210 } else if(current_url.login) {211 localStorage.previous_chapter_download = "download";212 localStorage.previous_page_download = "login";213 } else if(current_url.video) {214 if($('div.col-download ul.nav.nav-tabs li.active').length > 0) {215 var text = $('a', $('div.col-download ul.nav.nav-tabs li.active')).html();216 var active_tab = (text !== "undefined" && text != "") ? text.toLowerCase() : "download";217 localStorage.previous_chapter_download = "download";218 localStorage.previous_page_download = active_tab;219 }220 }221 localStorage.current_time_download = Math.floor(Date.now() / 1000);222 }223 }224 };225 })();226 /**227 * Se inicializa el objeto de AT-Internet con los datos que hacen referencia al site y al level2 en el código fuente de la página.228 * @FIXME Importante que Balidea, ponga esos datos en el código fuente de todas las páginas dependiendo del Entorno (DEV/PRE/PRO).229 */230 var initATInternetTag = (function() {231 return {232 getInstance: function() {233 siteID = (typeof site_id !== "undefined") ? site_id : 573738;234 level2 = (typeof level2Id !== "undefined") ? level2Id : 2;235 return new ATInternet.Tracker.Tag({log: "logc407", logSSL: "logs1407", secure: false, site: siteID, domain: "xiti.com"});236 }237 };238 })();239 240 /**241 * Recupera las variables del sitio personalizadas.242 * @FIXME Importante que Balidea implemente una etiqueta #tags-list con data-tags para poder recuperar correctamente los tags de la página si los hubiera.243 */244 var getVariablesSitioPersonalizadas = function() {245 var variablesSitioPersonalizadas = {246 7 : lang.toUpperCase()247 };248 249 if($('#tags-list').length > 0) {250 var tagsList = $('#tags-list').attr('data-tags');251 if(tagsList !== undefined && tagsList !== "undefined" && tagsList != "") {252 variablesSitioPersonalizadas[2] = "[" + tagsList + "]";253 }254 }255 256 if(typeof(Storage) !== "undefined" && localStorage.previous_chapter_download !== undefined && localStorage.previous_chapter_download != "") {257 variablesSitioPersonalizadas[3] = "[" + localStorage.previous_chapter_download + "]";258 }259 if(typeof(Storage) !== "undefined" && localStorage.previous_page_download !== undefined && localStorage.previous_page_download != "") {260 variablesSitioPersonalizadas[4] = "[" + localStorage.previous_page_download + "]";261 }262 263 return variablesSitioPersonalizadas;264 };265 266 /**267 * Si estamos en la página de búsqueda, según el plan de marcaje se han definido variables 268 * personalizadas que hay que enviar a la herramienta de analÃtica.269 */270 var getVariablesPaginaBusqueda = function() {271 var result = {};272 273 if($('.search-video-form').length > 0) {274 $('div.search-video-form input').each(function () {275 if($(this).attr('id') == "_downloadlist_WAR_europarltv_download_list_:j_idt6:inputTextSearchBy") {276 if(this.value != "") {277 result[1] = "[" + this.value + "]";278 }279 } else if($(this).attr('id') == "_downloadlist_WAR_europarltv_download_list_:j_idt6:calendarFrom_input") {280 var current_value = this.value;281 var current_value_split = current_value.split('/');282 if(current_value_split.length == 3) {283 var send_value = parseInt("" + current_value_split[2] + current_value_split[1] + current_value_split[0], 10);284 result[2] = "[" + send_value + "]";285 }286 } else if($(this).attr('id') == "_downloadlist_WAR_europarltv_download_list_:j_idt6:calendarTo_input") {287 var current_value = this.value;288 var current_value_split = current_value.split('/');289 if(current_value_split.length == 3) {290 var send_value = parseInt("" + current_value_split[2] + current_value_split[1] + current_value_split[0], 10);291 result[3] = "[" + send_value + "]";292 }293 } 294 });295 296 if($('label#_downloadlist_WAR_europarltv_download_list_\\:j_idt6\\:types_label').length > 0) {297 var types_label = $('label#_downloadlist_WAR_europarltv_download_list_\\:j_idt6\\:types_label').html();298 if(types_label != "") {299 result[4] = types_label; 300 }301 }302 303 if($('label#_downloadlist_WAR_europarltv_download_list_\\:j_idt6\\:categories_label').length > 0) {304 var categories_label = $('label#_downloadlist_WAR_europarltv_download_list_\\:j_idt6\\:categories_label').html();305 if(categories_label != "") {306 result[5] = categories_label; 307 }308 }309 310 if($('#_downloadlist_WAR_europarltv_download_list_\\:j_idt6\\:meps li span').length > 0) {311 var send_value = "";312 var meps = [];313 314 $('#_downloadlist_WAR_europarltv_download_list_\\:j_idt6\\:meps li span').each(function(i, val) {315 var valor = $(val).html();316 if(valor != "") {317 meps.push(valor);318 }319 });320 321 if(meps.length > 0) {322 send_value += meps.join('|');323 result[6] = "[" + send_value + "]";324 }325 }326 }327 return result;328 };329 330 /**331 * Si el usuario selecciona descargar un video o únicamente los subitulos, según el plan de marcaje se han definido variables 332 * personalizadas que hay que enviar a la herramienta de analÃtica.333 */334 var getVariablesPaginaDownload = function(downloadType) {335 var result = {};336 337 var programTitle = getProgramTitle();338 if(programTitle != "") {339 result[1] = programTitle;340 }341 342 if($('input#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:downloadLangCode').length > 0) {343 var idioma = $('input#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:downloadLangCode').val();344 if(idioma !== "undefined" && idioma !== undefined && idioma != "") {345 result[2] = idioma;346 }347 }348 349 if(downloadType && downloadType !== "") {350 result[3] = downloadType;351 }352 353 return result;354 };355 356 /**357 * Variables personalizadas para cuando el usuario hace un request de un video.358 */359 var getVariablesPaginaRequest = function() {360 var result = {};361 362 var programTitle = getProgramTitle();363 if(programTitle != "") {364 result[1] = programTitle;365 }366 367 if($('select#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:selectVideoFormat_input').length > 0) {368 var format = $('select#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:selectVideoFormat_input').val();369 if(format != "") {370 result[2] = format;371 }372 }373 374 if($('select#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:selectVideoResolution_input').length > 0) {375 var resolution = $('select#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:selectVideoResolution_input').val();376 if(resolution != "") {377 result[3] = resolution;378 }379 }380 if($('select#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:selectBitRate_input').length > 0) {381 var bitrate = $('select#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:selectBitRate_input').val();382 if(bitrate != "") {383 result[4] = bitrate;384 }385 }386 // Voice over387 if($('input#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:requestVOLangCode').length > 0) {388 var idioma = $('input#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:requestSTLangCode').val();389 if(idioma !== "undefined" && idioma !== undefined && idioma != "") {390 result[6] = idioma;391 }392 }393 394 // Burnt subtitles395 if($('input#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:requestSTLangCode').length > 0) {396 var idioma = $('input#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:requestSTLangCode').val();397 if(idioma !== "undefined" && idioma !== undefined && idioma != "") {398 result[6] = idioma;399 }400 }401 402 // European parliament logo403 result[7] = ($('div#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:checkLogo div.ui-state-active').length > 0) ? '1' : '2';404 405 return result;406 };407 408 /**409 * Variables personalizadas para cuando el usuario hace un copy de un embed.410 */411 var getVariablesPaginaEmbed = function() {412 var result = {};413 414 var programTitle = getProgramTitle();415 if(programTitle != "") {416 result[1] = programTitle;417 }418 419 if($('input#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:embeddedLangCode').length > 0) {420 var idioma = $('input#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:embeddedLangCode').val();421 if(idioma !== "undefined" && idioma !== undefined && idioma != "") {422 result[3] = idioma;423 }424 }425 426 return result;427 };428 429 /**430 * Variables personalizadas para cuando el usuario hace click en Bulk Download431 */432 var getVariablesPaginaBulkDownload = function() {433 var result = {};434 435 var programTitle = getProgramTitle();436 if(programTitle != "") {437 result[1] = programTitle;438 }439 440 return result;441 }442 443 /**444 * Devuelve el ID del usuario en sessión si no estamos en la página de login y si no se ha enviado previamente445 * ya a AT-Internet (expira en 1hora, entonces se deberÃa volver a enviar).446 */447 var getUserId = function() {448 if(typeof(Storage) !== "undefined" && localStorage.user_id !== undefined && localStorage.user_id != "") {449 return false;450 } else {451 if(!current_url.login) {452 if((typeof user_id !== "undefined") && (typeof user_id !== undefined)) {453 localStorage.user_id = user_id;454 return user_id;455 }456 }457 }458 459 return false;460 };461 462 /**463 * Dependiendo de la página que se esté visualizando se envian unos datos u otros 464 * a la herramienta de AnalÃtica Web de AT-Internet.465 */466 var tagThisPage = (function() {467 // Iniciamos el objeto y el envÃo de datos al proveedor de AnalÃtica web.468 current_url = initURLObject.getInstance();469 var tag = initATInternetTag.getInstance();470 471 var pageData = {};472 var customVars = {};473 var tagsData = {};474 var id_usuario = getUserId();475 476 if(current_url.home) {477 pageData = {name: 'homepage', chapter1: 'download', level2: level2}478 customVars = {site: getVariablesSitioPersonalizadas()};479 480 tag.page.set(pageData);481 tag.customVars.set(customVars);482 if(id_usuario !== false) {483 tag.identifiedVisitor.set({id: id_usuario});484 }485 tag.dispatch();486 487 debugData({action : 'Tagging Homepage', pageData : pageData, customVars : customVars});488 } else if(current_url.login) {489 pageData = {name: 'login', chapter1: 'download', level2: level2};490 customVars = {site: getVariablesSitioPersonalizadas()};491 492 tag.page.set(pageData);493 tag.customVars.set(customVars);494 tag.dispatch();495 496 debugData({action : 'Tagging Login page', pageData : pageData, customVars : customVars});497 } else if(current_url.video) {498 var programTitle = getProgramTitle();499 500 if(programTitle != "") {501 pageData = {name: 'download', chapter1: 'download', chapter2 : 'programme_details', chapter3 : programTitle, level2: level2};502 customVars = {site: getVariablesSitioPersonalizadas()};503 504 tag.page.set(pageData);505 tag.customVars.set(customVars);506 if(id_usuario !== false) {507 tag.identifiedVisitor.set({id: id_usuario});508 }509 510 // Segun el plan de marcaje hay que enviar los tags relacionados de las página de producto.511 if($('#tags-list').length > 0) {512 var lista_de_tags = $('#tags-list').attr('data-tags');513 if(lista_de_tags !== undefined && lista_de_tags !== "undefined") {514 var lista_de_tags_split = lista_de_tags.split('|');515 if(lista_de_tags_split.length > 0) {516 tagsData = {keywords: lista_de_tags_split};517 tag.tags.set(tagsData);518 }519 }520 }521 tag.dispatch();522 523 var data = {action : 'Tagging Product page', pageData : pageData, customVars : customVars};524 if(!$.isEmptyObject(tagsData)) {525 data.tags = tagsData;526 }527 debugData(data);528 }529 }530 531 initURLObject.setCurrentPageData();532 })();533 534 /**535 * Al clicar sobre el botón descargar solo subtitulos o de descarga de un video, 536 * notificamos a la herramienta de analitica los detalles de la descarga.537 */538 var sendDownloadOKPageEvent = function(self) {539 pageData = {name: "download_OK", chapter1: 'download', chapter2 : 'programme_details', level2: level2};540 541 var downloadType = 'original';542 if(self) {543 if($(self).hasClass('ati-download-translated') && typeof $(self).hasClass('ati-download-translated') !== "undefined") {544 downloadType = 'translated';545 }546 if($(self).hasClass('ati-download-original') && typeof $(self).hasClass('ati-download-original') !== "undefined") {547 downloadType = 'original';548 }549 if($(self).hasClass('ati-download-subtitles') && typeof $(self).hasClass('ati-download-subtitles') !== "undefined") {550 downloadType = 'subtitles';551 }552 }553 customVars = {554 site : getVariablesSitioPersonalizadas(),555 page : getVariablesPaginaDownload(downloadType)556 };557 558 var tag = initATInternetTag.getInstance();559 tag.page.set(pageData);560 tag.customVars.set(customVars);561 562 var id_usuario = getUserId();563 if(id_usuario !== false) {564 tag.identifiedVisitor.set({id: id_usuario});565 }566 567 // Segun el plan de marcaje hay que enviar los tags relacionados de las página de producto.568 if($('#tags-list').length > 0) {569 var lista_de_tags = $('#tags-list').attr('data-tags');570 if(lista_de_tags !== undefined && lista_de_tags !== "undefined") {571 var lista_de_tags_split = lista_de_tags.split('|');572 if(lista_de_tags_split.length > 0) {573 tagsData = {keywords: lista_de_tags_split};574 tag.tags.set(tagsData);575 576 debugData({action : 'Tagging Download OK page', pageData : pageData, customVars : customVars, tagsData : tagsData});577 }578 } else {579 debugData({action : 'Tagging Download OK page', pageData : pageData, customVars : customVars}); 580 }581 } else {582 debugData({action : 'Tagging Download OK page', pageData : pageData, customVars : customVars});583 }584 585 tag.dispatch();586 };587 588 /**589 * Al clickar en el botón de Request, notificamos a la herramienta de analitica los detalles seleccionados por el usuario.590 */591 var sendRequestOKPageEvent = function() {592 pageData = {name: "request_OK", chapter1: 'download', chapter2 : 'programme_details', level2: level2};593 customVars = {594 site : getVariablesSitioPersonalizadas(),595 page : getVariablesPaginaRequest()596 };597 598 var tag = initATInternetTag.getInstance();599 tag.page.set(pageData);600 tag.customVars.set(customVars);601 602 var id_usuario = getUserId();603 if(id_usuario !== false) {604 tag.identifiedVisitor.set({id: id_usuario});605 }606 607 // Segun el plan de marcaje hay que enviar los tags relacionados de las página de producto.608 if($('#tags-list').length > 0) {609 var lista_de_tags = $('#tags-list').attr('data-tags');610 if(lista_de_tags !== undefined && lista_de_tags !== "undefined") {611 var lista_de_tags_split = lista_de_tags.split('|');612 if(lista_de_tags_split.length > 0) {613 tagsData = {keywords: lista_de_tags_split};614 tag.tags.set(tagsData);615 616 debugData({action : 'Tagging Request OK page', pageData : pageData, customVars : customVars, tagsData : tagsData});617 }618 } else {619 debugData({action : 'Tagging Request OK page', pageData : pageData, customVars : customVars});620 }621 } else {622 debugData({action : 'Tagging Request OK page', pageData : pageData, customVars : customVars});623 }624 625 tag.dispatch();626 };627 628 /**629 * Al clickar en el botón de Request del Tab Bulk Download, notificamos a la herramienta de analitica los detalles seleccionados por el usuario.630 */631 var sendRequestOKBulkDownloadPageEvent = function() {632 pageData = {name: "bulk_download_OK", chapter1: 'download', chapter2 : 'programme_details', level2: level2};633 customVars = {634 site : getVariablesSitioPersonalizadas(),635 page : getVariablesPaginaBulkDownload()636 };637 638 var tag = initATInternetTag.getInstance();639 tag.page.set(pageData);640 tag.customVars.set(customVars);641 642 var id_usuario = getUserId();643 if(id_usuario !== false) {644 tag.identifiedVisitor.set({id: id_usuario});645 }646 647 // Segun el plan de marcaje hay que enviar los tags relacionados de las página de producto.648 if($('#tags-list').length > 0) {649 var lista_de_tags = $('#tags-list').attr('data-tags');650 if(lista_de_tags !== undefined && lista_de_tags !== "undefined") {651 var lista_de_tags_split = lista_de_tags.split('|');652 if(lista_de_tags_split.length > 0) {653 tagsData = {keywords: lista_de_tags_split};654 tag.tags.set(tagsData);655 656 debugData({action : 'Tagging Request Bulk Donwload OK page', pageData : pageData, customVars : customVars, tagsData : tagsData});657 }658 } else {659 debugData({action : 'Tagging Request Bulk Donwload OK page', pageData : pageData, customVars : customVars});660 }661 } else {662 debugData({action : 'Tagging Request Bulk Donwload OK page', pageData : pageData, customVars : customVars});663 }664 665 tag.dispatch();666 };667 668 /**669 * Al clickar en el botón de Copy Embed, notificamos a la herramienta de analitica los detalles seleccionados por el usuario.670 */671 var sendEmbedOKPageEvent = function() {672 pageData = {name: "embed_OK", chapter1: 'download', chapter2 : 'programme_details', level2: level2};673 customVars = {674 site : getVariablesSitioPersonalizadas(),675 page : getVariablesPaginaEmbed()676 };677 678 var tag = initATInternetTag.getInstance();679 tag.page.set(pageData);680 tag.customVars.set(customVars);681 682 var id_usuario = getUserId();683 if(id_usuario !== false) {684 tag.identifiedVisitor.set({id: id_usuario});685 }686 687 // Segun el plan de marcaje hay que enviar los tags relacionados de las página de producto.688 if($('#tags-list').length > 0) {689 var lista_de_tags = $('#tags-list').attr('data-tags');690 if(lista_de_tags !== undefined && lista_de_tags !== "undefined") {691 var lista_de_tags_split = lista_de_tags.split('|');692 if(lista_de_tags_split.length > 0) {693 tagsData = {keywords: lista_de_tags_split};694 tag.tags.set(tagsData);695 696 debugData({action : 'Tagging Embed OK page', pageData : pageData, customVars : customVars, tagsData : tagsData});697 }698 } else {699 debugData({action : 'Tagging Embed OK page', pageData : pageData, customVars : customVars});700 }701 } else {702 debugData({action : 'Tagging Embed OK page', pageData : pageData, customVars : customVars});703 }704 tag.dispatch();705 };706 707 /**708 * EnvÃa un evento de click a la herramienta de AT-Internet segun los datos recibidos por parámetro709 */710 var sendClickEvent = function(data) {711 var clickData = {712 elem: data.elem,713 name: data.name,714 level2: level2,715 type: data.type716 };717 718 if(typeof data.chapter1 !== "undefined" && data.chapter1 != "") {719 clickData.chapter1 = data.chapter1;720 }721 if(typeof data.chapter2 !== "undefined" && data.chapter2 != "") {722 clickData.chapter2 = data.chapter2;723 }724 if(typeof data.chapter3 !== "undefined" && data.chapter3 != "") {725 clickData.chapter3 = data.chapter3;726 }727 728 var tag = initATInternetTag.getInstance();729 tag.clickListener.send(clickData);730 731 debugData({action : data.action, clickData : clickData});732 };733 734 /**735 * Al cerrar la ventana/navegador, vaciamos el local storage si hace más de una hora que se guardó..736 * En local storage guardamos datos referentes al chapter1 y pagename de la página anterior que visitó el usuario.737 * @FIXME Importante hacer uso de navegadores modernos que soporten el uso de Local Storage.738 */ 739 $(window).unload(function() {740 if(typeof(Storage) !== "undefined") {741 if(typeof localStorage.current_time !== "undefined") {742 var timestamp = parseInt(localStorage.current_time, 10);743 if((Math.floor(Date.now() / 1000)) >= timestamp + 3600) {744 localStorage.removeItem("previous_chapter_download");745 localStorage.removeItem("previous_page_download");746 localStorage.removeItem("current_time_download");747 localStorage.removeItem("user_id");748 }749 }750 }751 });752 753 /**754 * BUSCADOR755 * 756 * Evento personalizado que envÃa de nuevo los datos de la home de deownload757 * cuando el usuario realiza una búsqueda.758 */ 759 $(document).on("click", "button#_downloadlist_WAR_europarltv_download_list_\\:j_idt6\\:j_idt34", function() {760 var pageData = {name: 'homepage', chapter1: 'download', level2: level2}761 var customVars = {762 site : getVariablesSitioPersonalizadas(),763 page : getVariablesPaginaBusqueda()764 };765 766 var tag = initATInternetTag.getInstance();767 tag.page.set(pageData);768 tag.customVars.set(customVars);769 tag.dispatch();770 771 debugData({action : 'Tagging Homepage - Search Request', pageData : pageData, customVars : customVars});772 });773 774 /**775 * Al cambiar de Tab en la página de producto enviamos eventos de página vista segun el 776 * plan de marcado. 777 */778 $(document).on("click", 'div.col-download ul.nav.nav-tabs li', function() {779 if($(this).hasClass('active')) {780 var programTitle = getProgramTitle();781 var tag = initATInternetTag.getInstance();782 if(programTitle != "") {783 var tab_link = $('a', this);784 if(tab_link !== "undefined") {785 if(tab_link.html() !== "undefined" && tab_link.html() != "") {786 var current_tab = tab_link.html().toLowerCase().replace(' ', '_');787 788 pageData = {name: current_tab, chapter1: 'download', chapter2 : 'programme_details', chapter3 : programTitle, level2: level2};789 customVars = {site: getVariablesSitioPersonalizadas()};790 791 tag.page.set(pageData);792 tag.customVars.set(customVars);793 794 var id_usuario = getUserId();795 if(id_usuario !== false) {796 tag.identifiedVisitor.set({id: id_usuario});797 }798 799 // Segun el plan de marcaje hay que enviar los tags relacionados de las página de producto.800 if($('#tags-list').length > 0) {801 var lista_de_tags = $('#tags-list').attr('data-tags');802 if(lista_de_tags !== undefined && lista_de_tags !== "undefined") {803 var lista_de_tags_split = lista_de_tags.split('|');804 if(lista_de_tags_split.length > 0) {805 tagsData = {keywords: lista_de_tags_split};806 tag.tags.set(tagsData);807 808 debugData({action : 'Tagging Product page', pageData : pageData, customVars : customVars, tagsData : tagsData});809 }810 } else {811 debugData({action : 'Tagging Product page', pageData : pageData, customVars : customVars});812 }813 } else {814 debugData({action : 'Tagging Product page', pageData : pageData, customVars : customVars});815 }816 817 tag.dispatch();818 }819 }820 }821 }822 });823 824 /**825 * Al clicar sobre el botón descargar solo subtitulos de un video notificamos a la herramienta de analitica 826 * los detalles de página vista y evento de click.827 */828 $(document).on("click", 'button.ati-download-subtitle', function() {829 sendDownloadOKPageEvent(this);830 831 var programTitle = getProgramTitle();832 if(programTitle != "") {833 if($('#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:downloadLangCode').length > 0) {834 var language = $('#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:downloadLangCode').val();835 sendClickEvent({elem: $(this).get(0), name: language, chapter1: 'download', chapter2 : programTitle, chapter3 : 'download_only_subtitles', type: 'download', action : '[Click] on Download Subtitles'});836 }837 }838 });839 840 /**841 * Al clicar sobre el enlace de descarga de un video notificamos a la herramienta de analitica 842 * los detalles de página vista y evento de click.843 */844 $(document).on("click", 'div#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:detailTabDownload a', function() {845 sendDownloadOKPageEvent(this);846 847 var programTitle = getProgramTitle();848 if(programTitle != "") {849 if($('select#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:selectLanguage_input').length > 0) {850 var fileName = $(this).parent().text().replace('Download', '').replace(/\s*$/,"");851 sendClickEvent({elem: $(this).get(0), name: fileName, chapter1: 'download', chapter2 : programTitle, chapter3 : 'download_file', type: 'download', action : '[Click] on Download File'});852 }853 }854 });855 856 /**857 * Al clicar en el botón de Request, notificamos a la herramienta de analitica los detalles seleccionados por el usuario.858 */859 $(document).on("click", "button.ati-request-video[disabled!='disabled']", function() {860 sendRequestOKPageEvent();861 862 var programTitle = getProgramTitle();863 if(programTitle != "") {864 sendClickEvent({elem: $(this).get(0), name: 'request', chapter1: 'download', chapter2 : programTitle, type: 'download', action : '[Click] on Request'});865 }866 });867 868 /**869 * Al clicar en el botón de Request, de Bulk download notificamos a la herramienta de analitica los detalles seleccionados por el usuario.870 */871 $(document).on("click", "button.ati-request-bulk[disabled!='disabled']", function() {872 sendRequestOKBulkDownloadPageEvent();873 });874 875 /**876 * Al clicar en el botón de copy embed, notificamos a la herramienta de analitica los detalles seleccionados por el usuario.877 */878 $(document).on("click", "span#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:embedLabelDetail input", function() {879 sendEmbedOKPageEvent();880 881 var programTitle = getProgramTitle();882 if(programTitle != "") {883 // Recuperamos el idoma seleccionado por el usuario...884 if($('select#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:selectLang_input').length > 0) {885 if($('#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:embeddedLangCode').length > 0) {886 var language = $('#_downloaddetail_WAR_europarltv_download_detail_\\:j_idt4\\:embeddedLangCode').val();887 var id = $(this).attr('id');888 889 if(id == "_downloaddetail_WAR_europarltv_download_detail_:j_idt4:j_idt174") {890 // Copy embed with subtitles891 sendClickEvent({elem: $(this).get(0), name: language, chapter1: 'download', chapter2 : programTitle, chapter3 : 'embed_subtitles', type: 'download', action : '[Click] on Copy Embed with subtitles'});892 } else if(id == "_downloaddetail_WAR_europarltv_download_detail_:j_idt4:j_idt180") {893 // Copy embed with voice over894 sendClickEvent({elem: $(this).get(0), name: language, chapter1: 'download', chapter2 : programTitle, chapter3 : 'embed_voice_over', type: 'download', action : '[Click] on Copy Embed with voice over'});895 }896 }897 }898 }899 });900 /**901 * CLICKS902 * Cuando se clica el link de Download Thumbnail, hay que enviar un evento de click a AT-INTERNET.903 */904 $(document).on("click", 'button.ati-download-thumb', function(e) {905 var programTitle = getProgramTitle();906 if(programTitle != "") {907 sendClickEvent({elem: $(this).get(0), name: 'download_thumbnail', chapter1: 'download', chapter2 : programTitle, type: 'download', action : '[Click] on Download Thumbnail'});908 }909 });910 911 /** 912 * JUST FOR DEBBUGING913 * Muestra los datos de la página actual y a las variables de página y chapter anterior914 * guardados en localStorage que se enviarán a la herramienta de analÃtica web. 915 */916 var var_dump = (function() {917 if(debugEnabled) {918 var current_url = initURLObject.getInstance();919 920 if($('pre#var_dump').length > 0) {921 var html = "<ol>";922 $.each(current_url, function(prop, val) {923 if(val == true) {924 html += "<li style=\"color:green; font-weight: bolder; font-size: 18px;\"><strong>" + prop + "</strong> : " + val + "</li>";925 } else {926 html += "<li><strong>" + prop + "</strong> : " + val + "</li>";927 }928 });929 html += "</ol>";930 $('pre#var_dump').html(html);931 }932 if($('span#pagename').length > 0) {933 $('span#pagename').html(current_url.url_path.slice(current_url.url_path.length - 1, current_url.url_path.length));934 }935 }936 })();...
FirstIntercept.js
Source:FirstIntercept.js
1import React, {useEffect, useState} from 'react';2import {3 Text,4 StyleSheet,5 Alert,6 View,7 KeyboardAvoidingView,8 Button,9} from 'react-native';10import {11 SafeAreaView,12 PrimaryButton,13 PrimaryButtonText,14 PrimaryTextInput,15} from '../controls/styles';16import CardView from '../controls/CardView';17import {connect} from 'react-redux';18import {updateAuth, updateVars} from '../redux/actions/authActions';19import Qualtrics from 'react-native-qualtrics';20import BottomHud from '../controls/BottomHud';21import {TouchableOpacity, ScrollView} from 'react-native-gesture-handler';22import QualtVar from '../controls/QualtVar';23import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome';24import WalkerLogoComponent from '../assets/Walker_Logo_JSX';25import QualtricsLogoComponent from '../assets/Qualtrics_logo_JSX';26function FirstIntercept({auth, setLogin, setCustomVars}) {27 const [interceptIDs, setInterceptIDs] = useState([]);28 const [customVars, setCVars] = useState(auth.custom_vars);29 useEffect(() => {30 console.log('intercept-auth:', auth);31 //console.log("custom_vars-int", custom_vars, customVars);32 if (auth.auth != null && typeof auth.auth.intercepts != 'undefined') {33 console.log('intercepts:', auth.auth.intercepts);34 let ret = [];35 for (const [key, value] of Object.entries(auth.auth.intercepts)) {36 console.log(`${key}: ${JSON.stringify(value)}`);37 ret.push(`${key}`);38 }39 setInterceptIDs(ret);40 } else {41 setInterceptIDs([]);42 }43 }, [auth.auth]);44 const resetCreds = () => {45 console.log('resettingCreds');46 setLogin(null);47 };48 async function testIntercept(intId) {49 console.log('intId:', intId);50 setQualtricsVariables();51 Qualtrics.evaluateIntercept(intId, async res => {52 console.log('evalRes:', res);53 if (res.passed) {54 console.log('result:', res);55 var inter = await Qualtrics.displayIntercept(intId);56 console.log('inter:', inter);57 } else {58 console.log('intercept failed...');59 Alert.alert(60 'Intercept Evaluated to FALSE\nNot displaying Intercept',61 JSON.stringify(res),62 [63 {text: 'Cancel', onPress: () => console.log('Cancel Pressed!')},64 {65 text: 'OK',66 onPress: () => {67 //setIsBusy(false);68 console.log('OK Pressed');69 },70 },71 ],72 {cancelable: false},73 );74 }75 });76 }77 const setQualtricsVariables = () => {78 for (let i = 0; i < customVars.length; i++) {79 let cVal = customVars[i].value;80 let nme = customVars[i].name;81 if (nme == '') {82 continue;83 }84 let v = parseInt(cVal);85 let isNum = cVal.match(/^[0-9]*$/) != null;86 console.log('isnum:', isNum);87 console.log('val:', cVal);88 console.log('v', v);89 if (!isNum) {90 Qualtrics.setString(nme, cVal);91 console.log('set strin:', cVal);92 } else {93 if (isNaN(v)) {94 Qualtrics.setNumber(nme, 0);95 console.log('set num:', 0);96 } else {97 Qualtrics.setNumber(nme, cVal);98 console.log('set num:', cVal);99 }100 }101 }102 };103 function newVariable() {104 let newvars = [...customVars];105 newvars.push({key: customVars.length, name: '', value: ''});106 setCVars(newvars);107 setCustomVars(newvars);108 }109 function removeVariable(k) {110 let cur = [];111 let kei = 0;112 for (var i = 0; i < customVars.length; i++) {113 if (customVars[i].key != k) {114 cur.push({...customVars[i], key: kei});115 kei++;116 }117 }118 //console.log(">>>>>>> ", cur)119 setCVars(cur);120 setCustomVars(cur);121 }122 function updateCvarName(k, n, v, o) {123 // where k is position in DOM, n is var new name, v is var value, and o is old value - to be removed124 let result = [];125 for (var i = 0; i < customVars.length; i++) {126 console.log('update cvar, name:', i, customVars[i].key, n, o);127 if (customVars[i].key == k) {128 let nObj = {129 key: customVars[i].key,130 name: n,131 value: customVars[i].value,132 };133 result.push(nObj);134 } else {135 console.log('passing on ', k, n, v, o);136 result.push(customVars[i]);137 }138 }139 console.log('after Name Change array:', result);140 setCVars(result);141 setCustomVars(result);142 }143 function updateCvarValue(k, n, v) {144 // where k is posision in dom, n is var name, and v is new value145 let accum = [];146 for (var i = 0; i < customVars.length; i++) {147 if (customVars[i].key == k) {148 accum.push({149 key: customVars[i].key,150 name: customVars[i].name,151 value: v,152 });153 } else {154 accum.push({155 key: customVars[i].key,156 name: customVars[i].name,157 value: customVars[i].value,158 });159 }160 }161 console.log('after value change:', accum);162 setCVars(accum);163 setCustomVars(accum);164 }165 return (166 <>167 <SafeAreaView style={{flex: 1, backgroundColor: '#417cca'}}>168 {/* <Text style={styles.header}>Intercepts</Text> */}169 <View170 style={{171 flexDirection: 'row',172 justifyContent: 'center',173 alignItems: 'center',174 marginBottom: 10,175 }}>176 <WalkerLogoComponent width="180" height="50" style={styles.Wlogo} />177 <Text178 style={{179 color: 'white',180 fontSize: 15,181 marginLeft: 20,182 fontFamily: my_font,183 }}>184 Digitial CX {'\n'}Mobile Demo185 </Text>186 </View>187 <KeyboardAvoidingView behavior="position">188 <View style={{backgroundColor: 'white', height: '100%'}}>189 <ScrollView style={{height: '100%'}}>190 <CardView style={styles.card}>191 {interceptIDs.length == 0 ? (192 <Text style={styles.interceptHeader}>193 No intercepts have been initilized.194 </Text>195 ) : (196 <Text style={styles.interceptHeader}>197 Available Intercepts198 </Text>199 )}200 {interceptIDs.map((val, idx) => {201 let my_title = val;202 return (203 <TouchableOpacity204 key={idx}205 onPress={() => {206 testIntercept(val);207 }}208 style={styles.intContainer}>209 {/* <Button210 title={my_title}211 style={styles.intButton}212 color="white"></Button> */}213 <Text style={styles.intButton}>{my_title}</Text>214 <FontAwesomeIcon215 icon="arrow-right"216 size={22}217 style={styles.interceptPlay}218 />219 </TouchableOpacity>220 );221 })}222 </CardView>223 <View224 style={{225 //borderWidth: 1,226 borderColor: '#e9ecef',227 //borderRadius: 10,228 justifyContent: 'space-between',229 padding: 10,230 }}>231 <View232 style={{233 backgroundColor: '#d3d3d3',234 marginHorizontal: -10,235 //borderRadius: 10,236 flexDirection: 'row',237 justifyContent: 'space-evenly',238 }}>239 <Text style={styles.interceptHeader}>240 Qualtrics Variables:241 </Text>242 <TouchableOpacity243 onPress={newVariable}244 style={styles.touchablePlusContainer}>245 <FontAwesomeIcon246 icon="plus-circle"247 size={30}248 style={styles.interceptPlus}249 />250 </TouchableOpacity>251 </View>252 <View style={{marginTop: 5, marginBottom: 50}}>253 {customVars.length > 0 ? (254 customVars.map((val, idx) => {255 console.log('creating variables:', idx);256 return (257 <QualtVar258 input={val}259 key={idx}260 font={my_font}261 changeValue={updateCvarValue}262 changeName={updateCvarName}263 removeVar={removeVariable}264 />265 );266 })267 ) : (268 <TouchableOpacity onPress={newVariable}>269 <Text270 style={{271 fontSize: 20,272 alignSelf: 'center',273 marginRight: 10,274 margin: 10,275 fontFamily: my_font,276 }}>277 No Custom Variables278 </Text>279 </TouchableOpacity>280 )}281 </View>282 </View>283 </ScrollView>284 </View>285 </KeyboardAvoidingView>286 </SafeAreaView>287 <CardView style={styles.footer}>288 <TouchableOpacity style={styles.resetButton} onPress={resetCreds}>289 <View style={styles.resetContainer}>290 <FontAwesomeIcon291 icon="arrow-circle-left"292 size={22}293 style={styles.interceptPlay}294 />295 <Text style={styles.resetButton}>Reset Project</Text>296 {/* <Button297 style={styles.resetButton}298 title="Reset Project"299 color="white"></Button> */}300 </View>301 </TouchableOpacity>302 {/*<Button title="RESET" onPress={resetCreds} style={styles.resetButton} />303 <BottomHud resetCreds={resetCreds} />304 <TouchableOpacity305 style={styles.helpContainer}306 onPress={() => {307 console.log('works');308 }}>309 <FontAwesomeIcon310 style={{color: '#417cca'}}311 icon="question-circle"312 size={20}></FontAwesomeIcon>313 <Text style={styles.helpText}>Help</Text>314 </TouchableOpacity> 315 <QualtricsLogoComponent style={styles.Qlogo} height="80" width="150" />316 */}317 </CardView>318 </>319 );320}321const my_font = 'HelveticaNeue';322const styles = StyleSheet.create({323 header: {324 alignSelf: 'center',325 fontSize: 30,326 marginVertical: 12,327 },328 intContainer: {329 backgroundColor: '#f7971e',330 alignItems: 'center',331 justifyContent: 'space-around',332 flexDirection: 'row',333 color: 'white',334 borderRadius: 10,335 marginVertical: 10,336 height: 45,337 },338 resetContainer: {339 backgroundColor: '#6a737c',340 alignItems: 'center',341 //justifyContent: 'center',342 flexDirection: 'row',343 color: 'white',344 borderRadius: 10,345 marginVertical: 10,346 paddingHorizontal: 20,347 height: 45,348 },349 interceptHeader: {350 fontSize: 22,351 margin: 10,352 alignSelf: 'center',353 fontFamily: my_font,354 },355 interceptPlus: {356 fontSize: 29,357 marginLeft: 20,358 alignSelf: 'center',359 marginBottom: 9,360 fontFamily: my_font,361 //color: 'blue',362 },363 interceptPlay: {364 marginRight: 8,365 color: 'white',366 paddingTop: 3,367 },368 touchablePlusContainer: {369 alignContent: 'center',370 //color: 'red',371 marginTop: 13,372 },373 card: {374 margin: 5,375 },376 intButton: {377 marginVertical: 5,378 fontFamily: my_font,379 color: 'white',380 fontSize: 18,381 },382 idText: {383 fontSize: 15,384 fontStyle: 'italic',385 fontFamily: my_font,386 },387 currLocText: {388 fontSize: 21,389 fontFamily: my_font,390 },391 inputLabel: {392 marginLeft: 12,393 fontSize: 11,394 marginBottom: 10,395 fontFamily: my_font,396 },397 resetButton: {398 //justifyContent: 'center',399 alignSelf: 'center',400 marginVertical: 5,401 fontSize: 17,402 //marginTop: -10,403 fontFamily: my_font,404 color: 'white',405 },406 footer: {407 position: 'absolute',408 bottom: 0,409 alignSelf: 'center',410 alignContent: 'center',411 backgroundColor: 'white',412 },413});414const mapStateToProps = ({auth, custom_vars}) => ({415 auth,416 custom_vars,417});418const mapDispatchToProps = dispatch => ({419 setLogin: data => dispatch(updateAuth(data)),420 setCustomVars: data => dispatch(updateVars(data)),421});...
Using AI Code Generation
1import { withCustomVars } from "storybook-root-decorator";2import { withKnobs } from "@storybook/addon-knobs";3export default {4};5export const MyComponent = () => <MyComponent />;6import { withCustomVars } from "storybook-root-decorator";7export const decorators = [withCustomVars];8import { withCustomVars } from "storybook-root-decorator";9export const parameters = {10};11import { withCustomVars } from "storybook-root-decorator";12export const decorators = [withKnobs, withCustomVars];13import { withCustomVars } from "storybook-root-decorator";14export const parameters = {15};16import { withCustomVars } from "storybook-root-decorator";17export const decorators = [withCustomVars, withKnobs];18import { withCustomVars } from "storybook-root-decorator";19export const parameters = {20};21import { withCustomVars } from "storybook-root-decorator";22export const decorators = [withCustomVars];23import { withCustomVars } from "storybook-root-decorator";24export const parameters = {25};26import { withCustomVars } from "storybook-root-decorator";27export const decorators = [withCustomVars];28import { withCustomVars } from "storybook-root-decorator";29export const parameters = {30};31import { withCustomVars } from "storybook-root-decorator";32export const decorators = [withCustomVars];33import { withCustomVars } from "storybook-root-decorator";34export const parameters = {35};
Using AI Code Generation
1import { customVars } from 'storybook-root-decorator';2import { customVars } from 'storybook-root-decorator';3import { customVars } from 'storybook-root-decorator';4import { customVars } from 'storybook-root-decorator';5import { customVars } from 'storybook-root-decorator';6import { customVars } from 'storybook-root-decorator';7import { customVars } from 'storybook-root-decorator';8import { customVars } from 'storybook-root-decorator';9import { customVars } from 'storybook-root-decorator';10import { customVars } from 'storybook-root-decorator';11import { customVars } from 'storybook-root-decorator';12import { customVars } from 'storybook-root-decorator';13import { customVars } from 'storybook-root-decorator';14import { customVars } from 'storybook-root-decorator';15import { customVars } from
Using AI Code Generation
1import { customVars } from 'storybook-root';2customVars();3export const customVars = () => {4 console.log('customVars');5};6export const customVars = () => {7 console.log('customVars');8};9import myFile from 'myFile';10import myFile from 'storybook-root/myFile';11import myFile from 'myFile';12import myFile from 'storybook-root/myFile';13import myFile from 'myFile';14import myFile from 'storybook-root/myFile';
Using AI Code Generation
1import { customVars } from 'storybook-root-decorator';2const myCustomVars = customVars({3});4export const MyComponent = () => {5 return <div style={{ '--myCustomVar': 'red' }}>MyComponent</div>;6};7MyComponent.story = {8};9import { addDecorator } from '@storybook/react';10import { withRootDecorator } from 'storybook-root-decorator';11addDecorator(withRootDecorator);12import { addDecorator } from '@storybook/react';13import { withRootDecorator } from 'storybook-root-decorator';14addDecorator(withRootDecorator);
Using AI Code Generation
1import { customVars } from 'storybook-root';2const test = () => {3 const testVar = customVars.testVar;4 console.log(testVar);5}6export default test;7import { customVars } from 'storybook-root';8export const parameters = {9 actions: { argTypesRegex: "^on[A-Z].*" },10 controls: {11 matchers: {12 color: /(background|color)$/i,13 },14 },15};16customVars.testVar = 'test value';17import { customVars } from 'storybook-root';18export const parameters = {19 actions: { argTypesRegex: "^on[A-Z].*" },20 controls: {21 matchers: {22 color: /(background|color)$/i,23 },24 },25};26customVars.testVar = 'test value';27import { customVars } from 'storybook-root';28export const parameters = {29 actions: { argTypesRegex: "^on[A-Z].*" },30 controls: {31 matchers: {32 color: /(background|color)$/i,33 },34 },35};36customVars.testVar = 'test value';37import { customVars } from 'storybook-root';38export const parameters = {39 actions: { argTypesRegex: "^on[A-Z].*" },40 controls: {41 matchers: {42 color: /(background|color)$/i,43 },44 },45};46customVars.testVar = 'test value';47import { customVars } from 'storybook-root';48export const parameters = {49 actions: { argTypesRegex: "^on[A-Z].*" },50 controls: {51 matchers: {52 color: /(background|color)$/i,53 },54 },55};
Using AI Code Generation
1import { customVars } from 'storybook-root'2customVars('test')3module.exports = {4 stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],5}6import { customVars } from 'storybook-root'7export const parameters = {8 actions: { argTypesRegex: '^on[A-Z].*' },9}10import { customVars } from 'storybook-root'11export const parameters = {12 actions: { argTypesRegex: '^on[A-Z].*' },13}14import { customVars } from 'storybook-root'15export const parameters = {16 actions: { argTypesRegex: '^on[A-Z].*' },17}18import { customVars } from 'storybook-root'19export const parameters = {20 actions: { argTypesRegex: '^on[A-Z].*' },21}22import { customVars } from 'storybook-root'23export const parameters = {24 actions: { argTypesRegex: '^on[A-Z].*' },25}26import { customVars } from 'storybook-root'27export const parameters = {28 actions: { argTypesRegex: '^on[A-Z].*' },29}30import { customVars } from 'storybook-root'31export const parameters = {32 actions: { argTypesRegex: '^on[A-Z].*' },33}34import { customVars } from 'storybook-root'35export const parameters = {36 actions: { argTypesRegex: '^on[A-Z].*' },37}38import { customVars } from 'storybook-root'39export const parameters = {40 actions: { argTypesRegex: '^on[A-Z].*' },41}42import { customVars } from 'storybook-root'43export const parameters = {44 actions: { argTypesRegex: '^on[A-Z].*' },45}
Using AI Code Generation
1import { customVars } from 'storybook-root';2import story from './story';3const customVariables = customVars(story);4const { color } = customVariables;5export default {6 customVariables: {7 },8};9import { customVars } from 'storybook-root';10import story from './story';11const customVariables = customVars(story);12const { color } = customVariables;13export default {14 customVariables: {15 },16};17import { customVars } from 'storybook-root';18import story from './story';19const customVariables = customVars(story);20const { color } = customVariables;21export default {22 customVariables: {23 },24};25import { customVars } from 'storybook-root';26import story from './story';27const customVariables = customVars(story);28const { color } = customVariables;29export default {30 customVariables: {31 },32};33import { customVars } from 'storybook-root';34import story from './story';35const customVariables = customVars(st
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!