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

infra/civicrm-spark#4 org.civicrm.sparkforms: add a test for onbehalf

parent 01c96680
......@@ -43,15 +43,20 @@ cv en sparkforms
## Test
The tests are not currently fully automated. They mostly aim to help with tech support.
The tests are not currently fully automated. They mostly aim to help with tech
support and make sure things work after doing changes. Saves a ton of time from
filling in the forms manually.
Before running the tests, make sure to enable the Dummy Payment Processor.
```
npm install
HEADLESS=false npm test -t 'spark'
HEADLESS=false npm test -t 'spark-individual'
HEADLESS=false npm test -t 'spark-onbehalf'
```
If running on Wayland:
Example if running on Wayland:
```
MOZ_ENABLE_WAYLAND=1 HEADLESS=false npm test -t 'spark'
MOZ_ENABLE_WAYLAND=1 HEADLESS=false npm test -t 'spark-individual'
```
......@@ -14,7 +14,7 @@ global.evalElement = async (page, selector) => {
return fieldValue;
}
describe("form-don", () => {
describe("form-contrib-spark-individual", () => {
// TODO: https://github.com/smooth-code/jest-puppeteer/issues/88#issuecomment-403603386
beforeAll(async () => {
......
const {firefox} = require("playwright");
const headless = process.env.HEADLESS !== 'false' ? true : false;
const timeout = headless ? 10000 : 600000;
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-contrib-spark-onbehalf", () => {
// TODO: https://github.com/smooth-code/jest-puppeteer/issues/88#issuecomment-403603386
beforeAll(async () => {
browser = await firefox.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'
]
});
const context = await browser.newContext();
page = await context.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");
await page.waitForSelector('.crm-contribution-page-id-123');
});
test("Base tests as individual", async() => {
await page.setViewportSize({ width: 1920, height: 1080 });
await page.waitForSelector('input[name=price_464]');
// Make sure the discount field is hidden
await page.waitForSelector('#discountcode', {
state: 'hidden',
timeout: 1000
});
// Make sure the source field is hidden
await page.waitForSelector('#custom_272', {
state: 'hidden',
timeout: 1000
});
// Make sure recurring is enabled and hidden
await expect(await global.evalElement(page, 'input[name=auto_renew]')).toBeTruthy();
var rand = Math.floor(Math.random() * 1000);
// On behalf of organization
await page.click('#is_for_organization');
await page.type('#onbehalf_organization_name', 'Spark Test Org ' + rand);
await page.type('#onbehalf_email-3', 'mathieu+sparkorg' + rand + '@civicrm.org');
await page.type('#onbehalf_city-3', 'Montréal');
await page.type('#onbehalf_postal_code-3', 'H1H 1H1');
await page.selectOption('#onbehalf_country-3', '1039');
await delay(1000);
await page.selectOption('#onbehalf_state_province-3', '1110');
// Personal info
await page.type('#email-5', 'mathieu+sparktest' + rand + '@civicrm.org');
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.selectOption('#state_province-Primary', '1110');
await page.type('#postal_code-Primary', 'H0H 0H0');
await page.selectOption('#country-Primary', '1039');
await delay(1000);
await page.selectOption('#state_province-Primary', '1110');
await fillCreditCardFields(page);
await page.type('input[name=custom_256]', 'Spark Test ' + rand);
await page.type('input[name=custom_257]', 'testspark' + rand);
await page.selectOption('select[name=custom_271]', '4');
await page.click('#custom_1_end_user');
// Debugging help
if (!headless) {
await delay(timeout - 1000);
}
}, timeout);
});
});
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