2018-02-20 01:04:37 +00:00
|
|
|
import { Selector as $ } from 'testcafe'
|
2018-02-20 02:25:59 +00:00
|
|
|
import { addInstanceButton, getUrl, instanceInput, settingsButton } from '../utils'
|
2018-02-20 01:04:37 +00:00
|
|
|
|
2018-02-20 02:25:59 +00:00
|
|
|
fixture`02-login-spec.js`
|
|
|
|
.page`http://localhost:4002`
|
2018-02-20 01:04:37 +00:00
|
|
|
|
|
|
|
const formError = $('.form-error')
|
|
|
|
|
2018-02-20 02:25:59 +00:00
|
|
|
function manualLogin (t, username, password) {
|
2018-02-20 02:24:22 +00:00
|
|
|
return t.click($('a').withText('log in to an instance'))
|
|
|
|
.expect(getUrl()).contains('/settings/instances/add')
|
|
|
|
.typeText(instanceInput, 'localhost:3000')
|
|
|
|
.click(addInstanceButton)
|
|
|
|
.expect(getUrl()).eql('http://localhost:3000/auth/sign_in')
|
|
|
|
.typeText($('input#user_email'), username)
|
|
|
|
.typeText($('input#user_password'), password)
|
|
|
|
.click($('button[type=submit]'))
|
|
|
|
.expect(getUrl()).contains('/oauth/authorize')
|
|
|
|
.click($('button[type=submit]:not(.negative)'))
|
|
|
|
.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-02-20 01:04:37 +00:00
|
|
|
await t.click($('a').withText('log in to an instance'))
|
2018-02-20 01:18:40 +00:00
|
|
|
.expect(getUrl()).contains('/settings/instances/add')
|
2018-02-20 01:04:37 +00:00
|
|
|
.typeText(instanceInput, 'fake.nolanlawson.com')
|
|
|
|
.click(addInstanceButton)
|
|
|
|
.expect(formError.exists).ok()
|
|
|
|
.expect(formError.innerText).contains('Is this a valid Mastodon instance?')
|
|
|
|
.typeText(instanceInput, '.biz')
|
|
|
|
.expect(formError.exists).notOk()
|
|
|
|
.typeText(instanceInput, 'fake.nolanlawson.com', {replace: true})
|
|
|
|
.expect(formError.exists).ok()
|
|
|
|
.expect(formError.innerText).contains('Is this a valid Mastodon instance?')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('Logs in to localhost:3000', async t => {
|
2018-02-20 02:24:22 +00:00
|
|
|
await manualLogin(t, 'foobar@localhost:3000', 'foobarfoobar')
|
2018-02-20 01:04:37 +00:00
|
|
|
.expect($('article.status-article').exists).ok()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('Logs out', async t => {
|
2018-02-20 02:24:22 +00:00
|
|
|
await manualLogin(t, 'foobar@localhost:3000', 'foobarfoobar')
|
2018-02-20 01:04:37 +00:00
|
|
|
.click(settingsButton)
|
|
|
|
.click($('a').withText('Instances'))
|
|
|
|
.click($('a').withText('localhost:3000'))
|
|
|
|
.expect(getUrl()).contains('/settings/instances/localhost:3000')
|
|
|
|
.click($('button').withText('Log out'))
|
|
|
|
.click($('#modal-dialog button').withText('OK'))
|
|
|
|
.expect($('.container').innerText)
|
|
|
|
.contains("You're not logged in to any instances")
|
2018-02-20 02:25:59 +00:00
|
|
|
})
|