2019-05-27 21:31:35 +02:00
|
|
|
import {
|
|
|
|
getNthStatusContent,
|
|
|
|
getNthStatusPollForm,
|
|
|
|
getNthStatusPollResult,
|
|
|
|
getNthStatusPollVoteCount,
|
|
|
|
pollButton,
|
|
|
|
getComposePollNthInput,
|
|
|
|
composePoll,
|
|
|
|
composePollMultipleChoice,
|
2019-11-01 07:01:35 +01:00
|
|
|
composePollExpiry,
|
|
|
|
composePollAddButton,
|
|
|
|
getComposePollRemoveNthButton,
|
|
|
|
postStatusButton,
|
|
|
|
composeInput,
|
|
|
|
sleep,
|
|
|
|
getNthStatus
|
2019-05-27 21:31:35 +02:00
|
|
|
} from '../utils'
|
|
|
|
import { loginAsFoobar } from '../roles'
|
|
|
|
import { POLL_EXPIRY_DEFAULT } from '../../src/routes/_static/polls'
|
|
|
|
|
|
|
|
fixture`127-compose-polls.js`
|
|
|
|
.page`http://localhost:4002`
|
|
|
|
|
|
|
|
test('Can add and remove poll', async t => {
|
|
|
|
await loginAsFoobar(t)
|
|
|
|
await t
|
2019-11-01 07:01:35 +01:00
|
|
|
.expect(getNthStatus(1).exists).ok()
|
2019-05-27 21:31:35 +02:00
|
|
|
.expect(composePoll.exists).notOk()
|
|
|
|
.expect(pollButton.getAttribute('aria-label')).eql('Add poll')
|
2019-11-09 23:25:26 +01:00
|
|
|
.expect(pollButton.getAttribute('title')).eql('Add poll')
|
2019-05-27 21:31:35 +02:00
|
|
|
.click(pollButton)
|
|
|
|
.expect(composePoll.exists).ok()
|
|
|
|
.expect(getComposePollNthInput(1).value).eql('')
|
|
|
|
.expect(getComposePollNthInput(2).value).eql('')
|
|
|
|
.expect(getComposePollNthInput(3).exists).notOk()
|
|
|
|
.expect(getComposePollNthInput(4).exists).notOk()
|
|
|
|
.expect(composePollMultipleChoice.checked).notOk()
|
|
|
|
.expect(composePollExpiry.value).eql(POLL_EXPIRY_DEFAULT.toString())
|
2019-11-23 20:25:36 +01:00
|
|
|
.expect(pollButton.getAttribute('aria-label')).eql('Remove poll')
|
2019-11-09 23:25:26 +01:00
|
|
|
.expect(pollButton.getAttribute('title')).eql('Remove poll')
|
2019-05-27 21:31:35 +02:00
|
|
|
.click(pollButton)
|
|
|
|
.expect(composePoll.exists).notOk()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('Can add and remove poll options', async t => {
|
|
|
|
await loginAsFoobar(t)
|
|
|
|
await t
|
2019-11-01 07:01:35 +01:00
|
|
|
.expect(getNthStatus(1).exists).ok()
|
2019-05-27 21:31:35 +02:00
|
|
|
.expect(composePoll.exists).notOk()
|
|
|
|
.expect(pollButton.getAttribute('aria-label')).eql('Add poll')
|
2019-11-09 23:25:26 +01:00
|
|
|
.expect(pollButton.getAttribute('title')).eql('Add poll')
|
2019-05-27 21:31:35 +02:00
|
|
|
.click(pollButton)
|
|
|
|
.expect(composePoll.exists).ok()
|
|
|
|
.typeText(getComposePollNthInput(1), 'first', { paste: true })
|
|
|
|
.typeText(getComposePollNthInput(2), 'second', { paste: true })
|
2019-06-22 22:21:19 +02:00
|
|
|
await sleep(1000)
|
|
|
|
await t
|
2019-05-27 21:31:35 +02:00
|
|
|
.click(composePollAddButton)
|
|
|
|
.typeText(getComposePollNthInput(3), 'third', { paste: true })
|
|
|
|
.expect(getComposePollNthInput(1).value).eql('first')
|
|
|
|
.expect(getComposePollNthInput(2).value).eql('second')
|
|
|
|
.expect(getComposePollNthInput(3).value).eql('third')
|
|
|
|
.expect(getComposePollNthInput(4).exists).notOk()
|
2019-06-22 22:21:19 +02:00
|
|
|
await sleep(1000)
|
|
|
|
await t
|
2019-05-27 21:31:35 +02:00
|
|
|
.click(getComposePollRemoveNthButton(2))
|
|
|
|
.expect(getComposePollNthInput(1).value).eql('first')
|
|
|
|
.expect(getComposePollNthInput(2).value).eql('third')
|
|
|
|
.expect(getComposePollNthInput(3).exists).notOk()
|
|
|
|
.expect(getComposePollNthInput(4).exists).notOk()
|
2019-06-22 22:21:19 +02:00
|
|
|
await sleep(1000)
|
|
|
|
await t
|
2019-05-27 21:31:35 +02:00
|
|
|
.click(composePollAddButton)
|
|
|
|
.typeText(getComposePollNthInput(3), 'fourth', { paste: true })
|
|
|
|
.typeText(composeInput, 'Vote on my poll!!!', { paste: true })
|
2019-06-22 22:21:19 +02:00
|
|
|
await sleep(1000)
|
|
|
|
await t
|
2019-05-27 21:31:35 +02:00
|
|
|
.click(postStatusButton)
|
|
|
|
.expect(getNthStatusContent(1).innerText).contains('Vote on my poll!!!')
|
|
|
|
.expect(getNthStatusPollForm(1).exists).notOk()
|
|
|
|
.expect(getNthStatusPollResult(1, 1).innerText).eql('0% first')
|
|
|
|
.expect(getNthStatusPollResult(1, 2).innerText).eql('0% third')
|
|
|
|
.expect(getNthStatusPollResult(1, 3).innerText).eql('0% fourth')
|
|
|
|
.expect(getNthStatusPollResult(1, 4).exists).notOk()
|
|
|
|
.expect(getNthStatusPollVoteCount(1).innerText).eql('0 votes')
|
|
|
|
})
|
2019-11-01 07:01:35 +01:00
|
|
|
|
|
|
|
test('Properly escapes HTML and emojos in polls', async t => {
|
|
|
|
await loginAsFoobar(t)
|
|
|
|
await t
|
|
|
|
.expect(getNthStatus(1).exists).ok()
|
|
|
|
.click(pollButton)
|
|
|
|
.expect(composePoll.exists).ok()
|
|
|
|
await sleep(1000)
|
|
|
|
await t
|
|
|
|
.typeText(composeInput, 'vote vote vote', { paste: true })
|
|
|
|
.typeText(getComposePollNthInput(1), '–', { paste: true })
|
|
|
|
.typeText(getComposePollNthInput(2), ':blobpeek:', { paste: true })
|
|
|
|
await sleep(1000)
|
|
|
|
await t
|
|
|
|
.click(postStatusButton)
|
|
|
|
.expect(getNthStatusPollResult(1, 1).innerText).contains('–')
|
|
|
|
.expect(getNthStatusPollResult(1, 2).find('img').exists).ok()
|
|
|
|
.expect(getNthStatusPollResult(1, 2).find('img').getAttribute('alt')).eql(':blobpeek:')
|
|
|
|
})
|