2019-11-24 04:11:15 +01:00
|
|
|
import {
|
2019-11-24 08:42:22 +01:00
|
|
|
accountProfileName,
|
|
|
|
closeDialogButton,
|
2019-11-24 04:11:15 +01:00
|
|
|
composeInput,
|
|
|
|
getNthAutosuggestionResult,
|
2019-11-24 08:42:22 +01:00
|
|
|
getNthStatusMediaButton, getNthStatusSensitiveMediaButton,
|
|
|
|
getNthStatus,
|
2019-11-24 04:11:15 +01:00
|
|
|
getNumSyntheticListeners,
|
|
|
|
getUrl,
|
2019-11-24 08:42:22 +01:00
|
|
|
homeNavButton, modalDialog, notificationsNavButton,
|
2019-11-24 04:11:15 +01:00
|
|
|
scrollToStatus,
|
|
|
|
scrollToTop,
|
|
|
|
settingsNavButton, sleep
|
|
|
|
} from '../utils'
|
|
|
|
import { loginAsFoobar } from '../roles'
|
2019-11-24 08:42:22 +01:00
|
|
|
import { installDomListenerListener, getNumDomListeners } from '../spyDomListeners'
|
|
|
|
import { homeTimeline } from '../fixtures'
|
|
|
|
import { Selector as $ } from 'testcafe'
|
2019-11-24 04:11:15 +01:00
|
|
|
|
|
|
|
fixture`038-memory-leaks.js`
|
|
|
|
.page`http://localhost:4002`
|
|
|
|
|
2019-11-24 08:42:22 +01:00
|
|
|
async function runMemoryLeakTest (t, firstStep, secondStep) {
|
|
|
|
await loginAsFoobar(t)
|
|
|
|
await installDomListenerListener()
|
|
|
|
await firstStep()
|
|
|
|
await sleep(1000)
|
|
|
|
const numSyntheticListeners = await getNumSyntheticListeners()
|
|
|
|
const numDomListeners = await getNumDomListeners()
|
|
|
|
await t
|
|
|
|
.expect(numSyntheticListeners).typeOf('number')
|
|
|
|
.expect(numDomListeners).typeOf('number')
|
|
|
|
await secondStep()
|
|
|
|
await sleep(1000)
|
|
|
|
await t
|
|
|
|
.expect(getNumSyntheticListeners()).eql(numSyntheticListeners)
|
|
|
|
.expect(getNumDomListeners()).eql(numDomListeners)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function goToSettings (t) {
|
2019-11-24 04:11:15 +01:00
|
|
|
await t
|
|
|
|
.click(settingsNavButton)
|
|
|
|
.expect(getUrl()).contains('/settings')
|
|
|
|
}
|
|
|
|
|
2019-11-24 08:42:22 +01:00
|
|
|
async function scrollUpAndDownAndDoAutosuggest (t) {
|
2019-11-24 04:11:15 +01:00
|
|
|
await t
|
|
|
|
.click(homeNavButton)
|
|
|
|
.expect(getUrl()).eql('http://localhost:4002/')
|
|
|
|
await scrollToStatus(t, 15)
|
|
|
|
await scrollToTop()
|
|
|
|
await t
|
|
|
|
.typeText(composeInput, 'hey @qu')
|
|
|
|
.expect(getNthAutosuggestionResult(1).find('.sr-only').innerText).contains('@quux')
|
2019-11-24 08:42:22 +01:00
|
|
|
await goToSettings(t)
|
2019-11-24 04:11:15 +01:00
|
|
|
}
|
|
|
|
|
2019-11-24 08:42:22 +01:00
|
|
|
async function openAndCloseMediaModal (t) {
|
2019-11-24 04:11:15 +01:00
|
|
|
await t
|
2019-11-24 08:42:22 +01:00
|
|
|
.click(homeNavButton)
|
|
|
|
.expect(getUrl()).eql('http://localhost:4002/')
|
|
|
|
const idx = homeTimeline.findIndex(_ => _.spoiler === 'kitten CW')
|
|
|
|
await scrollToStatus(t, idx + 1)
|
2019-11-24 04:11:15 +01:00
|
|
|
await t
|
2019-11-24 08:42:22 +01:00
|
|
|
.click(getNthStatusSensitiveMediaButton(idx + 1))
|
|
|
|
.click(getNthStatusMediaButton(idx + 1))
|
|
|
|
.expect(modalDialog.hasAttribute('aria-hidden')).notOk()
|
|
|
|
.click(closeDialogButton)
|
|
|
|
.expect(modalDialog.exists).notOk()
|
|
|
|
await goToSettings(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function openAProfileAndNotifications (t) {
|
|
|
|
await t
|
|
|
|
.click(homeNavButton)
|
|
|
|
.expect(getUrl()).eql('http://localhost:4002/')
|
|
|
|
.hover(getNthStatus(1))
|
|
|
|
.click($('.status-author-name').withText(('quux')))
|
|
|
|
.expect(getUrl()).contains('/accounts/3')
|
|
|
|
.expect(accountProfileName.innerText).contains('quux')
|
|
|
|
.click(notificationsNavButton)
|
|
|
|
.hover(getNthStatus(1))
|
|
|
|
await goToSettings(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
test('Does not leak listeners in timeline or autosuggest', async t => {
|
|
|
|
await runMemoryLeakTest(
|
|
|
|
t,
|
|
|
|
() => goToSettings(t),
|
|
|
|
() => scrollUpAndDownAndDoAutosuggest(t)
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('Does not leak listeners in modal', async t => {
|
|
|
|
await runMemoryLeakTest(
|
|
|
|
t,
|
|
|
|
() => goToSettings(t),
|
|
|
|
() => openAndCloseMediaModal(t)
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('Does not leak listeners in account profile or notifications page', async t => {
|
|
|
|
await runMemoryLeakTest(
|
|
|
|
t,
|
|
|
|
() => goToSettings(t),
|
|
|
|
() => openAProfileAndNotifications(t)
|
|
|
|
)
|
2019-11-24 04:11:15 +01:00
|
|
|
})
|