Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ gulp.task(
gulp.series('build:rollup', function () {
return gulp
.src('dist/pathfora.js')
.pipe(replace('`{{apiurl}}`', 'https://c.lytics.io'))
.pipe(replace('`{{apiurl}}`', APIURL))
.pipe(replace('`{{cssurl}}`', CSSURL))
.pipe(replace('`{{templates}}`', prepareTemplates()))
.pipe(gulp.dest('dist'))
Expand Down Expand Up @@ -176,7 +176,7 @@ gulp.task(
return gulp
.src('dist/pathfora.js')
.pipe(replace('`{{apiurl}}`', TESTAPIURL))
.pipe(replace('`{{cssurl}`}', TESTCSSURL))
.pipe(replace('`{{cssurl}}`', TESTCSSURL))
.pipe(replace('`{{templates}}`', prepareTemplates()))
.pipe(gulp.dest('dist'))
.pipe(connect.reload());
Expand Down
138 changes: 68 additions & 70 deletions test/acceptance/ab-testing.spec.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
import globalReset from '../utils/global-reset';
import { createMessageWidget } from '../utils/test-helpers';

// -------------------------
// A/B TESTING
// -------------------------
describe('when performing AB testing', function () {
describe('a/b testing', function () {
beforeEach(function () {
globalReset();
});

it('should select only one A/B Test group to show', function () {
var widgetA = new pathfora.Message({
var widgetA = createMessageWidget({
id: 'ab-widget1-a',
msg: 'A',
layout: 'slideout'
layout: 'slideout',
});

var widgetB = new pathfora.Message({
var widgetB = createMessageWidget({
id: 'ab-widget1-b',
msg: 'B',
layout: 'slideout'
layout: 'slideout',
});

var ab = new pathfora.ABTest({
id: 'ab-1',
type: '50/50',
groups: [[widgetA], [widgetB]]
groups: [[widgetA], [widgetB]],
});

pathfora.initializeABTesting([ab]);
Expand All @@ -35,34 +33,37 @@ describe('when performing AB testing', function () {
});

it('should show all widgets in an A/B test group', function () {
var widget1A = new pathfora.Message({
var widget1A = createMessageWidget({
id: 'ab-widget2-1a',
msg: 'A',
layout: 'slideout'
layout: 'slideout',
});

var widget2A = new pathfora.Message({
var widget2A = createMessageWidget({
id: 'ab-widget2-2a',
msg: 'A',
layout: 'slideout'
layout: 'slideout',
});

var widget1B = new pathfora.Message({
var widget1B = createMessageWidget({
id: 'ab-widget2-1b',
msg: 'B',
layout: 'slideout'
layout: 'slideout',
});

var widget2B = new pathfora.Message({
var widget2B = createMessageWidget({
id: 'ab-widget2-2b',
msg: 'B',
layout: 'slideout'
layout: 'slideout',
});

var ab = new pathfora.ABTest({
id: 'ab-2',
type: '50/50',
groups: [[widget1A, widget2A], [widget1B, widget2B]]
groups: [
[widget1A, widget2A],
[widget1B, widget2B],
],
});

pathfora.initializeABTesting([ab]);
Expand All @@ -73,10 +74,7 @@ describe('when performing AB testing', function () {

var first = w.first();
expect(first.find('.pf-widget-message').text()).toEqual(
first
.next()
.find('.pf-widget-message')
.text()
first.next().find('.pf-widget-message').text()
);
});

Expand All @@ -85,29 +83,29 @@ describe('when performing AB testing', function () {

pathfora.utils.write('PathforaTest_' + id, 0.2164252290967852);

var widgetA = new pathfora.Message({
var widgetA = createMessageWidget({
id: 'ab-widget3-a',
msg: 'A',
layout: 'modal'
layout: 'modal',
});

var widgetB = new pathfora.Message({
var widgetB = createMessageWidget({
id: 'ab-widget3-b',
msg: 'B',
layout: 'modal'
layout: 'modal',
});

var ab = new pathfora.ABTest({
id: id,
type: '50/50',
groups: [[widgetA], [widgetB]]
groups: [[widgetA], [widgetB]],
});

pathfora.initializeABTesting([ab]);
pathfora.initializeWidgets([widgetA, widgetB]);

var wB = $('#' + widgetB.id),
wA = $('#' + widgetA.id);
wA = $('#' + widgetA.id);
expect(wB.length).toBe(1);
expect(wA.length).toBe(0);
});
Expand All @@ -116,77 +114,77 @@ describe('when performing AB testing', function () {
var id = 'ab-4';
pathfora.utils.saveCookie('PathforaTest_' + id, 0.7077720651868731);

var widgetA = new pathfora.Message({
var widgetA = createMessageWidget({
id: 'ab-widget4-a',
msg: 'A',
layout: 'modal'
layout: 'modal',
});

var widgetB = new pathfora.Message({
var widgetB = createMessageWidget({
id: 'ab-widget4-b',
msg: 'B',
layout: 'modal'
layout: 'modal',
});

var ab = new pathfora.ABTest({
id: id,
type: '50/50',
groups: [[widgetA], [widgetB]]
groups: [[widgetA], [widgetB]],
});

pathfora.initializeABTesting([ab]);
pathfora.initializeWidgets([widgetA, widgetB]);

var wB = $('#' + widgetB.id),
wA = $('#' + widgetA.id);
wA = $('#' + widgetA.id);

expect(wA.length).toBe(1);
expect(wB.length).toBe(0);
});

it('should allow multiple A/B tests per page', function () {
var widgetA = new pathfora.Message({
var widgetA = createMessageWidget({
id: 'ab-widget5-a',
msg: 'A',
layout: 'modal'
layout: 'modal',
});

var widgetB = new pathfora.Message({
var widgetB = createMessageWidget({
id: 'ab-widget5-b',
msg: 'B',
layout: 'modal'
layout: 'modal',
});

var ab = new pathfora.ABTest({
id: 'ab-5',
type: '50/50',
groups: [[widgetA], [widgetB]]
groups: [[widgetA], [widgetB]],
});

var widgetC = new pathfora.Message({
var widgetC = createMessageWidget({
id: 'ab-widget6-c',
msg: 'C',
layout: 'modal'
layout: 'modal',
});

var widgetD = new pathfora.Message({
var widgetD = createMessageWidget({
id: 'ab-widget6-d',
msg: 'D',
layout: 'modal'
layout: 'modal',
});

var ab2 = new pathfora.ABTest({
id: 'ab-6',
type: '50/50',
groups: [[widgetC], [widgetD]]
groups: [[widgetC], [widgetD]],
});

pathfora.initializeABTesting([ab, ab2]);
pathfora.initializeWidgets([widgetA, widgetB, widgetC, widgetD]);

var w = $('[id*="ab-widget"]'),
w5 = $('[id*="ab-widget5"]'),
w6 = $('[id*="ab-widget6"]');
w5 = $('[id*="ab-widget5"]'),
w6 = $('[id*="ab-widget6"]');

expect(w.length).toBe(2);
expect(w5.length).toBe(1);
Expand All @@ -196,40 +194,40 @@ describe('when performing AB testing', function () {
it('should handle A/B Tests in conjunction with audience targeting', function () {
window.lio = {
data: {
segments: ['all', 'smt_new']
segments: ['all', 'smt_new'],
},
account: {
id: '0'
}
id: '0',
},
};

window.lio.loaded = true;

var widgetA = new pathfora.Message({
var widgetA = createMessageWidget({
id: 'ab-widget10-a',
layout: 'slideout',
msg: 'A'
msg: 'A',
});

var widgetB = new pathfora.Message({
var widgetB = createMessageWidget({
id: 'ab-widget10-b',
layout: 'slideout',
msg: 'B'
msg: 'B',
});

var ab = new pathfora.ABTest({
id: 'ab-10',
type: '50/50',
groups: [[widgetA], [widgetB]]
groups: [[widgetA], [widgetB]],
});

var widgets = {
target: [
{
segment: 'smt_new',
widgets: [widgetA, widgetB]
}
]
widgets: [widgetA, widgetB],
},
],
};

pathfora.initializeABTesting([ab]);
Expand All @@ -243,16 +241,16 @@ describe('when performing AB testing', function () {
var id = 'ab-11';
pathfora.utils.saveCookie('PathforaTest_' + id, 0.7077720651868731);

var widget = new pathfora.Message({
var widget = createMessageWidget({
id: 'ab-widget11-a',
msg: 'A',
layout: 'slideout'
layout: 'slideout',
});

var ab = new pathfora.ABTest({
id: 'ab-11',
type: '80/20',
groups: [[], [widget]]
groups: [[], [widget]],
});

pathfora.initializeABTesting([ab]);
Expand All @@ -263,22 +261,22 @@ describe('when performing AB testing', function () {
});

it('should not allow a widget to be used in more than one A/B test', function () {
var widgetA = new pathfora.Message({
var widgetA = createMessageWidget({
id: 'ab-widget8-a',
msg: 'A',
layout: 'slideout'
layout: 'slideout',
});

var ab = new pathfora.ABTest({
id: 'ab-7',
type: '50/50',
groups: [[widgetA], []]
groups: [[widgetA], []],
});

var ab2 = new pathfora.ABTest({
id: 'ab-8',
type: '50/50',
groups: [[widgetA], []]
groups: [[widgetA], []],
});

expect(function () {
Expand All @@ -291,28 +289,28 @@ describe('when performing AB testing', function () {
});

it('should not allow a widget to be used in more than one A/B test', function () {
var widgetA = new pathfora.Message({
var widgetA = createMessageWidget({
id: 'ab-widget9-a',
msg: 'A',
layout: 'slideout'
layout: 'slideout',
});

var widgetB = new pathfora.Message({
var widgetB = createMessageWidget({
id: 'ab-widget9-b',
msg: 'B',
layout: 'slideout'
layout: 'slideout',
});

var ab = new pathfora.ABTest({
id: 'ab-9',
type: '50/50',
groups: [[widgetA], []]
groups: [[widgetA], []],
});

var ab2 = new pathfora.ABTest({
id: 'ab-9',
type: '50/50',
groups: [[widgetB], []]
groups: [[widgetB], []],
});

expect(function () {
Expand Down
Loading