Skip to content

Commit

Permalink
Merge pull request #467 from GatherPress/mauteri-updates-4
Browse files Browse the repository at this point in the history
Added tests for OnlineEvent component.
  • Loading branch information
mauteri authored Dec 28, 2023
2 parents ef01a2e + 37b96b5 commit ebe408f
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/components/DateTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
* Formats the provided start date and time according to the specified label format
* and returns the formatted result in the time zone configured for the plugin.
*
* @since 1.0.0
*
* @param {Object} props - The properties object containing the start date and time.
* @param {string} props.dateTimeStart - The start date and time to be formatted.
*
Expand All @@ -35,6 +37,8 @@ export const DateTimeStartLabel = (props) => {
* Formats the provided end date and time according to the specified label format
* and returns the formatted result in the time zone configured for the plugin.
*
* @since 1.0.0
*
* @param {Object} props - The properties object containing the end date and time.
* @param {string} props.dateTimeStart - The end date and time to be formatted.
*
Expand Down
2 changes: 2 additions & 0 deletions src/components/EditCover.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* EditCover component provides an overlay for content to indicate its editability.
*
* @since 1.0.0
*
* @param {Object} props - The properties passed to the component.
* @param {boolean} props.isSelected - Indicates whether the content is selected for editing.
* @param {JSX.Element} props.children - The child elements to be rendered within the component.
Expand Down
2 changes: 2 additions & 0 deletions src/components/MapEmbed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* MapEmbed component renders an embedded Google Map based on provided location and settings.
*
* @since 1.0.0
*
* @param {number} props - The properties passed to the component.
* @param {string} props.location - The location to be displayed on the map (address or coordinates).
* @param {number} [props.zoom=1] - The zoom level of the map.
Expand Down
10 changes: 10 additions & 0 deletions src/components/OnlineEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ import { useState } from '@wordpress/element';
import { Listener } from '../helpers/broadcasting';
import { getFromGlobal } from '../helpers/globals';

/**
* OnlineEvent component displays information about an online event and provides a link to the event if available.
*
* @since 1.0.0
*
* @param {Object} props - The properties passed to the component.
* @param {string} [props.onlineEventLinkDefault=''] - The default link for the online event.
*
* @return {JSX.Element} The rendered OnlineEvent component.
*/
const OnlineEvent = ({ onlineEventLinkDefault = '' }) => {
const text = __('Online event', 'gatherpress');
const [onlineEventLink, setOnlineEventLink] = useState(
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/broadcasting.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* Broadcasts custom events based on the provided payload, optionally appending an identifier to each event type.
*
* @since 1.0.0
*
* @param {Object} payload - An object containing data to be dispatched with custom events.
* @param {string} identifier - An optional identifier to append to each event type.
*
Expand All @@ -26,6 +28,8 @@ export const Broadcaster = (payload, identifier = '') => {
* Sets up event listeners for custom events based on the provided payload, optionally appending an identifier to each event type.
* When an event is triggered, the corresponding listener callback is executed with the event detail.
*
* @since 1.0.0
*
* @param {Object} payload - An object specifying event types and their corresponding listener callbacks.
* @param {string} identifier - An optional identifier to append to each event type.
*
Expand Down
20 changes: 20 additions & 0 deletions src/helpers/datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const dateTimeLabelFormat = 'MMMM D, YYYY h:mm a';
* Retrieves the timezone for the application based on the provided timezone or the global setting.
* If the provided timezone is invalid, the default timezone is set to 'GMT'.
*
* @since 1.0.0
*
* @param {string} timezone - The timezone to be used, defaults to the global setting 'event_datetime.timezone'.
*
* @return {string} The retrieved timezone, or 'GMT' if the provided timezone is invalid.
Expand All @@ -43,6 +45,8 @@ export const getTimeZone = (
* Retrieves the UTC offset for a given timezone.
* If the timezone is not set to 'GMT', an empty string is returned.
*
* @since 1.0.0
*
* @param {string} timezone - The timezone for which to retrieve the UTC offset.
*
* @return {string} UTC offset without the colon if the timezone is set to 'GMT', otherwise an empty string.
Expand All @@ -63,6 +67,8 @@ export const getUtcOffset = (timezone) => {
* Converts a UTC offset string to a format suitable for display,
* removing the colon (:) between hours and minutes.
*
* @since 1.0.0
*
* @param {string} offset - The UTC offset string to be converted.
*
* @return {string} Converted UTC offset without the colon, suitable for display.
Expand All @@ -76,6 +82,8 @@ export const maybeConvertUtcOffsetForDisplay = (offset = '') => {
* The function accepts offsets in the form of 'UTC+HH:mm', 'UTC-HH:mm', 'UTC+HH', or 'UTC-HH'.
* The resulting format is '+HH:mm' or '-HH:mm'.
*
* @since 1.0.0
*
* @param {string} offset - The UTC offset string to be converted.
*
* @return {string} Converted UTC offset in the format '+HH:mm' or '-HH:mm'.
Expand Down Expand Up @@ -108,6 +116,8 @@ export const maybeConvertUtcOffsetForDatabase = (offset = '') => {
* Converts a UTC offset string to a format suitable for dropdown selection,
* specifically in the format '+HH:mm' or '-HH:mm'.
*
* @since 1.0.0
*
* @param {string} offset - The UTC offset string to be converted.
*
* @return {string} Converted UTC offset in the format '+HH:mm' or '-HH:mm'.
Expand Down Expand Up @@ -136,6 +146,8 @@ export const maybeConvertUtcOffsetForSelect = (offset = '') => {
* The default start date and time for an event.
* It is set to the current date and time plus one day at 18:00:00 in the application's timezone.
*
* @since 1.0.0
*
* @type {string} Formatted default start date and time in the application's timezone.
*/
export const defaultDateTimeStart = moment
Expand All @@ -150,6 +162,8 @@ export const defaultDateTimeStart = moment
* The default end date and time for an event.
* It is calculated based on the default start date and time plus two hours in the application's timezone.
*
* @since 1.0.0
*
* @type {string} Formatted default end date and time in the application's timezone.
*/
export const defaultDateTimeEnd = moment
Expand All @@ -162,6 +176,8 @@ export const defaultDateTimeEnd = moment
* If the start date and time is not set, it defaults to a predefined value.
* The formatted datetime is then stored in the global settings for future access.
*
* @since 1.0.0
*
* @return {string} The formatted start date and time for the event.
*/
export const getDateTimeStart = () => {
Expand All @@ -182,6 +198,8 @@ export const getDateTimeStart = () => {
* If the end date and time is not set, it defaults to a predefined value.
* The formatted datetime is then stored in the global settings for future access.
*
* @since 1.0.0
*
* @return {string} The formatted end date and time for the event.
*/
export const getDateTimeEnd = () => {
Expand All @@ -200,6 +218,8 @@ export const getDateTimeEnd = () => {
/**
* Updates the start date and time for an event, performs validation, and triggers the save functionality.
*
* @since 1.0.0
*
* @param {string} date - The new start date and time to be set.
* @param {Function} setDateTimeStart - Optional callback function to update the state or perform additional actions.
*
Expand Down
39 changes: 39 additions & 0 deletions test/unit/js/src/components/OnlineEvent.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* External dependencies.
*/
import { render } from '@testing-library/react';
import { expect, test } from '@jest/globals';
import '@testing-library/jest-dom';

/**
* Internal dependencies.
*/
import OnlineEvent from '../../../../../src/components/OnlineEvent';

/**
* Coverage for OnlineEvent.
*/
test('OnlineEvent renders component without link', () => {
const { container } = render(<OnlineEvent />);

expect(container).toHaveTextContent('Online event');
expect(container.children[0].children[0].children[0]).toHaveClass(
'dashicon dashicons dashicons-video-alt2'
);
expect(container.children[0].children[1].children[0]).toHaveClass(
'gp-tooltip'
);
});

test('OnlineEvent renders component with link', () => {
const link = 'https://unit.test/chat/';
const { container } = render(<OnlineEvent onlineEventLinkDefault={link} />);

expect(container).toHaveTextContent('Online event');
expect(container.children[0].children[0].children[0]).toHaveClass(
'dashicon dashicons dashicons-video-alt2'
);
expect(
container.children[0].children[1].children[0].getAttribute('href')
).toBe(link);
});

0 comments on commit ebe408f

Please sign in to comment.