From 1608884b091abc537ac5d046751fd6fd0588a58b Mon Sep 17 00:00:00 2001 From: filip mertens Date: Wed, 13 Jul 2022 11:59:22 +0200 Subject: [PATCH] hover tests --- .../src/tests/editorHoverContext.test.ts | 149 +++++++++--------- 1 file changed, 74 insertions(+), 75 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/editorHoverContext.test.ts b/apps/remix-ide-e2e/src/tests/editorHoverContext.test.ts index 7b4cefbbc7..f6562df06d 100644 --- a/apps/remix-ide-e2e/src/tests/editorHoverContext.test.ts +++ b/apps/remix-ide-e2e/src/tests/editorHoverContext.test.ts @@ -2,88 +2,86 @@ import { NightwatchBrowser } from 'nightwatch' import init from '../helpers/init' +const checkEditorHoverContent = (browser: NightwatchBrowser, path: string, expectedContent: string, offsetLeft: number = 0) => { + browser.useXpath() + .useXpath() + .moveToElement('//body', 0, 0) // always move away from the hover before the next test in case we hover in the same line on a different element + .waitForElementVisible(path) + .moveToElement(path, offsetLeft, 0) + .useCss() + .waitForElementContainsText('.monaco-hover-content', expectedContent).pause(1000) +} + module.exports = { '@disabled': true, before: function (browser: NightwatchBrowser, done: VoidFunction) { init(browser, done, 'http://127.0.0.1:8080', false) }, - 'Should show hover over contract in editor #group1': function (browser: NightwatchBrowser) { + + 'Should load the test file': function (browser: NightwatchBrowser) { browser.openFile('contracts') .openFile('contracts/3_Ballot.sol') .waitForElementVisible('#editorView') .setEditorValue(BallotWithARefToOwner) - .useXpath() - .waitForElementVisible("//*[contains(text(),'BallotHoverTest')]") - .click("//*[contains(text(),'BallotHoverTest')]") - //.moveToElement("//*[contains(text(),'BallotHoverTest')]", 0, 0) - .useCss() - .findElements('.view-line', function (res) { - - if (Array.isArray(res.value)) { - let found = false - for (const jsonWebElement of res.value) { - const jsonWebElementId = jsonWebElement.ELEMENT || jsonWebElement[Object.keys(jsonWebElement)[0]] - if (!found) { - browser.elementIdText(jsonWebElementId, (jsonElement) => { - - const text = jsonElement.value - if (typeof text == 'string') { - - if (text.indexOf('contract BallotHoverTest') !== -1) { - console.log(text) - console.log(jsonWebElementId) - browser - browser.moveTo(jsonWebElementId, 0, 0).pause(20000) - found = true - } - } - } - ) - } - } - /* - res.value.forEach(function (jsonWebElement) { - - - browser.elementIdText(jsonWebElementId, (jsonElement) => { - - const text = jsonElement.value - if (typeof text == 'string') { - - if (text.indexOf('contract BallotHoverTest') !== -1) { - console.log(text) - console.log(jsonWebElementId) - browser.moveTo(jsonWebElementId, 0, 0).pause(20000) - - } - } - }) - })*/ - } - }) - /* - .useCss() - .waitForElementContainsText('.monaco-hover-content', 'contract BallotHoverTest is BallotHoverTest') - .waitForElementContainsText('.monaco-hover-content', 'contracts/3_Ballot.sol 10:0') - .waitForElementContainsText('.monaco-hover-content', '@title Ballot') - .findElements('.view-line', function (res) { - Array.isArray(res.value) && res.value.forEach(function (jsonWebElement) { - const jsonWebElementId = jsonWebElement.ELEMENT || jsonWebElement[Object.keys(jsonWebElement)[0]] - - browser.elementIdText(jsonWebElementId, (jsonElement) => { - - const text = jsonElement.value - if (typeof text == 'string') { - if (text.indexOf('address public chairperson;') !== -1) { - console.log(jsonWebElementId) - browser.moveTo(jsonWebElementId, 20, 0).pause(20000) - } - } - }) - }) - }) - */ - + .pause(4000) // wait for the compiler to finish + }, + 'Should show hover over contract in editor #group1': function (browser: NightwatchBrowser) { + const path = "//*[contains(text(),'BallotHoverTest')]" + checkEditorHoverContent(browser, path, 'contract BallotHoverTest is BallotHoverTest') + checkEditorHoverContent(browser, path, 'contracts/3_Ballot.sol 10:0') + checkEditorHoverContent(browser, path, '@title Ballot') + }, + 'Should show hover over var definition in editor #group1': function (browser: NightwatchBrowser) { + const path = "//*[@class='view-line' and contains(.,'chairperson') and contains(.,'address') and contains(.,'public')]//span//span[contains(.,'chairperson')]" + const expectedContent = 'address public chairperson' + checkEditorHoverContent(browser, path, expectedContent) + }, + 'Should show hover over constructor in editor #group1': function (browser: NightwatchBrowser) { + const path: string = "//*[@class='view-line' and contains(.,'constructor') and contains(.,'bytes32') and contains(.,'memory')]//span//span[contains(.,'constructor')]" + const expectedContent = 'Estimated creation cost: infinite gas Estimated code deposit cost:' + checkEditorHoverContent(browser, path, expectedContent) + }, + 'Should show hover over function in editor #group1': function (browser: NightwatchBrowser) { + const path: string = "//*[@class='view-line' and contains(.,'giveRightToVote(address') and contains(.,'function') and contains(.,'public')]//span//span[contains(.,'giveRightToVote')]" + let expectedContent = 'Estimated execution cost' + checkEditorHoverContent(browser, path, expectedContent) + expectedContent = 'function giveRightToVote (address internal voter) public nonpayable returns ()' + checkEditorHoverContent(browser, path, expectedContent) + expectedContent = "@dev Give 'voter' the right to vote on this ballot. May only be called by 'chairperson'" + checkEditorHoverContent(browser, path, expectedContent) + }, + 'Should show hover over var components in editor #group1': function (browser: NightwatchBrowser) { + let path = "//*[@class='view-line' and contains(.,'voters') and contains(.,'weight')]//span//span[contains(.,'voters')]" + let expectedContent = 'mapping(address => struct BallotHoverTest.Voter) public voters' + checkEditorHoverContent(browser, path, expectedContent, 15) + path = "//*[@class='view-line' and contains(.,'voters') and contains(.,'weight')]//span//span[contains(.,'chairperson')]" + expectedContent = 'address public chairperson' + checkEditorHoverContent(browser, path, expectedContent, 3) + path = "//*[@class='view-line' and contains(.,'voters') and contains(.,'weight')]//span//span[contains(.,'weight')]" + expectedContent = 'uint256 internal weight' + checkEditorHoverContent(browser, path, expectedContent) + }, + 'Should show hover over new contract creation in editor #group1': function (browser: NightwatchBrowser) { + let path = "//*[@class='view-line' and contains(.,'Owner') and contains(.,'new')]//span//span[contains(.,'cowner')]" + let expectedContent = 'contract Owner internal cowner' + checkEditorHoverContent(browser, path, expectedContent, 10) + path = "//*[@class='view-line' and contains(.,'Owner') and contains(.,'new')]//span//span[contains(.,'Owner')]" + expectedContent = 'contract Owner is Owner' + checkEditorHoverContent(browser, path, expectedContent, 10) + }, + 'Should show hover over external class member in editor #group1': function (browser: NightwatchBrowser) { + const path = "//*[@class='view-line' and contains(.,'getOwner') and contains(.,'cowner')]//span//span[contains(.,'getOwner')]" + let expectedContent = 'function getOwner () external view returns (address internal )' + checkEditorHoverContent(browser, path, expectedContent, 0) + expectedContent = 'contracts/2_Owner.sol' + checkEditorHoverContent(browser, path, expectedContent, 0) + expectedContent = '@dev Return owner address' + checkEditorHoverContent(browser, path, expectedContent, 0) + }, + 'Should show hover over struct definition in editor #group1': function (browser: NightwatchBrowser) { + const path = "//*[@class='view-line' and contains(.,'Voter') and contains(.,'struct')]//span//span[contains(.,'Voter')]" + const expectedContent = 'StructDefinition' + checkEditorHoverContent(browser, path, expectedContent) } } @@ -100,7 +98,7 @@ import "./2_Owner.sol"; * @dev Implements voting process along with vote delegation */ contract BallotHoverTest { - Owner c; + Owner cowner; struct Voter { uint weight; // weight is accumulated by delegation bool voted; // if true, that person already voted @@ -126,7 +124,8 @@ contract BallotHoverTest { * @param proposalNames names of proposals */ constructor(bytes32[] memory proposalNames) { - c = new Owner(); + cowner = new Owner(); + cowner.getOwner(); chairperson = msg.sender; voters[chairperson].weight = 1;