pinafore/tests/spec/002-login-spec.js

61 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-02-19 17:04:37 -08:00
import { Selector as $ } from 'testcafe'
2018-02-28 22:45:42 -08:00
import {
2018-04-21 13:06:46 -07:00
addInstanceButton,
2018-03-06 23:57:06 -08:00
authorizeInput, emailInput, formError, getFirstVisibleStatus, getUrl, instanceInput, logInToInstanceLink,
2018-04-21 13:06:46 -07:00
mastodonLogInButton,
2018-03-06 23:57:06 -08:00
passwordInput,
settingsButton,
sleep
2018-02-28 22:45:42 -08:00
} from '../utils'
2018-02-19 17:04:37 -08:00
2018-03-06 21:32:51 -08:00
fixture`002-login-spec.js`
2018-02-19 18:25:59 -08:00
.page`http://localhost:4002`
2018-02-19 17:04:37 -08:00
2018-02-19 18:25:59 -08:00
function manualLogin (t, username, password) {
2018-03-06 23:57:06 -08:00
return t.click(logInToInstanceLink)
2018-02-19 18:24:22 -08:00
.expect(getUrl()).contains('/settings/instances/add')
.typeText(instanceInput, 'localhost:3000')
2018-04-21 13:06:46 -07:00
.click(addInstanceButton)
.expect(getUrl()).eql('http://localhost:3000/auth/sign_in', { timeout: 30000 })
.typeText(emailInput, username, { paste: true })
.typeText(passwordInput, password, { paste: true })
2018-04-21 13:06:46 -07:00
.click(mastodonLogInButton)
2018-02-19 18:24:22 -08:00
.expect(getUrl()).contains('/oauth/authorize')
2018-02-28 22:45:42 -08:00
.click(authorizeInput)
2018-02-19 18:24:22 -08:00
.expect(getUrl()).eql('http://localhost:4002/')
}
2018-02-19 17:18:40 -08:00
test('Cannot log in to a fake instance', async t => {
await sleep(500)
2018-03-06 23:57:06 -08:00
await t.click(logInToInstanceLink)
2018-02-19 17:18:40 -08:00
.expect(getUrl()).contains('/settings/instances/add')
.typeText(instanceInput, 'fake.nolanlawson.com', { paste: true })
2018-04-21 13:06:46 -07:00
.click(addInstanceButton)
2018-02-19 17:04:37 -08:00
.expect(formError.exists).ok()
.expect(formError.innerText).contains('Is this a valid Mastodon instance?')
.typeText(instanceInput, '.biz', { paste: true })
2018-02-19 17:04:37 -08:00
.expect(formError.exists).notOk()
.typeText(instanceInput, 'fake.nolanlawson.com', { paste: true, replace: true })
2018-02-19 17:04:37 -08:00
.expect(formError.exists).ok()
.expect(formError.innerText).contains('Is this a valid Mastodon instance?')
})
2018-02-28 22:45:42 -08:00
test('Logs in and logs out of localhost:3000', async t => {
await sleep(500)
2018-02-19 18:24:22 -08:00
await manualLogin(t, 'foobar@localhost:3000', 'foobarfoobar')
2018-03-04 12:46:46 -08:00
.expect(getUrl()).eql('http://localhost:4002/')
.hover(getFirstVisibleStatus())
2018-02-19 17:04:37 -08: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 14:06:36 -08:00
.expect($('.instance-name-h1').innerText).eql('localhost:3000')
.expect($('.acct-handle').innerText).eql('@foobar')
.expect($('.acct-display-name').innerText).eql('foobar')
2018-02-19 17:04:37 -08:00
.click($('button').withText('Log out'))
2018-03-31 22:08:24 -07:00
.click($('.modal-dialog button').withText('OK'))
.expect($('.main-content').innerText)
2018-02-19 17:04:37 -08:00
.contains("You're not logged in to any instances")
2018-02-19 18:25:59 -08:00
})