refactor time convert funcs
This commit is contained in:
parent
93f3c1d59c
commit
98c03b5a64
|
@ -16,7 +16,7 @@ const logger = createLogger({
|
|||
myFormat
|
||||
),
|
||||
transports: [
|
||||
//new (winston.transports.Console)(),
|
||||
new (winston.transports.Console)(),
|
||||
new (winston.transports.File)({filename: tempOutputFile})
|
||||
]
|
||||
});
|
||||
|
|
|
@ -14,6 +14,7 @@ const Utils = require('../utils/Utils.js').Utils;
|
|||
const Crowdsale = require('../entity/Crowdsale.js').Crowdsale;
|
||||
const Page = require('../pages/Page.js').Page;
|
||||
const fs = require('fs');
|
||||
const TIME_FORMAT = require('../utils/constants.js').TIME_FORMAT;
|
||||
|
||||
class User {
|
||||
constructor(driver, file) {
|
||||
|
@ -194,8 +195,8 @@ class User {
|
|||
|
||||
async changeEndTimeFromManagePage(tier, newDate, newTime) {
|
||||
logger.info("changeEndTimeFromManagePage for tier#" + tier + ", new date=" + newDate + ", new time=" + newTime);
|
||||
let formatTimeBrowser = await Utils.getDateFormat(this.driver);
|
||||
if ( formatTimeBrowser === "mdy" ) {
|
||||
let formatTimeBrowser = await Utils.getDateFormat(this.driver);
|
||||
if ( formatTimeBrowser === TIME_FORMAT.MDY ) {
|
||||
newDate = Utils.convertDateToMdy(newDate);
|
||||
newTime = Utils.convertTimeToMdy(newTime);
|
||||
}
|
||||
|
@ -228,7 +229,7 @@ class User {
|
|||
async changeStartTime(tier, newDate, newTime) {
|
||||
logger.info("change StartTime for tier#" + tier + ", new date=" + newDate + ", new time=" + newTime);
|
||||
let formatTimeBrowser = await Utils.getDateFormat(this.driver);
|
||||
if ( formatTimeBrowser == "mdy" ) {
|
||||
if ( formatTimeBrowser === TIME_FORMAT.MDY ) {
|
||||
newDate = Utils.convertDateToMdy(newDate);
|
||||
newTime = Utils.convertTimeToMdy(newTime);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
"e2eMinted": "mocha ./test/e2eMinted.js",
|
||||
"e2eMintedUI": "mocha ./test/e2eMintedUI.js",
|
||||
"e2eMintedWhitelist": "mocha ./test/e2eMintedWhitelist.js",
|
||||
"e2eMintedMincap": "mocha ./test/e2eMintedMincap.js",
|
||||
"e2eMintedMincap": "mocha -b ./test/e2eMintedMincap.js",
|
||||
"e2eDutch": "mocha ./test/e2eDutch.js",
|
||||
"e2eDutchUI": "mocha ./test/e2eDutchUI.js",
|
||||
"e2eDutchWhitelist": "mocha ./test/e2eDutchWhitelist.js",
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
const logger = require('../entity/Logger.js').logger;
|
||||
const Page = require('./Page.js').Page;
|
||||
const By = require('selenium-webdriver/lib/by').By;
|
||||
const statusTimer = require('../utils/constants.js').statusTimer;
|
||||
|
||||
const buttonContribute = By.className("button button_fill");
|
||||
const fieldContribute = By.id("contribute");
|
||||
const buttonOk = By.className("swal2-confirm swal2-styled");
|
||||
|
@ -13,16 +15,6 @@ const countdownTimerValue = By.className("timer-count");
|
|||
const countdownTimerStatus = By.className("timer-interval");
|
||||
const fieldsHashTitles = By.className("hashes-title");
|
||||
|
||||
const statusTimer = {
|
||||
start: "START",
|
||||
end: "CROWDSALE HAS ENDED",
|
||||
finalized: "HAS BEEN FINALIZED",
|
||||
tier1: "END OF TIER 1",
|
||||
tier2: "END OF TIER 2",
|
||||
tier3: "END OF TIER 3",
|
||||
|
||||
}
|
||||
|
||||
class ContributionPage extends Page {
|
||||
|
||||
constructor(driver) {
|
||||
|
@ -38,15 +30,10 @@ class ContributionPage extends Page {
|
|||
async getStatusTimer() {
|
||||
logger.info(this.name + "getTimerStatus ");
|
||||
try {
|
||||
let counter = 10;
|
||||
do {
|
||||
await this.driver.sleep(1000);
|
||||
}
|
||||
while ((counter-- > 0) && (await this.isCrowdsaleTimeOver()))
|
||||
|
||||
let array = await this.initTimerFields();
|
||||
let result = await super.getTextForElement(array[array.length - 1]);
|
||||
logger.info("timer status: " + result);
|
||||
if (! await this.waitUntilShowUpTimerStatus(120)) return false;
|
||||
const array = await this.initTimerFields();
|
||||
const result = await super.getTextForElement(array[array.length - 1]);
|
||||
console.log("timer status: " + result);
|
||||
if (result.includes(statusTimer.start)) return statusTimer.start;
|
||||
else if (result.includes(statusTimer.tier1)) return statusTimer.tier1;
|
||||
else if (result.includes(statusTimer.tier2)) return statusTimer.tier2;
|
||||
|
@ -165,6 +152,11 @@ class ContributionPage extends Page {
|
|||
return (await super.waitUntilDisplayed(countdownTimer,Twaiting));
|
||||
}
|
||||
|
||||
async waitUntilShowUpTimerStatus(Twaiting) {
|
||||
logger.info(this.name + "waitUntilShowUpTimerStatus ");
|
||||
return (await super.waitUntilDisplayed(countdownTimerStatus,Twaiting));
|
||||
}
|
||||
|
||||
async clickButtonOK() {
|
||||
logger.info(this.name + "clickButtonOK ");
|
||||
return await super.clickWithWait(buttonOk);
|
||||
|
|
|
@ -206,6 +206,7 @@ class Page {
|
|||
let field = await this.getElement(element, Twaiting);
|
||||
if (field === null) return false;
|
||||
await field.sendKeys(k);
|
||||
console.log(k)
|
||||
return true;
|
||||
}
|
||||
catch (err) {
|
||||
|
|
|
@ -13,7 +13,7 @@ const buttonYesAlert = By.className("swal2-confirm swal2-styled");
|
|||
const fieldMinRate = By.id("tiers[0].minRate");
|
||||
const fieldMaxRate = By.id("tiers[0].maxRate");
|
||||
const contentContainer = By.className("steps-content container");
|
||||
|
||||
const TIME_FORMAT = require('../utils/constants.js').TIME_FORMAT;
|
||||
let COUNT_TIERS = 0;
|
||||
const timeAdjust = 0;//relative value for tier time
|
||||
|
||||
|
@ -131,17 +131,22 @@ class TierPage extends Page {
|
|||
let locator = await this.getFieldStartTime();
|
||||
let format = await Utils.getDateFormat(this.driver);
|
||||
if (!this.tier.startDate.includes("/")) {
|
||||
this.tier.startTime = Utils.getTimeWithAdjust(timeAdjust + parseInt(this.tier.startTime), "utc");
|
||||
this.tier.startDate = Utils.getDateWithAdjust(timeAdjust + parseInt(this.tier.startDate), "utc");
|
||||
this.tier.startTime = Utils.getTimeWithAdjust(timeAdjust + parseInt(this.tier.startTime), format);
|
||||
this.tier.startDate = Utils.getDateWithAdjust(timeAdjust + parseInt(this.tier.startDate), format);
|
||||
}
|
||||
if (format === "mdy") {
|
||||
this.tier.startDate = Utils.convertDateToMdy(this.tier.startDate);
|
||||
this.tier.startTime = Utils.convertTimeToMdy(this.tier.startTime);
|
||||
}
|
||||
return await super.clickWithWait(locator) &&
|
||||
await super.fillWithWait(locator, this.tier.startDate) &&
|
||||
await super.pressKey(key.TAB, 1) &&
|
||||
await super.fillWithWait(locator, this.tier.startTime);
|
||||
|
||||
console.log("format= "+format)
|
||||
console.log("this.tier.startDate= "+this.tier.startDate)
|
||||
console.log("this.tier.startTime= "+this.tier.startTime)
|
||||
|
||||
|
||||
|
||||
return await super.clickWithWait(locator)
|
||||
&& await super.fillWithWait(locator, this.tier.startDate)
|
||||
&& await super.pressKey(key.TAB, 1)
|
||||
&& await super.fillWithWait(locator, this.tier.startTime)
|
||||
//&& await super.fillWithWait(locator, '2:34am')
|
||||
|
||||
}
|
||||
|
||||
async getFieldEndTime() {
|
||||
|
@ -156,13 +161,10 @@ class TierPage extends Page {
|
|||
let locator = await this.getFieldEndTime();
|
||||
let format = await Utils.getDateFormat(this.driver);
|
||||
if (!this.tier.endDate.includes("/")) {
|
||||
this.tier.endTime = Utils.getTimeWithAdjust(timeAdjust + parseInt(this.tier.endDate), "utc");
|
||||
this.tier.endDate = Utils.getDateWithAdjust(timeAdjust + parseInt(this.tier.endDate), "utc");
|
||||
}
|
||||
if (format === "mdy") {
|
||||
this.tier.endDate = Utils.convertDateToMdy(this.tier.endDate);
|
||||
this.tier.endTime = Utils.convertTimeToMdy(this.tier.endTime);
|
||||
this.tier.endTime = Utils.getTimeWithAdjust(timeAdjust + parseInt(this.tier.endDate), format);
|
||||
this.tier.endDate = Utils.getDateWithAdjust(timeAdjust + parseInt(this.tier.endDate), format);
|
||||
}
|
||||
|
||||
return await super.clickWithWait(locator) &&
|
||||
await super.fillWithWait(locator, this.tier.endDate) &&
|
||||
await super.pressKey(key.TAB, 1) &&
|
||||
|
|
|
@ -18,6 +18,7 @@ const Utils = require('../utils/Utils.js').Utils;
|
|||
const User = require("../entity/User.js").User;
|
||||
const adjEndTimeTier2 = 540000;
|
||||
const adjEndTimeTier3 = 240000;
|
||||
const TIME_FORMAT = require('../utils/constants.js').TIME_FORMAT;
|
||||
|
||||
test.describe(`e2e test for TokenWizard2.0/MintedCappedCrowdsale. v ${testVersion} `, async function () {
|
||||
this.timeout(2400000);//40 min
|
||||
|
@ -57,6 +58,7 @@ test.describe(`e2e test for TokenWizard2.0/MintedCappedCrowdsale. v ${testVersio
|
|||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
test.before(async function () {
|
||||
|
||||
await Utils.copyEnvFromWizard();
|
||||
const scenarioE2eMintedMinCap = './scenarios/scenarioE2eMintedMinCap.json';
|
||||
e2eMinCap = await Utils.getMintedCrowdsaleInstance(scenarioE2eMintedMinCap);
|
||||
|
@ -158,8 +160,9 @@ test.describe(`e2e test for TokenWizard2.0/MintedCappedCrowdsale. v ${testVersio
|
|||
assert.equal(await owner.setWalletAccount(), true, "Can not set Metamask account");
|
||||
assert.equal(await owner.openManagePage(e2eMinCap), true, 'Owner can not open manage page');
|
||||
let adjust = 80000000;
|
||||
let newTime = Utils.getTimeWithAdjust(adjust, "utc");
|
||||
let newDate = Utils.getDateWithAdjust(adjust, "utc");
|
||||
let format = TIME_FORMAT.UTC;
|
||||
let newTime = Utils.getTimeWithAdjust(adjust, format);
|
||||
let newDate = Utils.getDateWithAdjust(adjust, format);
|
||||
let tierNumber = 1;
|
||||
let result = await owner.changeEndTimeFromManagePage(tierNumber, newDate, newTime);
|
||||
return await assert.equal(result, false, 'Test FAILED.Owner can modify the end time of tier#1 if crowdsale not modifiable ');
|
||||
|
@ -303,7 +306,7 @@ test.describe(`e2e test for TokenWizard2.0/MintedCappedCrowdsale. v ${testVersio
|
|||
let owner = Owner;
|
||||
assert.equal(await owner.openManagePage(e2eMinCap), true, 'Owner can not open manage page');
|
||||
let tierNumber = 2;
|
||||
let format = "utc";
|
||||
let format = TIME_FORMAT.UTC;
|
||||
endTime = Utils.getTimeWithAdjust(adjEndTimeTier2, format);
|
||||
endDate = Utils.getDateWithAdjust(adjEndTimeTier2, format);
|
||||
let result = await owner.changeEndTimeFromManagePage(tierNumber, endDate, endTime);
|
||||
|
@ -482,7 +485,7 @@ test.describe(`e2e test for TokenWizard2.0/MintedCappedCrowdsale. v ${testVersio
|
|||
assert.equal(await owner.setWalletAccount(), true, "Can not set Metamask account");
|
||||
assert.equal(await owner.openManagePage(e2eMinCap), true, 'Owner can not open manage page');
|
||||
let tierNumber = 3;
|
||||
let format = "utc";
|
||||
let format = TIME_FORMAT.UTC;
|
||||
endTime = Utils.getTimeWithAdjust(adjEndTimeTier3, format);
|
||||
endDate = Utils.getDateWithAdjust(adjEndTimeTier3, format);
|
||||
let result = await owner.changeEndTimeFromManagePage(tierNumber, endDate, endTime);
|
||||
|
|
1549
utils/Utils.js
1549
utils/Utils.js
File diff suppressed because it is too large
Load Diff
|
@ -2,7 +2,22 @@ const WALLET = {
|
|||
METAMASK: 'METAMASK',
|
||||
NIFTY: 'NIFTY'
|
||||
}
|
||||
const statusTimer = {
|
||||
start: "START",
|
||||
end: "CROWDSALE HAS ENDED",
|
||||
finalized: "HAS BEEN FINALIZED",
|
||||
tier1: "END OF TIER 1",
|
||||
tier2: "END OF TIER 2",
|
||||
tier3: "END OF TIER 3",
|
||||
}
|
||||
const TIME_FORMAT = {
|
||||
MDY: "mdy",
|
||||
UTC: "utc"
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
WALLET: WALLET
|
||||
WALLET: WALLET,
|
||||
statusTimer:statusTimer,
|
||||
TIME_FORMAT:TIME_FORMAT
|
||||
}
|
||||
global.testVersion='2.10.2'
|
Loading…
Reference in New Issue