diff --git a/webapp/components/features/FollowList/FollowList.spec.js b/webapp/components/features/FollowList/FollowList.spec.js
index 38efd5bd8..6bda73acc 100644
--- a/webapp/components/features/FollowList/FollowList.spec.js
+++ b/webapp/components/features/FollowList/FollowList.spec.js
@@ -10,29 +10,50 @@ config.stubs['client-only'] = ''
config.stubs['ds-space'] = ''
config.stubs['nuxt-link'] = ''
+const user = {
+ ...helpers.fakeUser()[0],
+ followedByCount: 12,
+ followingCount: 15,
+ followedBy: helpers.fakeUser(7),
+ following: helpers.fakeUser(7),
+}
+
+const allConnectionsUser = {
+ ...user,
+ followedBy: [
+ ...user.followedBy,
+ ...helpers.fakeUser(user.followedByCount - user.followedBy.length),
+ ],
+ following: [...user.following, ...helpers.fakeUser(user.followingCount - user.following.length)],
+}
+
+const noConnectionsUser = {
+ ...user,
+ followedByCount: 0,
+ followingCount: 0,
+ followedBy: [],
+ following: [],
+}
+
describe('FollowList.vue', () => {
- let store, mocks, getters, propsData
+ let store, getters
+ const Wrapper = (customProps) =>
+ mount(FollowList, {
+ store,
+ propsData: { user, ...customProps },
+ mocks: {
+ $t: jest.fn((str) => str),
+ },
+ localVue,
+ })
beforeAll(() => {
- mocks = {
- $t: jest.fn(),
- }
getters = {
'auth/user': () => {
return {}
},
'auth/isModerator': () => false,
}
- const [_user] = helpers.fakeUser()
- propsData = {
- user: {
- ..._user,
- followedByCount: 12,
- followingCount: 15,
- followedBy: helpers.fakeUser(7),
- following: helpers.fakeUser(7),
- },
- }
})
describe('mount', () => {
@@ -42,88 +63,71 @@ describe('FollowList.vue', () => {
})
})
- describe('given a user with connections', () => {
- ;['following', 'followedBy'].forEach((type) =>
- describe(`and type=${type}`, () => {
- let wrapper
- let queryMock
+ describe('given a user', () => {
+ describe('without connections', () => {
+ it('displays the followingNobody message', () => {
+ const wrapper = Wrapper({ user: noConnectionsUser })
+ expect(wrapper.find('.no-connections').text()).toBe(
+ `${noConnectionsUser.name} ${wrapper.vm.$t(`profile.network.followingNobody`)}`,
+ )
+ })
- beforeAll(() => {
- queryMock = jest.fn().mockResolvedValue({
- data: { User: [{ [type]: additionalConnections[type] }] },
- })
+ it('displays the followedByNobody message', () => {
+ const wrapper = Wrapper({ user: noConnectionsUser, type: 'followedBy' })
+ expect(wrapper.find('.no-connections').text()).toBe(
+ `${noConnectionsUser.name} ${wrapper.vm.$t(`profile.network.followedByNobody`)}`,
+ )
+ })
+ })
- wrapper = mount(FollowList, {
- store,
- propsData: { ...propsData, type: type },
- mocks: {
- ...mocks,
- $apollo: {
- query: queryMock,
- },
- },
- localVue,
- })
- })
+ describe('with up to 7 loaded connections', () => {
+ let followingWrapper
+ let followedByWrapper
+ beforeAll(() => {
+ followingWrapper = Wrapper()
+ followedByWrapper = Wrapper({ type: 'followedBy' })
+ })
- it(`shows the users ${type}`, () => {
- expect(wrapper.findAll('.user-teaser').length).toEqual(propsData.user[type].length)
- })
+ it(`renders the connections`, () => {
+ expect(followedByWrapper.findAll('.user-teaser').length).toEqual(user.followedBy.length)
+ expect(followingWrapper.findAll('.user-teaser').length).toEqual(user.following.length)
+ })
- it(`has a button to load all remaining users ${type}`, async () => {
- jest.useFakeTimers()
+ it(`has a button to load all remaining connections`, async () => {
+ followingWrapper.find('.base-button').trigger('click')
+ followedByWrapper.find('.base-button').trigger('click')
+ expect(followingWrapper.emitted('fetchAllConnections')).toBeTruthy()
+ expect(followedByWrapper.emitted('fetchAllConnections')).toBeTruthy()
+ })
+ })
- wrapper.find('.base-button').trigger('click')
- await jest.runAllTicks()
- await wrapper.vm.$nextTick()
+ describe('with more than 7 loaded connections', () => {
+ let followingWrapper
+ let followedByWrapper
+ beforeAll(() => {
+ followingWrapper = Wrapper({ user: allConnectionsUser })
+ followedByWrapper = Wrapper({ user: allConnectionsUser, type: 'followedBy' })
+ })
- expect(wrapper.vm.connections.length).toBe(propsData.user[`${type}Count`])
- expect(queryMock).toHaveBeenCalledWith({
- query: wrapper.vm.queries[type],
- variables: { id: propsData.user.id },
- })
- })
- }),
- )
- })
+ it('renders the connections', () => {
+ expect(followedByWrapper.findAll('.user-teaser')).toHaveLength(
+ allConnectionsUser.followedByCount,
+ )
+ expect(followingWrapper.findAll('.user-teaser')).toHaveLength(
+ allConnectionsUser.followingCount,
+ )
+ })
- describe('given a user without connections', () => {
- ;['following', 'followedBy'].forEach((type) =>
- describe(`and type=${type}`, () => {
- let wrapper
+ it('renders the user-teaser in an overflow-container', () => {
+ expect(followingWrapper.find('.overflow-container').is('div')).toBe(true)
+ expect(followedByWrapper.find('.overflow-container').is('div')).toBe(true)
+ })
- beforeAll(() => {
- wrapper = mount(FollowList, {
- store,
- mocks: {
- $t: jest.fn().mockReturnValue('has no connections'),
- },
- localVue,
- propsData: {
- user: {
- ...propsData.user,
- followedByCount: 0,
- followingCount: 0,
- followedBy: [],
- following: [],
- },
- type,
- },
- })
- })
-
- it('displays the no-follower message', () => {
- expect(wrapper.find('.no-connections').text()).toBe(
- `${propsData.user.name} ${wrapper.vm.$t()}`,
- )
- })
- }),
- )
+ it('renders a filter text input', () => {
+ expect(followingWrapper.find('[name="followingFilter"]').is('input')).toBe(true)
+ expect(followedByWrapper.find('[name="followedByFilter"]').is('input')).toBe(true)
+ })
+ })
})
})
})
-
-const additionalConnections = {
- followedBy: helpers.fakeUser(5),
- following: helpers.fakeUser(8),
-}
diff --git a/webapp/components/features/FollowList/FollowList.story.js b/webapp/components/features/FollowList/FollowList.story.js
index 7c6918c94..b8cc02978 100644
--- a/webapp/components/features/FollowList/FollowList.story.js
+++ b/webapp/components/features/FollowList/FollowList.story.js
@@ -1,7 +1,6 @@
-import Vue from 'vue'
import { storiesOf } from '@storybook/vue'
import { withA11y } from '@storybook/addon-a11y'
-import apolloStorybookDecorator from 'apollo-storybook-vue'
+import { action } from '@storybook/addon-actions'
import helpers from '~/storybook/helpers'
import FollowList from './FollowList.vue'
@@ -20,38 +19,9 @@ const allConnectionsUser = {
followedBy: [...sevenConnectionsUser.followedBy, ...helpers.fakeUser(5)],
}
-const mocks = {
- Query: () => ({
- User: () => [allConnectionsUser],
- }),
-}
-const typeDefs = `
- type User {
- followedByCount: Int
- followedBy(offset: Int): [User]
- name: String
- slug: String
- id: String
- }
-
- type Query {
- User(id: ID!): [User]
- }
- schema {
- query: Query
- }
-`
-
storiesOf('FollowList', module)
.addDecorator(withA11y)
.addDecorator(helpers.layout)
- .addDecorator(
- apolloStorybookDecorator({
- mocks,
- typeDefs,
- Vue,
- }),
- )
.add('without connections', () => {
const user = {
...sevenConnectionsUser,
@@ -77,7 +47,13 @@ storiesOf('FollowList', module)
user,
}
},
- template: ``,
+ methods: {
+ fetchAllConnections(type) {
+ this.user = allConnectionsUser
+ action('fetchAllConnections')(type, this.user)
+ },
+ },
+ template: ``,
}
})
diff --git a/webapp/components/features/FollowList/FollowList.vue b/webapp/components/features/FollowList/FollowList.vue
index 29086eb66..06ce5201f 100644
--- a/webapp/components/features/FollowList/FollowList.vue
+++ b/webapp/components/features/FollowList/FollowList.vue
@@ -9,14 +9,19 @@
{{ userName }} {{ $t(`profile.network.${type}Nobody`) }}
-
+
-
+
-
+
{{
$t('profile.network.andMore', {
number: allConnectionsCount - connections.length,
@@ -27,13 +32,9 @@
-
+
-
+
@@ -44,6 +45,7 @@
v-focus="true"
size="small"
icon="filter"
+ :name="`${type}Filter`"
/>
@@ -51,9 +53,7 @@