1
0
mirror of https://github.com/nolanlawson/pinafore synced 2024-12-13 02:37:20 +01:00
Pinafore-Web-Client-Frontend/tests/spec/025-shortcuts-status.js
Sorin Davidoi 77bb784efd feat(media): Blurhash (#1381)
* chore(npm): Install blurhash

* feat(media): Show blurhash

* fix(media/blurhash): Better sensitive video handling

* feat(media): Preference for using blurhash

* chore(utils/blurhash): Add performance marks

* fix(utils/blurhash): Performance marks

* fix(utils/blurhash): Use correct dimension

* refactor(utils/blurhash): Use constant for number of pixels

* refactor(media): Simplify logic for displaying blurhash

* chore(tests/spec): Attempt to adjust sensitivity tests for blurhash

* chore(tests/spec): Update sensitivity tests for blurhash

* chore(tests/spec): Check for sensitive

* fix(media/blurhash): Handle videos

* fix: Video handling

* fix: Videos

* minor refactoring, fix Svelte warning

* fix: Large inline images and videos

* feat(settings): Rename blurhash setting

* refactor: Use toBlob, block media rendering until blurhash ready

* refactor: Move computations to Web Worker

* fix(workers/blurhash): More error handling

* feat(workers/blurhash): Use quick-lru for caching

* fix: Don't create Context2D needlessly

* fix(workers/blurhash): Increase cache size to 100

* fix(workers/blurhash): Don't resolve promise twice

* fix(utils/decode-image): Ignore data URLs

Throws exception which prevents the image from loading.
2019-08-17 10:54:45 -07:00

217 lines
7.1 KiB
JavaScript

import {
closeDialogButton,
composeModalInput,
getNthFavorited,
getNthStatus,
getNthStatusContent,
getNthStatusMediaImg,
getNthStatusSensitiveMediaButton,
getNthStatusSpoiler,
getUrl, modalDialog,
scrollToStatus,
isNthStatusActive, getActiveElementRectTop, scrollToTop, isActiveStatusPinned
} from '../utils'
import { homeTimeline } from '../fixtures'
import { loginAsFoobar } from '../roles'
import { Selector as $ } from 'testcafe'
fixture`025-shortcuts-status.js`
.page`http://localhost:4002`
async function activateStatus (t, idx) {
const timeout = 20000
for (let i = 0; i <= idx; i++) {
await t.expect(getNthStatus(1 + i).exists).ok({ timeout })
.pressKey('j')
.expect(isNthStatusActive(1 + i)()).ok()
}
}
test('Shortcut j/k change the active status', async t => {
await loginAsFoobar(t)
await t
.expect(getUrl()).eql('http://localhost:4002/')
.expect(getNthStatus(1).exists).ok({ timeout: 30000 })
.expect(isNthStatusActive(1)()).notOk()
.pressKey('j')
.expect(isNthStatusActive(1)()).ok()
.pressKey('j')
.expect(isNthStatusActive(2)()).ok()
.pressKey('j')
.expect(isNthStatusActive(3)()).ok()
.pressKey('j')
.expect(isNthStatusActive(4)()).ok()
.pressKey('k')
.expect(isNthStatusActive(3)()).ok()
.pressKey('k')
.expect(isNthStatusActive(2)()).ok()
.pressKey('k')
.expect(isNthStatusActive(1)()).ok()
.expect(isNthStatusActive(2)()).notOk()
.expect(isNthStatusActive(3)()).notOk()
.expect(isNthStatusActive(4)()).notOk()
})
test('Shortcut j goes to the first visible status', async t => {
await loginAsFoobar(t)
await t
.expect(getUrl()).eql('http://localhost:4002/')
await scrollToStatus(t, 11)
await t
.expect(getNthStatus(11).exists).ok({ timeout: 30000 })
.pressKey('j')
.expect(getActiveElementRectTop()).gte(0)
})
test('Shortcut o opens active status, backspace goes back', async t => {
await loginAsFoobar(t)
await t
.expect(getUrl()).eql('http://localhost:4002/')
.expect(getNthStatus(3).exists).ok({ timeout: 30000 })
.pressKey('j') // activates status 0
.pressKey('j') // activates status 1
.pressKey('j') // activates status 2
.expect(isNthStatusActive(3)()).ok()
.pressKey('o')
.expect(getUrl()).contains('/statuses/')
.pressKey('Backspace')
.expect(isNthStatusActive(3)()).ok()
})
test('Shortcut x shows/hides spoilers', async t => {
const idx = homeTimeline.findIndex(_ => _.spoiler === 'kitten CW')
await loginAsFoobar(t)
await t
.expect(getUrl()).eql('http://localhost:4002/')
await activateStatus(t, idx)
await t
.expect(isNthStatusActive(1 + idx)()).ok()
.expect(getNthStatusSpoiler(1 + idx).innerText).contains('kitten CW')
.expect(getNthStatusContent(1 + idx).hasClass('shown')).notOk()
.pressKey('x')
.expect(getNthStatusContent(1 + idx).hasClass('shown')).ok()
.pressKey('x')
.expect(getNthStatusContent(1 + idx).hasClass('shown')).notOk()
})
test('Shortcut y shows/hides sensitive image', async t => {
const idx = homeTimeline.findIndex(_ => _.content === "here's a secret kitten")
await loginAsFoobar(t)
await t
.expect(getUrl()).eql('http://localhost:4002/')
await activateStatus(t, idx)
await t
.expect(isNthStatusActive(1 + idx)()).ok()
.expect(getNthStatusSensitiveMediaButton(1 + idx).exists).ok()
.expect(getNthStatusMediaImg(1 + idx).getAttribute('src')).match(/^blob:http:\/\/localhost/)
.pressKey('y')
.expect(getNthStatusMediaImg(1 + idx).getAttribute('src')).match(/^http:\/\//)
.pressKey('y')
.expect(getNthStatusMediaImg(1 + idx).getAttribute('src')).match(/^blob:http:\/\/localhost/)
})
test('Shortcut f toggles favorite status', async t => {
const idx = homeTimeline.findIndex(_ => _.content === 'this is unlisted')
await loginAsFoobar(t)
await t
.expect(getUrl()).eql('http://localhost:4002/')
.expect(getNthStatus(1 + idx).exists).ok({ timeout: 30000 })
.expect(getNthFavorited(1 + idx)).eql('false')
.pressKey('j '.repeat(idx + 1))
.expect(isNthStatusActive(1 + idx)()).ok()
.pressKey('f')
.expect(getNthFavorited(1 + idx)).eql('true')
.pressKey('f')
.expect(getNthFavorited(1 + idx)).eql('false')
})
test('Shortcut p toggles profile', async t => {
const idx = homeTimeline.findIndex(_ => _.content === 'pinned toot 1')
await loginAsFoobar(t)
await t
.expect(getUrl()).eql('http://localhost:4002/')
.expect(getNthStatus(1 + idx).exists).ok({ timeout: 30000 })
.pressKey('j '.repeat(idx + 1))
.expect(isNthStatusActive(1 + idx)()).ok()
.pressKey('p')
.expect(getUrl()).contains('/accounts/3')
})
test('Shortcut m toggles mention', async t => {
const idx = homeTimeline.findIndex(_ => _.content === 'pinned toot 1')
await loginAsFoobar(t)
await t
.expect(getUrl()).eql('http://localhost:4002/')
.expect(getNthStatus(1 + idx).exists).ok({ timeout: 30000 })
.pressKey('j '.repeat(idx + 1))
.expect(isNthStatusActive(1 + idx)()).ok()
.pressKey('m')
.expect(composeModalInput.value).eql('@quux ')
.click(closeDialogButton)
.expect(modalDialog.exists).notOk()
})
test('Shortcut j/k change the active status on a thread', async t => {
await loginAsFoobar(t)
await t
.click($('a').withText('quux'))
await scrollToStatus(t, 3)
await t
.click(getNthStatus(3))
.expect(getUrl()).contains('/statuses')
await scrollToStatus(t, 1)
await scrollToTop()
await t
.expect(getNthStatus(1).exists).ok({ timeout: 30000 })
.expect(isNthStatusActive(1)()).notOk()
.pressKey('j')
.expect(isNthStatusActive(1)()).ok()
.pressKey('j')
.expect(isNthStatusActive(2)()).ok()
.pressKey('j')
.expect(isNthStatusActive(3)()).ok()
.pressKey('j')
.expect(isNthStatusActive(4)()).ok()
.pressKey('k')
.expect(isNthStatusActive(3)()).ok()
.pressKey('k')
.expect(isNthStatusActive(2)()).ok()
.pressKey('k')
.expect(isNthStatusActive(1)()).ok()
.expect(isNthStatusActive(2)()).notOk()
.expect(isNthStatusActive(3)()).notOk()
.expect(isNthStatusActive(4)()).notOk()
})
test('Shortcut j/k change the active status on pinned statuses', async t => {
await loginAsFoobar(t)
await t
.click($('a').withText('quux'))
.expect(getUrl()).contains('/accounts')
await t
.expect(getNthStatus(1).exists).ok({ timeout: 30000 })
.expect(isNthStatusActive(1)()).notOk()
.pressKey('j')
.expect(isNthStatusActive(1)()).ok()
.expect(isActiveStatusPinned()).eql(true)
.pressKey('j')
.expect(isNthStatusActive(2)()).ok()
.expect(isActiveStatusPinned()).eql(true)
.pressKey('j')
.expect(isNthStatusActive(1)()).ok()
.expect(isActiveStatusPinned()).eql(false)
.pressKey('j')
.expect(isNthStatusActive(2)()).ok()
.expect(isActiveStatusPinned()).eql(false)
.pressKey('k')
.expect(isNthStatusActive(1)()).ok()
.expect(isActiveStatusPinned()).eql(false)
.pressKey('k')
.expect(isNthStatusActive(2)()).ok()
.expect(isActiveStatusPinned()).eql(true)
.pressKey('k')
.expect(isNthStatusActive(1)()).ok()
.expect(isActiveStatusPinned()).eql(true)
})