diff --git a/backend/src/schema/resolvers/posts.spec.js b/backend/src/schema/resolvers/posts.spec.js index 2e5069de7..233be450a 100644 --- a/backend/src/schema/resolvers/posts.spec.js +++ b/backend/src/schema/resolvers/posts.spec.js @@ -18,10 +18,11 @@ const createPostWithCategoriesMutation = ` mutation($title: String!, $content: String!, $categoryIds: [ID]) { CreatePost(title: $title, content: $content, categoryIds: $categoryIds) { id + title } } ` -const creatPostWithCategoriesVariables = { +const createPostWithCategoriesVariables = { title: postTitle, content: postContent, categoryIds: ['cat9', 'cat4', 'cat15'], @@ -35,6 +36,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 Post($filter: _PostFilter) { + Post(filter: $filter) { + title + id + categories { + id + } + } + } +` +const postCategoriesFilterParam = { categories_some: { id_in: ['cat4'] } } +const postQueryFilteredByCategoryVariables = { + filter: postCategoriesFilterParam, +} beforeEach(async () => { userParams = { name: 'TestUser', @@ -133,7 +154,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', @@ -151,18 +173,39 @@ describe('CreatePost', () => { icon: 'shopping-cart', }), ]) - const expected = [{ id: 'cat9' }, { id: 'cat4' }, { id: 'cat15' }] - const postWithCategories = await client.request( + postWithCategories = await client.request( createPostWithCategoriesMutation, - creatPostWithCategoriesVariables, + createPostWithCategoriesVariables, ) + }) + + 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, } + await expect( 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 categoryIds = [{ id: 'cat4' }, { id: 'cat15' }, { id: 'cat9' }] + const expected = { + Post: [ + { + title: postTitle, + id: postWithCategories.CreatePost.id, + categories: expect.arrayContaining(categoryIds), + }, + ], + } + await expect( + client.request(postQueryFilteredByCategory, postQueryFilteredByCategoryVariables), + ).resolves.toEqual(expected) + }) }) }) }) @@ -260,7 +303,7 @@ describe('UpdatePost', () => { ]) postWithCategories = await client.request( createPostWithCategoriesMutation, - creatPostWithCategoriesVariables, + createPostWithCategoriesVariables, ) updatePostVariables = { id: postWithCategories.CreatePost.id, diff --git a/cypress/integration/administration/TagsAndCategories.feature b/cypress/integration/administration/TagsAndCategories.feature index e55535ea9..96196be01 100644 --- a/cypress/integration/administration/TagsAndCategories.feature +++ b/cypress/integration/administration/TagsAndCategories.feature @@ -22,16 +22,16 @@ Feature: Tags and Categories When I navigate to the administration dashboard And I click on the menu item "Categories" Then I can see the following table: - | | Name | Posts | - | | Just For Fun | 2 | - | | Happyness & Values | 1 | - | | Health & Wellbeing | 0 | + | | Name | Posts | + | | Just For Fun | 2 | + | | Happyness & Values | 1 | + | | Health & Wellbeing | 0 | Scenario: See an overview of tags When I navigate to the administration dashboard And I click on the menu item "Tags" Then I can see the following table: - | | Name | Users | Posts | - | 1 | Democracy | 3 | 4 | - | 2 | Nature | 2 | 3 | - | 3 | Ecology | 1 | 1 | + | | Name | Users | Posts | + | 1 | Democracy | 3 | 4 | + | 2 | Nature | 2 | 3 | + | 3 | Ecology | 1 | 1 | diff --git a/cypress/integration/common/profile.js b/cypress/integration/common/profile.js index 1df1e2652..b1bf9e4e0 100644 --- a/cypress/integration/common/profile.js +++ b/cypress/integration/common/profile.js @@ -1,36 +1,36 @@ -import { When, Then } from 'cypress-cucumber-preprocessor/steps' +import { When, Then } from "cypress-cucumber-preprocessor/steps"; /* global cy */ -When('I visit my profile page', () => { - cy.openPage('profile/peter-pan') -}) +When("I visit my profile page", () => { + cy.openPage("profile/peter-pan"); +}); -Then('I should be able to change my profile picture', () => { - const avatarUpload = 'onourjourney.png' +Then("I should be able to change my profile picture", () => { + const avatarUpload = "onourjourney.png"; - cy.fixture(avatarUpload, 'base64').then(fileContent => { - cy.get('#customdropzone').upload( - { fileContent, fileName: avatarUpload, mimeType: 'image/png' }, - { subjectType: 'drag-n-drop' } - ) - }) - cy.get('.profile-avatar img') - .should('have.attr', 'src') - .and('contains', 'onourjourney') - cy.contains('.iziToast-message', 'Upload successful').should( - 'have.length', + cy.fixture(avatarUpload, "base64").then(fileContent => { + cy.get("#customdropzone").upload( + { fileContent, fileName: avatarUpload, mimeType: "image/png" }, + { subjectType: "drag-n-drop", force: true } + ); + }); + cy.get(".profile-avatar img") + .should("have.attr", "src") + .and("contains", "onourjourney"); + cy.contains(".iziToast-message", "Upload successful").should( + "have.length", 1 - ) -}) + ); +}); When("I visit another user's profile page", () => { - cy.openPage('profile/peter-pan') -}) + cy.openPage("profile/peter-pan"); +}); -Then('I cannot upload a picture', () => { - cy.get('.ds-card-content') +Then("I cannot upload a picture", () => { + cy.get(".ds-card-content") .children() - .should('not.have.id', 'customdropzone') - .should('have.class', 'ds-avatar') -}) + .should("not.have.id", "customdropzone") + .should("have.class", "ds-avatar"); +}); diff --git a/webapp/components/CategoriesSelect/CategoriesSelect.vue b/webapp/components/CategoriesSelect/CategoriesSelect.vue index 163f31419..94276a958 100644 --- a/webapp/components/CategoriesSelect/CategoriesSelect.vue +++ b/webapp/components/CategoriesSelect/CategoriesSelect.vue @@ -27,7 +27,7 @@ diff --git a/webapp/components/FilterPosts/FilterPostsMenuItems.vue b/webapp/components/FilterPosts/FilterPostsMenuItems.vue new file mode 100644 index 000000000..593781cdb --- /dev/null +++ b/webapp/components/FilterPosts/FilterPostsMenuItems.vue @@ -0,0 +1,126 @@ + + + diff --git a/webapp/components/notifications/NotificationMenu/index.vue b/webapp/components/notifications/NotificationMenu/index.vue index 20a9a7074..a7c0cc4b7 100644 --- a/webapp/components/notifications/NotificationMenu/index.vue +++ b/webapp/components/notifications/NotificationMenu/index.vue @@ -2,7 +2,7 @@ {{ totalNotifications }} - +