1
0
mirror of https://github.com/nolanlawson/pinafore synced 2025-02-09 16:08:48 +01:00
Pinafore-Web-Client-Frontend/tests/spec/013-compose-media.js

58 lines
2.5 KiB
JavaScript
Raw Normal View History

2018-03-03 11:26:10 -08:00
import { composeInput, getNthDeleteMediaButton, getNthMedia, mediaButton, uploadKittenImage } from '../utils'
2018-03-02 21:55:04 -08:00
import { foobarRole } from '../roles'
2018-03-06 21:32:51 -08:00
fixture`013-compose-media.js`
2018-03-02 21:55:04 -08:00
.page`http://localhost:4002`
test('inserts media', async t => {
await t.useRole(foobarRole)
.expect(mediaButton.hasAttribute('disabled')).notOk()
await (uploadKittenImage(1)())
await t.expect(getNthMedia(1).getAttribute('alt')).eql('kitten1.jpg')
await (uploadKittenImage(2)())
await t.expect(getNthMedia(1).getAttribute('alt')).eql('kitten1.jpg')
.expect(getNthMedia(2).getAttribute('alt')).eql('kitten2.jpg')
.expect(mediaButton.hasAttribute('disabled')).notOk()
await (uploadKittenImage(3)())
await t.expect(getNthMedia(1).getAttribute('alt')).eql('kitten1.jpg')
.expect(getNthMedia(2).getAttribute('alt')).eql('kitten2.jpg')
.expect(getNthMedia(3).getAttribute('alt')).eql('kitten3.jpg')
.expect(mediaButton.hasAttribute('disabled')).notOk()
await (uploadKittenImage(4)())
await t.expect(getNthMedia(1).getAttribute('alt')).eql('kitten1.jpg')
.expect(getNthMedia(2).getAttribute('alt')).eql('kitten2.jpg')
.expect(getNthMedia(3).getAttribute('alt')).eql('kitten3.jpg')
.expect(getNthMedia(4).getAttribute('alt')).eql('kitten4.jpg')
.expect(mediaButton.getAttribute('disabled')).eql('')
2018-03-03 10:27:14 -08:00
.click(getNthDeleteMediaButton(4))
.click(getNthDeleteMediaButton(3))
.click(getNthDeleteMediaButton(2))
.click(getNthDeleteMediaButton(1))
2018-03-02 21:55:04 -08:00
})
test('removes media', async t => {
await t.useRole(foobarRole)
await (uploadKittenImage(1)())
2018-03-03 15:44:43 -08:00
await t.expect(getNthMedia(1).getAttribute('alt')).eql('kitten1.jpg')
2018-03-02 21:55:04 -08:00
await (uploadKittenImage(2)())
await t.expect(getNthMedia(1).getAttribute('alt')).eql('kitten1.jpg')
.expect(getNthMedia(2).getAttribute('alt')).eql('kitten2.jpg')
2018-03-03 10:27:14 -08:00
.click(getNthDeleteMediaButton(2))
2018-03-02 21:55:04 -08:00
.expect(getNthMedia(2).exists).notOk()
.expect(getNthMedia(1).exists).ok()
2018-03-03 11:26:10 -08:00
.click(getNthDeleteMediaButton(1))
.expect(getNthMedia(2).exists).notOk()
})
test('changes URLs as media is added/removed', async t => {
await t.useRole(foobarRole)
await (uploadKittenImage(1)())
await t.expect(composeInput.value).match(/^ http:\/\/localhost:3000\/media\/\S+$/)
await (uploadKittenImage(1)())
await t.expect(composeInput.value).match(/^ http:\/\/localhost:3000\/media\/\S+ http:\/\/localhost:3000\/media\/\S+$/)
.click(getNthDeleteMediaButton(1))
.expect(composeInput.value).match(/^ http:\/\/localhost:3000\/media\/\S+$/)
.click(getNthDeleteMediaButton(1))
.expect(composeInput.value).eql('')
2018-03-02 21:55:04 -08:00
})