2018-02-20 01:04:37 +00:00
|
|
|
import { Selector as $ } from 'testcafe'
|
2018-03-01 06:45:42 +00:00
|
|
|
import {
|
|
|
|
authorizeInput, emailInput, formError, getUrl, instanceInput, passwordInput,
|
|
|
|
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
|
|
|
|
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')
|
2018-03-01 06:45:42 +00:00
|
|
|
.pressKey('enter')
|
2018-02-20 02:24:22 +00:00
|
|
|
.expect(getUrl()).eql('http://localhost:3000/auth/sign_in')
|
2018-03-01 06:45:42 +00:00
|
|
|
.typeText(emailInput, username, {paste: true})
|
|
|
|
.typeText(passwordInput, password, {paste: true})
|
|
|
|
.pressKey('enter')
|
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-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-03-01 06:45:42 +00:00
|
|
|
.typeText(instanceInput, 'fake.nolanlawson.com', {paste: true})
|
|
|
|
.pressKey('enter')
|
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
|
|
|
.typeText(instanceInput, '.biz', {paste: true})
|
2018-02-20 01:04:37 +00:00
|
|
|
.expect(formError.exists).notOk()
|
2018-03-01 06:45:42 +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-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()
|
|
|
|
.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'))
|
|
|
|
.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
|
|
|
})
|