From 342c8df39d2c88fb63ca1a544e3babb850102598 Mon Sep 17 00:00:00 2001 From: kamre Date: Thu, 13 Jan 2022 23:26:27 +0700 Subject: [PATCH] [GH-1754] Feature: card badges (#2025) * First shot implementation of badges for the card. * Showing and hiding card badges in board/gallery views via header menu action added. * Counting of checkboxes in markdown supported. * Use Intl.formatMessage for badge titles. * Unit tests for `CardBadges` component added. Some other unit tests fixed. * Unit test for 'Show card badges' action in the view header menu added. * Cypress test for card badges added: - card with comments, description and checkboxes added for testing - card badges are shown and hidden via view menu - new Cypress command `uiAddNewCard` added - label property added to `MenuWrapper` and used in `ViewHeaderActionsMenu` * Unit tests fixed after change of the label for view menu. * Fix stylelint issues. * Class name for `CardBadges` component fixed. * Show and hide for card badges moved to `Properties` menu: - field `cardBadgesVisible` removed from `BoardViewFields` - new constant `badgesColumnId` introduced and used as an element in `visiblePropertyIds` - card badges added to calendar view - added `role` and `aria-label` for menu component `SwitchOption` - unit and Cypress tests updated * Fix Cypress test: use `blur` after typing text. Co-authored-by: Mattermod --- webapp/cypress.json | 3 +- webapp/cypress/global.d.ts | 1 + webapp/cypress/integration/cardBadges.ts | 67 +++++++++++ webapp/cypress/support/api_commands.ts | 11 ++ .../__snapshots__/cardBadges.test.tsx.snap | 47 ++++++++ .../__snapshots__/centerPanel.test.tsx.snap | 56 ++++----- .../__snapshots__/workspace.test.tsx.snap | 8 +- .../src/components/calendar/fullCalendar.tsx | 6 + webapp/src/components/cardBadges.scss | 13 +++ webapp/src/components/cardBadges.test.tsx | 82 ++++++++++++++ webapp/src/components/cardBadges.tsx | 107 ++++++++++++++++++ .../__snapshots__/gallery.test.tsx.snap | 27 ++++- .../src/components/gallery/gallery.test.tsx | 12 +- webapp/src/components/gallery/gallery.tsx | 2 + .../src/components/gallery/galleryCard.scss | 5 + .../components/gallery/galleryCard.test.tsx | 12 ++ webapp/src/components/gallery/galleryCard.tsx | 7 ++ .../globalHeaderSettingsMenu.test.tsx.snap | 4 + webapp/src/components/kanban/kanban.tsx | 3 + .../src/components/kanban/kanbanCard.test.tsx | 5 + webapp/src/components/kanban/kanbanCard.tsx | 3 + .../sidebarSettingsMenu.test.tsx.snap | 6 + .../__snapshots__/filterValue.test.tsx.snap | 2 + .../__snapshots__/viewHeader.test.tsx.snap | 4 +- .../viewHeaderActionsMenu.test.tsx.snap | 8 +- .../viewHeaderPropertiesMenu.test.tsx.snap | 64 ++++++++++- .../viewHeader/viewHeaderActionsMenu.test.tsx | 9 +- .../viewHeader/viewHeaderActionsMenu.tsx | 2 +- .../viewHeaderPropertiesMenu.test.tsx | 34 +++++- .../viewHeader/viewHeaderPropertiesMenu.tsx | 47 ++++---- webapp/src/constants.ts | 1 + webapp/src/test/testBlockFactory.ts | 32 +++--- webapp/src/testUtils.tsx | 11 ++ webapp/src/utils.test.ts | 14 +++ webapp/src/utils.ts | 19 ++++ webapp/src/widgets/icons/check.scss | 5 +- webapp/src/widgets/icons/message.tsx | 15 +++ webapp/src/widgets/icons/text.scss | 7 +- webapp/src/widgets/menu/switchOption.tsx | 2 + webapp/src/widgets/menuWrapper.tsx | 3 +- 40 files changed, 672 insertions(+), 94 deletions(-) create mode 100644 webapp/cypress/integration/cardBadges.ts create mode 100644 webapp/src/components/__snapshots__/cardBadges.test.tsx.snap create mode 100644 webapp/src/components/cardBadges.scss create mode 100644 webapp/src/components/cardBadges.test.tsx create mode 100644 webapp/src/components/cardBadges.tsx create mode 100644 webapp/src/widgets/icons/message.tsx diff --git a/webapp/cypress.json b/webapp/cypress.json index d1caf2b06..538f7b0d2 100644 --- a/webapp/cypress.json +++ b/webapp/cypress.json @@ -5,7 +5,8 @@ "**/login*.ts", "**/create*.ts", "**/manage*.ts", - "**/group*.ts" + "**/group*.ts", + "**/card*.ts" ], "env": { "username": "test-user", diff --git a/webapp/cypress/global.d.ts b/webapp/cypress/global.d.ts index a7c8a4283..0a9b24202 100644 --- a/webapp/cypress/global.d.ts +++ b/webapp/cypress/global.d.ts @@ -19,6 +19,7 @@ declare namespace Cypress { apiResetBoards: () => Chainable uiCreateNewBoard: (title?: string) => Chainable uiAddNewGroup: (name?: string) => Chainable + uiAddNewCard: (title?: string, columnIndex?: number) => Chainable /** * Create a board on a given menu item. diff --git a/webapp/cypress/integration/cardBadges.ts b/webapp/cypress/integration/cardBadges.ts new file mode 100644 index 000000000..c5cb4f2cd --- /dev/null +++ b/webapp/cypress/integration/cardBadges.ts @@ -0,0 +1,67 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +describe('Card badges', () => { + beforeEach(() => { + cy.apiInitServer() + cy.apiResetBoards() + localStorage.setItem('welcomePageViewed', 'true') + }) + + it('Shows and hides card badges', () => { + cy.visit('/') + + // Create new board + cy.uiCreateNewBoard('Testing') + + // Add a new card + cy.uiAddNewCard('Card') + + // Add some comments + cy.log('**Add some comments**') + addComment('Some comment') + addComment('Another comment') + addComment('Additional comment') + + // Add card description + cy.log('**Add card description**') + cy.findByText('Add a description...').click() + cy.findByRole('combobox').type('## Header\n- [ ] one\n- [x] two{esc}') + + // Add checkboxes + cy.log('**Add checkboxes**') + cy.findByRole('button', {name: 'Add content'}).click() + cy.findByRole('button', {name: 'checkbox'}).click() + cy.findByDisplayValue('').type('three{enter}') + cy.findByDisplayValue('').type('four{enter}') + cy.findByDisplayValue('').type('{esc}') + cy.findByDisplayValue('three').prev().click() + + // Close card dialog + cy.log('**Close card dialog**') + cy.findByRole('button', {name: 'Close dialog'}).click() + cy.findByRole('dialog').should('not.exist') + + // Show card badges + cy.log('**Show card badges**') + cy.findByRole('button', {name: 'Properties menu'}).click() + cy.findByRole('button', {name: 'Comments and Description'}).click() + cy.findByTitle('This card has a description').should('exist') + cy.findByTitle('Comments').contains('3').should('exist') + cy.findByTitle('Checkboxes').contains('2/4').should('exist') + + // Hide card badges + cy.log('**Hide card badges**') + cy.findByRole('button', {name: 'Properties menu'}).click() + cy.findByRole('button', {name: 'Comments and Description'}).click() + cy.findByTitle('This card has a description').should('not.exist') + cy.findByTitle('Comments').should('not.exist') + cy.findByTitle('Checkboxes').should('not.exist') + }) + + const addComment = (text: string) => { + cy.findByText('Add a comment...').click() + cy.findByRole('combobox').type(text).blur() + cy.findByRole('button', {name: 'Send'}).click() + } +}) diff --git a/webapp/cypress/support/api_commands.ts b/webapp/cypress/support/api_commands.ts index 405b957d9..72109849d 100644 --- a/webapp/cypress/support/api_commands.ts +++ b/webapp/cypress/support/api_commands.ts @@ -126,3 +126,14 @@ Cypress.Commands.add('uiAddNewGroup', (name?: string) => { } cy.wait(500) }) + +Cypress.Commands.add('uiAddNewCard', (title?: string, columnIndex?: number) => { + cy.log('**Add a new card**') + cy.findByRole('button', {name: '+ New'}).eq(columnIndex || 0).click() + cy.findByRole('dialog').should('exist') + + if (title) { + cy.log('**Change card title**') + cy.findByPlaceholderText('Untitled').type(title) + } +}) diff --git a/webapp/src/components/__snapshots__/cardBadges.test.tsx.snap b/webapp/src/components/__snapshots__/cardBadges.test.tsx.snap new file mode 100644 index 000000000..5c290856a --- /dev/null +++ b/webapp/src/components/__snapshots__/cardBadges.test.tsx.snap @@ -0,0 +1,47 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`components/cardBadges should match snapshot 1`] = ` +
+
+ + + + + + + + 3 + + + + + + 3/7 + +
+
+`; + +exports[`components/cardBadges should match snapshot for empty card 1`] = `
`; diff --git a/webapp/src/components/__snapshots__/centerPanel.test.tsx.snap b/webapp/src/components/__snapshots__/centerPanel.test.tsx.snap index 23353d011..6eb91edb7 100644 --- a/webapp/src/components/__snapshots__/centerPanel.test.tsx.snap +++ b/webapp/src/components/__snapshots__/centerPanel.test.tsx.snap @@ -168,7 +168,7 @@ exports[`components/centerPanel return centerPanel and click on card to show car class="octo-spacer" />