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