describe('TestGroupFormTests', () => { const scripts = ['instrumentation.js', '../shared/common-component-base.js', 'components/base.js', 'components/test-group-form.js']; function createTestGroupFormWithContext(context) { return context.importScripts(scripts, 'ComponentBase', 'TestGroupForm').then((symbols) => { const testGroupForm = new context.symbols.TestGroupForm; context.document.body.appendChild(testGroupForm.element()); return testGroupForm; }); } it('must dispatch "startTesting" action with the number of repetitions the user clicks on "Start A/B testing"', () => { const context = new BrowsingContext(); return createTestGroupFormWithContext(context).then((testGroupForm) => { const calls = []; testGroupForm.listenToAction('startTesting', (...args) => calls.push(args)); expect(calls).to.eql({}); testGroupForm.content('start-button').click(); expect(calls).to.eql([[4, 'alternating', true]]); }); }); it('must dispatch "startTesting" action with the repetition type user selects on "Start A/B testing"', async () => { const context = new BrowsingContext(); const testGroupForm = await createTestGroupFormWithContext(context); const calls = []; testGroupForm.listenToAction('startTesting', (...args) => calls.push(args)); expect(calls).to.eql({}); testGroupForm.content('start-button').click(); expect(calls).to.eql([[4, 'alternating', true]]); const typeForm = testGroupForm.content('repetition-type'); typeForm.value = 'sequential'; typeForm.dispatchEvent(new Event('change')); testGroupForm.content('start-button').click(); expect(calls).to.eql([[4, 'alternating', true], [4, 'sequential', true]]); }); it('must update the repetition count when the user selected a different count', () => { const context = new BrowsingContext(); return createTestGroupFormWithContext(context).then((testGroupForm) => { const calls = []; testGroupForm.listenToAction('startTesting', (...args) => calls.push(args)); expect(calls).to.eql({}); testGroupForm.content('start-button').click(); expect(calls).to.eql([[4, 'alternating', true]]); const countForm = testGroupForm.content('repetition-count'); countForm.value = '6'; countForm.dispatchEvent(new Event('change')); testGroupForm.content('start-button').click(); expect(calls).to.eql([[4, 'alternating', true], [6, 'alternating', true]]); }); }); it('must update "notify on completion" when it is unchecked', () => { const context = new BrowsingContext(); return createTestGroupFormWithContext(context).then((testGroupForm) => { const calls = []; testGroupForm.listenToAction('startTesting', (...args) => calls.push(args)); expect(calls).to.eql({}); testGroupForm.content('start-button').click(); expect(calls).to.eql([[4, 'alternating', true]]); const countForm = testGroupForm.content('repetition-count'); countForm.value = '6'; countForm.dispatchEvent(new Event('change')); const notifyOnCompletionCheckbox = testGroupForm.content('notify-on-completion-checkbox'); notifyOnCompletionCheckbox.checked = false; notifyOnCompletionCheckbox.dispatchEvent(new Event('change')); testGroupForm.content('start-button').click(); expect(calls).to.eql([[4, 'alternating', true], [6, 'alternating', false]]); }); }); describe('setRepetitionCount', () => { it('must update the visible repetition count', () => { const context = new BrowsingContext(); return createTestGroupFormWithContext(context).then((testGroupForm) => { expect(testGroupForm.content('repetition-count').value).to.be('4'); testGroupForm.setRepetitionCount(2); return waitForComponentsToRender(context).then(() => { expect(testGroupForm.content('repetition-count').value).to.be('2'); }); }); }); it('must update the repetition count passed to "startTesting" action', () => { const context = new BrowsingContext(); return createTestGroupFormWithContext(context).then((testGroupForm) => { const calls = []; testGroupForm.listenToAction('startTesting', (...args) => calls.push(args)); expect(calls).to.eql({}); testGroupForm.content().querySelector('button').click(); expect(calls).to.eql([[4, 'alternating', true]]); testGroupForm.setRepetitionCount(8); testGroupForm.content().querySelector('button').click(); expect(calls).to.eql([[4, 'alternating', true], [8, 'alternating', true]]); }); }); }); });