Co-authored-by: Chiedo John <2156688+chiedo@users.noreply.github.com>
This commit is contained in:
Kevin Heis 2021-02-22 10:27:57 -08:00 коммит произвёл GitHub
Родитель 408fcdf4fd
Коммит bcd91a04c6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 4 добавлений и 81 удалений

Просмотреть файл

@ -1,8 +1,6 @@
import murmur from 'imurmurhash' import murmur from 'imurmurhash'
import { getUserEventsId, sendEvent } from './events' import { getUserEventsId, sendEvent } from './events'
import h from './hyperscript' // import h from './hyperscript'
import { updateDisplay, submitForm } from './helpfulness'
const TREATMENT = 'TREATMENT' const TREATMENT = 'TREATMENT'
const CONTROL = 'CONTROL' const CONTROL = 'CONTROL'
@ -29,79 +27,4 @@ export default function () {
// const x = document.querySelector(...) // const x = document.querySelector(...)
// x.addEventListener('click', () => { sendSuccess(testName) }) // x.addEventListener('click', () => { sendSuccess(testName) })
// if (xbucket === TREATMENT) applyTreatment(x) // if (xbucket === TREATMENT) applyTreatment(x)
const testName = 'survey-stars'
const xbucket = bucket(testName)
const form = document.querySelector('.js-helpfulness')
if (!form) return
// Overwrites the default handler for helpfulness survey...
form.addEventListener('submit', evt => {
evt.preventDefault()
sendSuccess(testName)
submitForm(form)
updateDisplay(form, 'end')
})
if (xbucket === TREATMENT) applyTreatment(form)
}
function applyTreatment (form) {
const p = form.querySelector('.radio-group')
p.innerHTML = ''
const buttons = [1, 2, 3, 4, 5].map(i =>
h(
'button',
{
'data-value': i,
'aria-label': i,
class: 'btn-link tooltipped tooltipped-n'
},
h(
'span',
{
class: 'star-empty f3'
},
'☆'
),
h(
'span',
{
class: 'star-full f3',
hidden: true
},
'★'
)
)
)
const input = h('input', {
name: 'helpfulness-vote',
type: 'hidden'
})
buttons.forEach(btn => p.appendChild(btn))
p.appendChild(input)
buttons.forEach((btn, i) => {
btn.addEventListener('click', evt => {
evt.preventDefault()
updateBtnDisplay(i)
submitForm(form)
updateDisplay(form, i > 2 ? 'yes' : 'no')
})
})
function updateBtnDisplay (i) {
buttons.forEach((xbtn, xi) => {
if (xi <= i) {
xbtn.querySelector('.star-full').removeAttribute('hidden')
xbtn.querySelector('.star-empty').setAttribute('hidden', true)
} else {
xbtn.querySelector('.star-full').setAttribute('hidden', true)
xbtn.querySelector('.star-empty').removeAttribute('hidden')
}
})
input.setAttribute('value', i > 2 ? 'Yes' : 'No')
}
} }

Просмотреть файл

@ -8,7 +8,7 @@ function hideElement (el) {
el.setAttribute('hidden', true) el.setAttribute('hidden', true)
} }
export function updateDisplay (form, state) { function updateDisplay (form, state) {
Array.from( Array.from(
form.querySelectorAll( form.querySelectorAll(
['start', 'yes', 'no', 'end'] ['start', 'yes', 'no', 'end']
@ -21,7 +21,7 @@ export function updateDisplay (form, state) {
.forEach(showElement) .forEach(showElement)
} }
export function submitForm (form) { function submitForm (form) {
const formData = new FormData(form) const formData = new FormData(form)
const data = Object.fromEntries( const data = Object.fromEntries(
Array.from(formData.entries()) Array.from(formData.entries())

Просмотреть файл

@ -85,7 +85,7 @@ describe('browser search', () => {
}) })
}) })
describe.skip('helpfulness', () => { describe('helpfulness', () => {
it('sends an event to /events when submitting form', async () => { it('sends an event to /events when submitting form', async () => {
// Visit a page that displays the prompt // Visit a page that displays the prompt
await page.goto('http://localhost:4001/en/actions/getting-started-with-github-actions/about-github-actions') await page.goto('http://localhost:4001/en/actions/getting-started-with-github-actions/about-github-actions')