Skip to content

Commit

Permalink
Merge pull request #488 from GatherPress/mauteri-test-update
Browse files Browse the repository at this point in the history
Added more tests.
  • Loading branch information
mauteri authored Jan 12, 2024
2 parents 37ad066 + e3a165e commit 4d0f979
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/components/RsvpResponse.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
/**
* WordPress dependencies.
*/
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies.
*/
import RsvpResponseHeader from './RsvpResponseHeader';
import RsvpResponseContent from './RsvpResponseContent';
import { Listener } from '../helpers/broadcasting';
import { getFromGlobal } from '../helpers/globals';

/**
* Component for displaying and managing RSVP responses.
*
* This component renders a user interface for managing RSVP responses to an event.
* It includes options for attending, being on the waiting list, or not attending,
* and updates the status based on user interactions. The component also listens for
* changes in RSVP status and updates the state accordingly.
*
* @since 1.0.0
*
* @return {JSX.Element} The rendered RSVP response component.
*/
const RsvpResponse = () => {
const defaultLimit = 8;
const defaultStatus = 'attending';
Expand Down
66 changes: 66 additions & 0 deletions test/unit/js/src/components/RsvpResponse.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* External dependencies.
*/
import { render } from '@testing-library/react';
import { describe, expect, it } from '@jest/globals';
import '@testing-library/jest-dom';

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

/**
* Coverage for RsvpResponse.
*/
describe('RsvpResponse', () => {
it('renders component correctly', () => {
global.GatherPress = {
responses: {
all: {
count: 1,
responses: [
{
guests: 0,
id: 1,
name: 'unittest',
photo: 'https://unit.test/photo',
profile: 'https://unit.test/profile',
role: 'Member',
status: 'attending',
timestamp: '2023-05-11 00:00:00',
},
],
},
attending: {
count: 1,
responses: [
{
guests: 0,
id: 1,
name: 'John Doe',
photo: 'https://unit.test/photo',
profile: 'https://unit.test/profile',
role: 'Member',
status: 'attending',
timestamp: '2023-05-11 00:00:00',
},
],
},
not_attending: {
count: 0,
responses: [],
},
waiting_list: {
count: 0,
responses: [],
},
},
};

const { container } = render(<RsvpResponse />);

expect(container.children[0]).toHaveClass('gp-rsvp-response');
expect(container.children[0]).toHaveTextContent('John Doe');
});
});
2 changes: 2 additions & 0 deletions test/unit/js/src/helpers/event.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { dateTimeMomentFormat } from '../../../../../src/helpers/datetime';
*/
describe('hasEventPast', () => {
it('returns false if not set', () => {
global.GatherPress = {};

expect(hasEventPast()).toBe(false);

Check failure on line 30 in test/unit/js/src/helpers/event.test.js

View workflow job for this annotation

GitHub Actions / Jest Tests

Error: expect(received).toBe(expected) // Object.is equality Expected: false Received: true at Object.toBe (/home/runner/work/gatherpress/gatherpress/test/unit/js/src/helpers/event.test.js:30:26) at Promise.then.completed (/home/runner/work/gatherpress/gatherpress/node_modules/jest-circus/build/utils.js:298:28) at new Promise (<anonymous>) at callAsyncCircusFn (/home/runner/work/gatherpress/gatherpress/node_modules/jest-circus/build/utils.js:231:10) at _callCircusTest (/home/runner/work/gatherpress/gatherpress/node_modules/jest-circus/build/run.js:316:40) at processTicksAndRejections (node:internal/process/task_queues:95:5) at _runTest (/home/runner/work/gatherpress/gatherpress/node_modules/jest-circus/build/run.js:252:3) at _runTestsForDescribeBlock (/home/runner/work/gatherpress/gatherpress/node_modules/jest-circus/build/run.js:126:9) at _runTestsForDescribeBlock (/home/runner/work/gatherpress/gatherpress/node_modules/jest-circus/build/run.js:121:9) at run (/home/runner/work/gatherpress/gatherpress/node_modules/jest-circus/build/run.js:71:3) at runAndTransformResultsToJestFormat (/home/runner/work/gatherpress/gatherpress/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21) at jestAdapter (/home/runner/work/gatherpress/gatherpress/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19) at runTestInternal (/home/runner/work/gatherpress/gatherpress/node_modules/jest-runner/build/runTest.js:367:16) at runTest (/home/runner/work/gatherpress/gatherpress/node_modules/jest-runner/build/runTest.js:444:34) at Object.worker (/home/runner/work/gatherpress/gatherpress/node_modules/jest-runner/build/testWorker.js:106:12)
});

Expand Down

0 comments on commit 4d0f979

Please sign in to comment.