All files / components/Announcement AnnouncementCard.js

100% Statements 19/19
100% Branches 13/13
100% Functions 2/2
100% Lines 19/19

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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62        89x 89x 89x 89x 89x 89x 89x   89x 81x 4x     77x       8x       4x 86x   86x 4x     82x 1x   81x                                                    
import React from "react";
import { Card, Container, Row, Col } from "react-bootstrap";
 
export function isFutureDate(startingDate) {
    const curr = new Date();
    const startYear = parseInt(startingDate);
    const startMonth = parseInt(startingDate.substring(5,7));
    const startDate = parseInt(startingDate.substring(8,10));
    const currYear = curr.getFullYear();
    const currMonth = curr.getMonth() + 1;
    const currDate = curr.getDate();
 
    if (startYear === currYear) {
        if (startMonth === currMonth) {
            return startDate > currDate;
        } else {
            // Stryker disable next-line all: mutation test unreasonable
            return startMonth > currMonth;
        }
    } else {
        // Stryker disable next-line all: mutation test unreasonable
        return startYear > currYear;
    }
}
 
const AnnouncementCard = ({ announcement }) => {
    const testIdPrefix = "announcementCard";
 
    if (!announcement || !announcement.startDate || isFutureDate(announcement.startDate)) {
        return null;
    }
 
    if ( announcement.endDate && (!isFutureDate(announcement.endDate))) {
        return null;
    }
    return (
        <Card.Body 
        // Stryker disable next-line all : don't mutation test CSS
        style={{ fontSize: "14px", border: "1px solid lightgrey", padding: "4px", borderRadius: "10px", margin: "10px 0" }}>
            <Container>
                <Row>
                    <Col xs={12} data-testid={`${testIdPrefix}-id-${announcement.announcementText}`}>
                        <div
                            // Stryker disable next-line all : don't mutation test CSS
                            style={{overflow: 'auto',
                            // Stryker disable next-line all : don't mutation test CSS
                            maxHeight: '100px',
                            // Stryker disable next-line all : don't mutation test CSS
                            wordWrap: 'break-word',
                            // Stryker disable next-line all : don't mutation test CSS
                            padding: '5px'
                        }}>
                            {announcement.announcementText}
                        </div>
                    </Col>
                </Row>
            </Container>
        </Card.Body>
    );
};
 
export default AnnouncementCard;