From 14e2fcfef3ba9ce39c2d5b19dd0131be289b782c Mon Sep 17 00:00:00 2001 From: Veljko Date: Wed, 22 Feb 2023 09:43:45 +0100 Subject: [PATCH] Add first part of the k6 test adding a subscriber [MAILPOET-4956] --- mailpoet/tests/performance/config.js | 4 + mailpoet/tests/performance/scenarios.js | 2 + .../performance/tests/subscribers-adding.js | 85 +++++++++++++++++++ mailpoet/tests/performance/utils/helpers.js | 8 ++ 4 files changed, 99 insertions(+) create mode 100644 mailpoet/tests/performance/tests/subscribers-adding.js diff --git a/mailpoet/tests/performance/config.js b/mailpoet/tests/performance/config.js index 52c3e9d37b..e992096cc2 100644 --- a/mailpoet/tests/performance/config.js +++ b/mailpoet/tests/performance/config.js @@ -9,5 +9,9 @@ export const adminUsername = 'admin'; export const adminPassword = 'password'; export const adminEmail = 'test@test.com'; +export const firstName = 'John'; +export const lastName = 'Doe'; +export const defaultListName = 'Newsletter mailing list'; + export const thinkTimeMin = '1'; export const thinkTimeMax = '4'; diff --git a/mailpoet/tests/performance/scenarios.js b/mailpoet/tests/performance/scenarios.js index eec92b1fd1..8f93dcf810 100644 --- a/mailpoet/tests/performance/scenarios.js +++ b/mailpoet/tests/performance/scenarios.js @@ -5,6 +5,7 @@ import { newsletterListing } from './tests/newsletter-listing.js'; import { subscribersListing } from './tests/subscribers-listing.js'; import { settingsBasic } from './tests/settings-basic.js'; import { subscribersFiltering } from './tests/subscribers-filtering.js'; +import { subscribersAdding } from './tests/subscribers-adding.js'; import { htmlReport } from 'https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js'; import { textSummary } from 'https://jslib.k6.io/k6-summary/0.0.1/index.js'; import { scenario } from './config.js'; @@ -60,6 +61,7 @@ export function pullRequests() { subscribersListing(); settingsBasic(); subscribersFiltering(); + subscribersAdding(); } // All the tests ran for a nightly testing diff --git a/mailpoet/tests/performance/tests/subscribers-adding.js b/mailpoet/tests/performance/tests/subscribers-adding.js new file mode 100644 index 0000000000..501b170c28 --- /dev/null +++ b/mailpoet/tests/performance/tests/subscribers-adding.js @@ -0,0 +1,85 @@ +/* eslint-disable no-shadow */ +/* eslint-disable import/no-unresolved */ +/* eslint-disable import/no-default-export */ +/** + * External dependencies + */ +import { sleep, check, group } from 'k6'; +import { chromium } from 'k6/x/browser'; +import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js'; + +/** + * Internal dependencies + */ +import { + baseURL, + thinkTimeMin, + thinkTimeMax, + headlessSet, + timeoutSet, + firstName, + lastName, + defaultListName, +} from '../config.js'; +import { authenticate, selectInSelect2 } from '../utils/helpers.js'; +/* global Promise */ + +export function subscribersAdding() { + const browser = chromium.launch({ + headless: headlessSet, + timeout: timeoutSet, + }); + const page = browser.newPage(); + + group('Subscribers - Add a new subscriber', function subscribersAdding() { + page + .goto(`${baseURL}/wp-admin/admin.php?page=mailpoet-subscribers`, { + waitUntil: 'networkidle', + }) + + .then(() => { + authenticate(page); + }) + + .then(() => { + return Promise.all([ + page.waitForNavigation({ waitUntil: 'networkidle' }), + ]); + }) + + .then(() => { + page + .locator('[data-automation-id="add-new-subscribers-button"]') + .click(); + page + .locator('input[name="email"]') + .type('test+' + Math.floor(Math.random() * 9999 + 1) + '@test.com'); + page.locator('input[name="first_name"]').type(firstName); + page.locator('input[name="last_name"]').type(lastName); + selectInSelect2(page, defaultListName); + page.locator('button[type="submit"]').click(); + page.waitForSelector('.mailpoet-listing-no-items'); + page.waitForSelector('[data-automation-id="filters_subscribed"]'); + check(page, { + 'subscribers filter is visible': page + .locator('[data-automation-id="listing_filter_segment"]') + .isVisible(), + }); + }) + + .then(() => { + // search for added subscriber + }) + + .finally(() => { + page.close(); + browser.close(); + }); + }); + + sleep(randomIntBetween(thinkTimeMin, thinkTimeMax)); +} + +export default function subscribersAddingTest() { + subscribersAdding(); +} diff --git a/mailpoet/tests/performance/utils/helpers.js b/mailpoet/tests/performance/utils/helpers.js index 52bd228a9b..12a7031539 100644 --- a/mailpoet/tests/performance/utils/helpers.js +++ b/mailpoet/tests/performance/utils/helpers.js @@ -18,3 +18,11 @@ export function authenticate(page) { page.locator('input[name="wp-submit"]').click(), ]); } + +// Select a segment or a list from a select2 search field +export function selectInSelect2(page, listName) { + // Click and write a list name from a dropdown + page.locator('.select2-selection').click(); + page.locator('.select2-selection').type(listName); + page.keyboard.press('Enter'); +}