2018-02-20 01:04:37 +00:00
|
|
|
import { Selector as $ } from 'testcafe'
|
2018-03-01 06:45:42 +00:00
|
|
|
import {
|
2018-04-21 20:06:46 +00:00
|
|
|
addInstanceButton,
|
2018-12-14 08:25:12 +00:00
|
|
|
authorizeInput,
|
|
|
|
emailInput,
|
|
|
|
formError,
|
2018-12-16 20:39:16 +00:00
|
|
|
getFirstVisibleStatus, getNthStatus, getOpacity,
|
2018-12-14 08:25:12 +00:00
|
|
|
getUrl,
|
|
|
|
homeNavButton,
|
|
|
|
instanceInput,
|
|
|
|
logInToInstanceLink,
|
2018-04-21 20:06:46 +00:00
|
|
|
mastodonLogInButton,
|
2018-12-14 08:25:12 +00:00
|
|
|
passwordInput, reload,
|
2018-05-25 03:01:34 +00:00
|
|
|
settingsButton,
|
|
|
|
sleep
|
2018-03-01 06:45:42 +00:00
|
|
|
} from '../utils'
|
2018-12-16 20:39:16 +00:00
|
|
|
import { loginAsFoobar } from '../roles'
|
2018-02-20 01:04:37 +00:00
|
|
|
|
2018-03-07 05:32:51 +00:00
|
|
|
fixture`002-login-spec.js`
|
2018-02-20 02:25:59 +00:00
|
|
|
.page`http://localhost:4002`
|
2018-02-20 01:04:37 +00:00
|
|
|
|
2018-02-20 02:25:59 +00:00
|
|
|
function manualLogin (t, username, password) {
|
2018-03-07 07:57:06 +00:00
|
|
|
return t.click(logInToInstanceLink)
|
2018-02-20 02:24:22 +00:00
|
|
|
.expect(getUrl()).contains('/settings/instances/add')
|
|
|
|
.typeText(instanceInput, 'localhost:3000')
|
2018-04-21 20:06:46 +00:00
|
|
|
.click(addInstanceButton)
|
2018-08-30 04:42:57 +00:00
|
|
|
.expect(getUrl()).eql('http://localhost:3000/auth/sign_in', { timeout: 30000 })
|
|
|
|
.typeText(emailInput, username, { paste: true })
|
|
|
|
.typeText(passwordInput, password, { paste: true })
|
2018-04-21 20:06:46 +00:00
|
|
|
.click(mastodonLogInButton)
|
2018-02-20 02:24:22 +00:00
|
|
|
.expect(getUrl()).contains('/oauth/authorize')
|
2018-03-01 06:45:42 +00:00
|
|
|
.click(authorizeInput)
|
2018-02-20 02:24:22 +00:00
|
|
|
.expect(getUrl()).eql('http://localhost:4002/')
|
|
|
|
}
|
|
|
|
|
2018-02-20 01:18:40 +00:00
|
|
|
test('Cannot log in to a fake instance', async t => {
|
2018-05-25 03:01:34 +00:00
|
|
|
await sleep(500)
|
2018-03-07 07:57:06 +00:00
|
|
|
await t.click(logInToInstanceLink)
|
2018-02-20 01:18:40 +00:00
|
|
|
.expect(getUrl()).contains('/settings/instances/add')
|
2018-08-30 04:42:57 +00:00
|
|
|
.typeText(instanceInput, 'fake.nolanlawson.com', { paste: true })
|
2018-04-21 20:06:46 +00:00
|
|
|
.click(addInstanceButton)
|
2018-02-20 01:04:37 +00:00
|
|
|
.expect(formError.exists).ok()
|
|
|
|
.expect(formError.innerText).contains('Is this a valid Mastodon instance?')
|
2018-08-30 04:42:57 +00:00
|
|
|
.typeText(instanceInput, '.biz', { paste: true })
|
2018-02-20 01:04:37 +00:00
|
|
|
.expect(formError.exists).notOk()
|
2018-08-30 04:42:57 +00:00
|
|
|
.typeText(instanceInput, 'fake.nolanlawson.com', { paste: true, replace: true })
|
2018-02-20 01:04:37 +00:00
|
|
|
.expect(formError.exists).ok()
|
|
|
|
.expect(formError.innerText).contains('Is this a valid Mastodon instance?')
|
|
|
|
})
|
|
|
|
|
2018-03-01 06:45:42 +00:00
|
|
|
test('Logs in and logs out of localhost:3000', async t => {
|
2018-05-25 03:01:34 +00:00
|
|
|
await sleep(500)
|
2018-02-20 02:24:22 +00:00
|
|
|
await manualLogin(t, 'foobar@localhost:3000', 'foobarfoobar')
|
2018-03-04 20:46:46 +00:00
|
|
|
.expect(getUrl()).eql('http://localhost:4002/')
|
|
|
|
.hover(getFirstVisibleStatus())
|
2018-02-20 01:04:37 +00:00
|
|
|
.expect($('article.status-article').exists).ok()
|
|
|
|
.click(settingsButton)
|
|
|
|
.click($('a').withText('Instances'))
|
|
|
|
.click($('a').withText('localhost:3000'))
|
|
|
|
.expect(getUrl()).contains('/settings/instances/localhost:3000')
|
2018-02-25 22:06:36 +00:00
|
|
|
.expect($('.instance-name-h1').innerText).eql('localhost:3000')
|
|
|
|
.expect($('.acct-handle').innerText).eql('@foobar')
|
|
|
|
.expect($('.acct-display-name').innerText).eql('foobar')
|
2018-02-20 01:04:37 +00:00
|
|
|
.click($('button').withText('Log out'))
|
2018-04-01 05:08:24 +00:00
|
|
|
.click($('.modal-dialog button').withText('OK'))
|
2018-12-14 08:25:12 +00:00
|
|
|
.expect($('.main-content').innerText).contains("You're not logged in to any instances")
|
|
|
|
.click(homeNavButton)
|
|
|
|
// check that the "hidden from SSR" content is visible
|
|
|
|
.expect(getOpacity('.hidden-from-ssr')()).eql('1')
|
|
|
|
.navigateTo('/')
|
|
|
|
.expect(getOpacity('.hidden-from-ssr')()).eql('1')
|
|
|
|
await reload()
|
|
|
|
await t
|
|
|
|
.expect(getOpacity('.hidden-from-ssr')()).eql('1')
|
2018-02-20 02:25:59 +00:00
|
|
|
})
|
2018-12-16 20:39:16 +00:00
|
|
|
|
|
|
|
test('Logs in, refreshes, then logs out', async t => {
|
|
|
|
await loginAsFoobar(t)
|
|
|
|
await t
|
|
|
|
.hover(getNthStatus(0))
|
|
|
|
await reload()
|
|
|
|
await t
|
|
|
|
.hover(getNthStatus(0))
|
|
|
|
.click(settingsButton)
|
|
|
|
.click($('a').withText('Instances'))
|
|
|
|
.click($('a').withText('localhost:3000'))
|
|
|
|
.expect(getUrl()).contains('/settings/instances/localhost:3000')
|
|
|
|
.expect($('.instance-name-h1').innerText).eql('localhost:3000')
|
|
|
|
.expect($('.acct-handle').innerText).eql('@foobar')
|
|
|
|
.expect($('.acct-display-name').innerText).eql('foobar')
|
|
|
|
.click($('button').withText('Log out'))
|
|
|
|
.click($('.modal-dialog button').withText('OK'))
|
|
|
|
.expect($('.main-content').innerText).contains("You're not logged in to any instances")
|
|
|
|
.click(homeNavButton)
|
|
|
|
.expect(getOpacity('.hidden-from-ssr')()).eql('1')
|
|
|
|
})
|