From 3308a4431ffd08459d55028fa82ef38ac9b45812 Mon Sep 17 00:00:00 2001 From: Luke Watts Date: Thu, 1 Feb 2024 19:24:57 +0100 Subject: [PATCH] feat: add content statistics to questions --- src/pages/Question/QuestionPage.tsx | 124 ++++++++++++++------ src/pages/Question/question.routes.test.tsx | 6 + 2 files changed, 91 insertions(+), 39 deletions(-) diff --git a/src/pages/Question/QuestionPage.tsx b/src/pages/Question/QuestionPage.tsx index 2f484b4ea7..0d93de4a69 100644 --- a/src/pages/Question/QuestionPage.tsx +++ b/src/pages/Question/QuestionPage.tsx @@ -1,6 +1,7 @@ import { useEffect, useState } from 'react' import { Link, useParams } from 'react-router-dom' import { + ContentStatistics, FollowButton, Loader, ModerationStatus, @@ -9,8 +10,8 @@ import { import { logger } from 'src/logger' import { useDiscussionStore } from 'src/stores/Discussions/discussions.store' import { useQuestionStore } from 'src/stores/Question/question.store' -import { isAllowedToEditContent } from 'src/utils/helpers' -import { Box, Button, Card, Flex, Heading, Text } from 'theme-ui' +import { buildStatisticsLabel, isAllowedToEditContent } from 'src/utils/helpers' +import { Box, Button, Card, Divider, Flex, Heading, Text } from 'theme-ui' import { ContentAuthorTimestamp } from '../common/ContentAuthorTimestamp/ContentAuthorTimestamp' import { QuestionComments } from './QuestionComments' @@ -116,47 +117,92 @@ export const QuestionPage = () => { ) : question ? ( <> - - - + + + + + {isEditable && ( + + + + )} + + - - {isEditable && ( - - - - )} - - - + - - {question.title} - - {question.description} - + + {question.title} + + {question.description} + + + + + {question._id && ( { new RegExp(`^${question.description.split(' ')[0]}`), ), ).toBeInTheDocument() + + // Content statistics + expect(wrapper.getByText(`0 views`)).toBeInTheDocument() + expect(wrapper.getByText(`0 following`)).toBeInTheDocument() + expect(wrapper.getByText(`1 comment`)).toBeInTheDocument() + expect(mockFetchQuestionBySlug).toBeCalledWith(question.slug) }) })