-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #458 from Psychedelic/feat/automatic-testing
Feat/automatic testing
- Loading branch information
Showing
12 changed files
with
1,887 additions
and
1,607 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,10 @@ | ||
const JsConfigPathsMapper = require('jsconfig-paths-jest-mapper'); | ||
const regeneratorRuntime = require("regenerator-runtime"); | ||
const chrome = require('sinon-chrome/extensions'); | ||
const firefox = require('selenium-webdriver/firefox'); | ||
const browser = require('sinon-chrome/webextensions'); | ||
const webdriver = require('selenium-webdriver'); | ||
const { Builder, By, Key, Capabilities, until } = require('selenium-webdriver'); | ||
const { Options: ChromeOptions } = require('selenium-webdriver/chrome'); | ||
const { Options: FirefoxOptions } = require('selenium-webdriver/firefox'); | ||
const path = require('path'); | ||
|
||
const instantiateSeleniumDriver = async () => { | ||
const seleniumChrome = webdriver.Capabilities.chrome(); | ||
const seleniumFirefox = webdriver.Capabilities.firefox(); | ||
|
||
const chromeOptions = new ChromeOptions(); | ||
const firefoxOptions = new FirefoxOptions(); | ||
|
||
chromeOptions.addArguments("--load-extension=" + path.resolve(__dirname, 'extension', 'chrome')); | ||
firefoxOptions.setPreference("xpinstall.signatures.required", false); | ||
|
||
const chromeDriver = new webdriver.Builder() | ||
.withCapabilities(seleniumChrome) | ||
.setChromeOptions(chromeOptions) | ||
.build(); | ||
|
||
const firefoxDriver = new webdriver.Builder() | ||
.forBrowser('firefox') | ||
.setFirefoxOptions(firefoxOptions) | ||
.build(); | ||
|
||
//await firefoxDriver.installAddon(path.resolve(__dirname, 'extension', 'firefox.xpi')); | ||
|
||
return [chromeDriver, firefoxDriver]; | ||
}; | ||
|
||
module.exports = { | ||
moduleFileExtensions: ["js", "jsx"], | ||
preset: "jest-puppeteer", | ||
setupFilesAfterEnv: ['<rootDir>/tests/setup/jestSetup.js'], | ||
transform: { | ||
"^.+\\.jsx?$": "<rootDir>/tests/__setup__/jest.transform.js", | ||
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/tests/__setup__/assetsTransformer.js", | ||
"\\.(css|less)$": "<rootDir>/tests/__setup__/assetsTransformer.js" | ||
}, | ||
globals: { | ||
chrome, | ||
browser, | ||
regeneratorRuntime, | ||
getDrivers: instantiateSeleniumDriver, | ||
closeDriver: (drivers) => { | ||
drivers.forEach(driver => driver.quit()); | ||
}, | ||
"node_modules/variables/.js": "babel-jest", | ||
}, | ||
moduleNameMapper: new JsConfigPathsMapper({ configFileName: "./jsconfig.json" }), | ||
transformIgnorePatterns: [ | ||
"node_modules/(?!variables/.*)" | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
describe('Import/Create', () => { | ||
let chromeBrowser; | ||
let page; | ||
|
||
const passwordErrorLabel = '#options-root > div > div.MuiContainer-root.MuiContainer-maxWidthSm > div > div.MuiGrid-root.makeStyles-passwordError-4.MuiGrid-item.MuiGrid-grid-xs-12 > p'; | ||
|
||
const badSeedphrase = 'sadf adsf adfdfasd adfad adfafd sdfsd sdfsdf sdfds sdfd sdf sfsfs sdfadsf'; | ||
|
||
const getButtonCollection = async (page) => { | ||
return await page.$$('button'); | ||
} | ||
|
||
const getImportButton = async (page) => { | ||
const buttonCollection = await getButtonCollection(page); | ||
return buttonCollection[0]; | ||
}; | ||
|
||
const getCreateButton = async (page) => { | ||
const buttonCollection = await getButtonCollection(page); | ||
return buttonCollection[1]; | ||
}; | ||
|
||
beforeAll(async () => { | ||
chromeBrowser = await setupChrome(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
page = await chromeBrowser.newPage(); | ||
await page.goto(chromeData.optionsUrl); | ||
}); | ||
|
||
afterEach(async () => { | ||
await page.close(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await chromeBrowser.close(); | ||
}); | ||
|
||
describe('Import', () => { | ||
beforeEach(async () => { | ||
const importButton = await utils.getButtonWithIndex(page, 0); | ||
await importButton.click(); | ||
}); | ||
|
||
test('Fails on incorrect seedphrase', async () => { | ||
const importInputElement = await utils.getElement(page, 'textarea'); | ||
await importInputElement.type(badSeedphrase); | ||
|
||
const submitImport = await utils.getButtonWithIndex(page, 0); | ||
await submitImport.click(); | ||
|
||
const updatedImportBtn = await utils.getButtonWithIndex(page, 0); | ||
const importButtonClassName = await (await updatedImportBtn.getProperty('className')).jsonValue(); | ||
const importButtonClassNameArray = importButtonClassName.split(' '); | ||
|
||
expect(importButtonClassNameArray).toEqual(expect.arrayContaining(['Mui-disabled'])); | ||
}); | ||
|
||
test('Fails on missmatched passwords', async () => { | ||
const importInputElement = await utils.getElement(page, 'textarea'); | ||
await importInputElement.type(secrets.seedphrase); | ||
|
||
const submitImport = await utils.getButtonWithIndex(page, 0); | ||
await submitImport.click(); | ||
|
||
await utils.waitForRender(500); | ||
const [passwordInput, confirmPasswordInput] = await utils.getInputs(page); | ||
await passwordInput.type('TestPassword123'); | ||
await confirmPasswordInput.type('MissMatchedPassword'); | ||
|
||
const submitPassword = await utils.getButtonWithIndex(page, 0); | ||
await submitPassword.click(); | ||
|
||
await page.waitForSelector(passwordErrorLabel); | ||
const labelErrorElement = await page.$(passwordErrorLabel) | ||
const value = await page.evaluate(el => el.textContent, labelErrorElement); | ||
|
||
expect(value).toBe('The passwords gotta match, smh!'); | ||
}); | ||
|
||
test('Fails on password shorter than 12 characters', async () => { | ||
const importInputElement = await utils.getElement(page, 'textarea'); | ||
await importInputElement.type(secrets.seedphrase); | ||
|
||
const submitImport = await utils.getButtonWithIndex(page, 0); | ||
await submitImport.click(); | ||
|
||
const [passwordInput, confirmPasswordInput] = await utils.getInputs(page); | ||
await passwordInput.type('123'); | ||
await confirmPasswordInput.type('123'); | ||
|
||
const submitPassword = await utils.getButtonWithIndex(page, 0); | ||
await submitPassword.click(); | ||
|
||
await page.waitForSelector(passwordErrorLabel); | ||
const labelErrorElement = await page.$(passwordErrorLabel) | ||
const value = await page.evaluate(el => el.textContent, labelErrorElement); | ||
|
||
expect(value).toBe('The minimum is 12 characters, smh!'); | ||
}); | ||
|
||
test('Correctly imports', async () => { | ||
const importInputElement = await utils.getElement(page, 'textarea'); | ||
await importInputElement.type(secrets.seedphrase); | ||
|
||
const submitImport = await utils.getButtonWithIndex(page, 0); | ||
await submitImport.click(); | ||
|
||
const [passwordInput, confirmPasswordInput] = await utils.getInputs(page, true); | ||
await passwordInput.type(secrets.password); | ||
await confirmPasswordInput.type(secrets.password); | ||
|
||
const submitPassword = await utils.getButtonWithIndex(page, 0); | ||
await submitPassword.click(); | ||
|
||
await page.goto(chromeData.popupUrl); | ||
|
||
const popupPasswordInput = await utils.getInputWithIndex(page, 0, true); | ||
await popupPasswordInput.type(secrets.password); | ||
|
||
const unlockPlugButton = await utils.getButtonWithIndex(page, 0); | ||
await unlockPlugButton.click(); | ||
|
||
const [plugBanner] = await utils.getXPathElements(page, 'span', 'Alpha Release', true); | ||
const value = await page.evaluate(el => el.textContent, plugBanner); | ||
|
||
expect(value).toMatch(/Plug/i); | ||
}); | ||
}); | ||
|
||
describe('Create', () => { | ||
beforeEach(async () => { | ||
const createButton = await utils.getButtonWithIndex(page, 1); | ||
await createButton.click(); | ||
}); | ||
|
||
test('Fails on missmatched passwords', async () => { | ||
const [passwordInput, confirmPasswordInput] = await utils.getInputs(page); | ||
await passwordInput.type('TestPassword123'); | ||
await confirmPasswordInput.type('MissMatchedPassword'); | ||
|
||
const submitPasswordButton = await utils.getButtonWithIndex(page, 0); | ||
await submitPasswordButton.click(); | ||
|
||
await page.waitForSelector(passwordErrorLabel); | ||
const labelErrorElement = await page.$(passwordErrorLabel) | ||
const value = await page.evaluate(el => el.textContent, labelErrorElement); | ||
|
||
expect(value).toBe('The passwords gotta match, smh!'); | ||
}); | ||
|
||
test('Fails on password shorter than 12 characters', async () => { | ||
const [passwordInput, confirmPasswordInput] = await utils.getInputs(page); | ||
await passwordInput.type('123'); | ||
await confirmPasswordInput.type('123'); | ||
|
||
const submitPasswordButton = await utils.getButtonWithIndex(page, 0); | ||
await submitPasswordButton.click(); | ||
|
||
await page.waitForSelector(passwordErrorLabel); | ||
const labelErrorElement = await page.$(passwordErrorLabel) | ||
const value = await page.evaluate(el => el.textContent, labelErrorElement); | ||
|
||
expect(value).toBe('The minimum is 12 characters, smh!'); | ||
}); | ||
|
||
test('Correctly creates', async () => { | ||
const [passwordInput, confirmPasswordInput] = await utils.getInputs(page); | ||
await passwordInput.type(secrets.password); | ||
await confirmPasswordInput.type(secrets.password); | ||
|
||
const submitPasswordButton = await utils.getButtonWithIndex(page, 0); | ||
await submitPasswordButton.click(); | ||
|
||
const [revealSeedphraseElement] = await utils.getXPathElements(page, 'span', 'Reveal Secret Recovery Phrase', true); | ||
await revealSeedphraseElement.click(); | ||
|
||
const confirmSeedphraseElement = await utils.getInputWithIndex(page, 0); | ||
await confirmSeedphraseElement.click(); | ||
|
||
const continueBtn = await utils.getButtonWithIndex(page, 0); | ||
await continueBtn.click(); | ||
|
||
await page.goto(chromeData.popupUrl); | ||
|
||
const popupPasswordInput = await utils.getInputWithIndex(page, 0, true); | ||
await popupPasswordInput.type(secrets.password); | ||
|
||
const unlockPlugButton = await utils.getButtonWithIndex(page, 0); | ||
await unlockPlugButton.click(); | ||
|
||
const [plugBanner] = await utils.getXPathElements(page, 'span', 'Alpha Release', true); | ||
const value = await page.evaluate(el => el.textContent, plugBanner); | ||
|
||
expect(value).toMatch(/Plug/i); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.