All files / components/ChatMessage ChatMessageDisplay.js

100% Statements 4/4
100% Branches 0/0
100% Functions 2/2
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26        70x 70x 70x       70x                              
import React from 'react';
import Card from 'react-bootstrap/Card';
 
function formatTimestamp(timestamp) {
  const date = new Date(timestamp);
  const formattedDate = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')} ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}:${date.getSeconds().toString().padStart(2, '0')}`;
  return formattedDate;
}
 
function ChatMessageDisplay({ chatMessage }) {
  return (
    <Card data-testid="ChatMessageDisplay">
      <Card.Body>
        <Card.Title>
          Email: {chatMessage.email}
        </Card.Title>
        <Card.Subtitle className="mb-2 text-muted">{formatTimestamp(chatMessage.chatMessage.timestamp)}</Card.Subtitle>
        <Card.Text>{chatMessage.chatMessage.payload}</Card.Text>
      </Card.Body>
    </Card>
  );
}
 
export default ChatMessageDisplay;