From c6b261853f9aef26fc1d72b3f87fd62d947c6a9e Mon Sep 17 00:00:00 2001 From: Matt Rider Date: Wed, 3 Jul 2019 19:46:26 -0300 Subject: [PATCH 01/39] Add test for filter posts by category --- backend/src/schema/resolvers/posts.spec.js | 52 ++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/backend/src/schema/resolvers/posts.spec.js b/backend/src/schema/resolvers/posts.spec.js index 763945527..4c288fc25 100644 --- a/backend/src/schema/resolvers/posts.spec.js +++ b/backend/src/schema/resolvers/posts.spec.js @@ -32,6 +32,26 @@ const postQueryWithCategories = ` } } ` +const createPostWithoutCategoriesVariables = { + title: 'This is a post without categories', + content: 'I should be able to filter it out', + categoryIds: null, +} +const postQueryFilteredByCategory = ` + query($name: String) { + Post(filter: { categories_some: { name: $name } }) { + title + id + categories { + name + } + } + } +` +const postCategoriesFilterParam = 'Environment & Nature' +const postQueryFilteredByCategoryVariables = { + name: postCategoriesFilterParam, +} beforeEach(async () => { await factory.create('User', { email: 'test@example.org', @@ -124,7 +144,8 @@ describe('CreatePost', () => { }) describe('categories', () => { - it('allows a user to set the categories of the post', async () => { + let postWithCategories + beforeEach(async () => { await Promise.all([ factory.create('Category', { id: 'cat9', @@ -142,11 +163,14 @@ describe('CreatePost', () => { icon: 'shopping-cart', }), ]) - const expected = [{ id: 'cat9' }, { id: 'cat4' }, { id: 'cat15' }] - const postWithCategories = await client.request( + postWithCategories = await client.request( createPostWithCategoriesMutation, creatPostWithCategoriesVariables, ) + }) + + it('allows a user to set the categories of the post', async () => { + const expected = [{ id: 'cat9' }, { id: 'cat4' }, { id: 'cat15' }] const postQueryWithCategoriesVariables = { id: postWithCategories.CreatePost.id, } @@ -154,6 +178,28 @@ describe('CreatePost', () => { client.request(postQueryWithCategories, postQueryWithCategoriesVariables), ).resolves.toEqual({ Post: [{ categories: expect.arrayContaining(expected) }] }) }) + + it('allows a user to filter for posts by category', async () => { + await client.request(createPostWithCategoriesMutation, createPostWithoutCategoriesVariables) + const categoryNames = [ + { name: 'Democracy & Politics' }, + { name: 'Environment & Nature' }, + { name: 'Consumption & Sustainability' }, + ] + const expected = { + Post: [ + { + title: postTitle, + id: postWithCategories.CreatePost.id, + categories: expect.arrayContaining(categoryNames), + }, + ], + } + + await expect( + client.request(postQueryFilteredByCategory, postQueryFilteredByCategoryVariables), + ).resolves.toEqual(expected) + }) }) }) }) From bb93052b88da55c9c551cacd2934a91b38319e28 Mon Sep 17 00:00:00 2001 From: Matt Rider Date: Wed, 3 Jul 2019 19:46:49 -0300 Subject: [PATCH 02/39] Add FilterPosts dropdown with category names --- webapp/components/FilterPosts/FilterPosts.vue | 86 +++++++++++++++++++ webapp/layouts/default.vue | 21 ++++- webapp/store/categories.js | 42 +++++++++ 3 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 webapp/components/FilterPosts/FilterPosts.vue create mode 100644 webapp/store/categories.js diff --git a/webapp/components/FilterPosts/FilterPosts.vue b/webapp/components/FilterPosts/FilterPosts.vue new file mode 100644 index 000000000..7fff1d477 --- /dev/null +++ b/webapp/components/FilterPosts/FilterPosts.vue @@ -0,0 +1,86 @@ + + diff --git a/webapp/layouts/default.vue b/webapp/layouts/default.vue index e3fc1cccd..1c1ace9de 100644 --- a/webapp/layouts/default.vue +++ b/webapp/layouts/default.vue @@ -4,12 +4,12 @@
- + - + + + + + +