pinafore/tests/spec/100-favorite-unfavorite.js

99 lines
3.2 KiB
JavaScript
Raw Permalink Normal View History

2018-02-24 22:49:28 +00:00
import {
getFavoritesCount,
getNthFavoriteButton,
getNthFavoritedLabel,
getNthStatus,
getNthStatusContent,
getUrl,
homeNavButton,
notificationsNavButton,
scrollToBottom,
scrollToTop,
sleep
2018-02-24 22:49:28 +00:00
} from '../utils'
import { loginAsFoobar } from '../roles'
import { favoriteStatusAs, postAs } from '../serverActions'
2018-02-24 22:49:28 +00:00
fixture`100-favorite-unfavorite.js`
2018-02-24 22:49:28 +00:00
.page`http://localhost:4002`
test('favorites a status', async t => {
await postAs('admin', 'favorite me!!!')
await loginAsFoobar(t)
await t
.expect(getNthStatusContent(1).innerText).contains('favorite me')
.hover(getNthStatus(1))
.expect(getNthFavoritedLabel(1)).eql('Favorite')
.click(getNthFavoriteButton(1))
.expect(getNthFavoritedLabel(1)).eql('Unfavorite')
2018-02-24 22:49:28 +00:00
// scroll down and back up to force an unrender
2018-11-22 06:08:37 +00:00
await scrollToBottom()
await sleep(1)
await scrollToTop()
2018-02-24 22:49:28 +00:00
await t
.hover(getNthStatus(1))
.expect(getNthFavoritedLabel(1)).eql('Unfavorite')
2018-02-24 22:49:28 +00:00
.click(notificationsNavButton)
.click(homeNavButton)
.expect(getNthFavoritedLabel(1)).eql('Unfavorite')
2018-02-24 22:49:28 +00:00
.click(notificationsNavButton)
.expect(getUrl()).contains('/notifications')
.click(homeNavButton)
.expect(getUrl()).eql('http://localhost:4002/')
.hover(getNthStatus(1))
.expect(getNthFavoritedLabel(1)).eql('Unfavorite')
.click(getNthFavoriteButton(1))
.expect(getNthFavoritedLabel(1)).eql('Favorite')
2018-02-24 22:49:28 +00:00
})
test('unfavorites a status', async t => {
const { id: statusId } = await postAs('admin', 'favorite this one too')
await favoriteStatusAs('foobar', statusId)
await loginAsFoobar(t)
await t
.expect(getNthStatusContent(1).innerText).contains('favorite this one too')
.expect(getNthFavoritedLabel(1)).eql('Unfavorite')
.click(getNthFavoriteButton(1))
.expect(getNthFavoritedLabel(1)).eql('Favorite')
2018-02-24 22:49:28 +00:00
// scroll down and back up to force an unrender
2018-11-22 06:08:37 +00:00
await scrollToBottom()
await sleep(1)
await scrollToTop()
2018-02-24 22:49:28 +00:00
await t
.expect(getNthFavoritedLabel(1)).eql('Favorite')
2018-02-24 22:49:28 +00:00
.click(notificationsNavButton)
.click(homeNavButton)
.expect(getNthFavoritedLabel(1)).eql('Favorite')
2018-02-24 22:49:28 +00:00
.click(notificationsNavButton)
.navigateTo('/')
.expect(getNthFavoritedLabel(1)).eql('Favorite')
.click(getNthFavoriteButton(1))
.expect(getNthFavoritedLabel(1)).eql('Unfavorite')
2018-02-24 22:49:28 +00:00
})
2018-02-25 02:20:33 +00:00
test('Keeps the correct favorites count', async t => {
const { id: statusId } = await postAs('admin', 'favorite this twice pls')
await favoriteStatusAs('quux', statusId)
await loginAsFoobar(t)
await t
.expect(getNthStatusContent(1).innerText).contains('favorite this twice pls')
.hover(getNthStatus(1))
.click(getNthFavoriteButton(1))
.expect(getNthFavoritedLabel(1)).eql('Unfavorite')
.click(getNthStatus(1))
2018-02-24 22:49:28 +00:00
.expect(getUrl()).contains('/status')
.expect(getNthFavoritedLabel(1)).eql('Unfavorite')
2018-02-24 22:49:28 +00:00
.expect(getFavoritesCount()).eql(2)
.click(homeNavButton)
.expect(getUrl()).eql('http://localhost:4002/')
.hover(getNthStatus(1))
.click(getNthFavoriteButton(1))
.expect(getNthFavoritedLabel(1)).eql('Favorite')
.click(getNthStatus(1))
2018-02-24 22:49:28 +00:00
.expect(getUrl()).contains('/status')
.expect(getNthFavoritedLabel(1)).eql('Favorite')
2018-02-24 22:49:28 +00:00
.expect(getFavoritesCount()).eql(1)
})