Commit a43c5a82 authored by Mathieu Lutfy's avatar Mathieu Lutfy Committed by bgm

civiext/org.civicrm.sparkforms: partial tests

parent 09e5e062
......@@ -40,3 +40,12 @@ cv en sparkforms
## Known Issues
(* FIXME *)
## Test
The tests are not currently fully automated. They mostly aim to help with tech support.
```
npm install
HEADLESS=false npm test -t 'spark'
```
{
"name": "sparkforms",
"version": "1.0.0",
"description": "CiviCRM Spark form customizations",
"main": "index.js",
"scripts": {
"test": "jest"
},
"jest": {
"setupFiles": [
"./tests/puppeteer/utils/helpers.js"
],
"testMatch": [
"**/tests/puppeteer/*.spec.js"
]
},
"repository": {
"type": "git",
"url": "git@lab.civicrm.org:marketing-team/civicrm-website.git"
},
"author": "CiviCRM LLC",
"license": "AGPL-3.0-or-later",
"devDependencies": {
"jest": "^24.9.0"
},
"dependencies": {
"puppeteer": "^3"
}
}
const puppeteer = require("puppeteer");
const headless = process.env.HEADLESS !== 'false' ? true : false;
const timeout = headless ? 10000 : 350000;
let browser, page;
/**
* Helper to evaluate the value of an input element.
*/
global.evalElement = async (page, selector) => {
let fieldHandle = await page.$(selector);
let fieldValue = await page.evaluate(x => x.value, fieldHandle);
return fieldValue;
}
describe("form-don", () => {
// TODO: https://github.com/smooth-code/jest-puppeteer/issues/88#issuecomment-403603386
beforeAll(async () => {
browser = await puppeteer.launch({
headless: headless,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
// Required for testing Stripe
// https://github.com/GoogleChrome/puppeteer/issues/4989
'--disable-features=site-per-process'
]
});
page = await browser.newPage();
});
afterAll(async () => {
browser.close();
});
describe("Signup to CiviCRM Spark", () => {
beforeEach(async () => {
await page.goto("https://civicrm.org/civicrm/contribute/transact?reset=1&id=123", {waitUntil: "networkidle2"});
await page.waitForSelector('.crm-contribution-page-id-123');
});
test("Base tests as individual", async() => {
await page.setViewport({ width: 1920, height: 1080 });
await page.waitForSelector('input[name=price_464]');
// Make sure the discount field is hidden
await page.waitForSelector('#discountcode', {
visible: false,
timeout: 1000
});
// Make sure the source field is hidden
await page.waitForSelector('#custom_272', {
visible: false,
timeout: 1000
});
// Make sure recurring is enabled and hidden
await expect(await global.evalElement(page, 'input[name=auto_renew]')).toBeTruthy();
// Personal info
var rand = Math.floor(Math.random() * 1000);
await page.type('#first_name', "Mathieu");
await page.type('#last_name', 'Sparktest' + rand);
await page.type('#street_address-Primary', '123 Example St.');
await page.type('#city-Primary', 'Montréal');
await page.select('#state_province-Primary', '1110');
await page.type('#postal_code-Primary', 'H0H 0H0');
await page.type('#email-5', 'mathieu+sparktest' + rand + '@symbiotic.coop');
await page.select('#country-Primary', '1039');
await delay(1000);
await page.select('#state_province-Primary', '1110');
// fillStripeFields(page);
// Debugging help
if (!headless) {
await delay(timeout - 1000);
}
}, timeout);
});
});
/**
* Helper function to delay execution.
*/
global.delay = (time) => {
return new Promise(function(resolve) {
setTimeout(resolve, time)
});
}
/**
* Helper to click on the next step in jquery-steps
*/
global.nextStepAndWaitFor = async (page, selector) => {
await page.click('.actions li.last a');
if (selector) {
await page.waitForSelector(selector, {visible: true});
}
}
/**
* Helper function to fill in Stripe CC fields.
*/
global.fillStripeFields = async (page) => {
// Stripe
// https://stackoverflow.com/a/56420104
// https://github.com/GoogleChrome/puppeteer/issues/4960
const elementHandle = await page.$('#card-element iframe');
const frame = await elementHandle.contentFrame();
await frame.waitForSelector('input[name=cardnumber]');
const cc = await frame.$('input[name=cardnumber]');
await cc.type('4111111111111111');
const exp = await frame.$('input[name=exp-date]');
await exp.type('1124');
const cvc = await frame.$('input[name=cvc]');
await cvc.type('123');
const postcode = await frame.$('input[name=postal]');
await postcode.type('12345');
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment