Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
stephl3 committed Oct 24, 2024
1 parent 92829c4 commit b25cea8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { act, render, waitFor } from '@testing-library/react';
import { act, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { renderHook } from '@leafygreen-ui/testing-lib';
Expand All @@ -8,7 +8,6 @@ import {
ModalPopoverProvider,
useModalPopoverContext,
} from './ModalPopoverContext';
import { type ModalPopoverProviderProps } from './ModalPopoverContext.types';

const childTestID = 'modal-popover-provider';
const buttonTestId = 'test-button';
Expand All @@ -29,9 +28,9 @@ function TestContextComponent() {
);
}

function renderProvider(props?: ModalPopoverProviderProps) {
function renderProvider() {
const utils = render(
<ModalPopoverProvider {...props}>
<ModalPopoverProvider>
<TestContextComponent />
</ModalPopoverProvider>,
);
Expand All @@ -44,20 +43,6 @@ describe('packages/leafygreen-provider/ModalPopoverContext', () => {
const { container, testChild } = renderProvider();
expect(container.firstChild).toBe(testChild);
});

test('`isPopoverOpen` is initialized as false', () => {
const { testChild } = renderProvider();
expect(testChild.textContent).toBe('false');
});

test('when passed true, `setIsPopoverOpen` sets `isPopoverOpen` to true', () => {
const { testChild, getByTestId } = renderProvider();

// The button's click handler fires setIsPopoverOpen(true)
userEvent.click(getByTestId(buttonTestId));

expect(testChild.textContent).toBe('true');
});
});

describe('useModalPopoverContext', () => {
Expand All @@ -75,9 +60,8 @@ describe('useModalPopoverContext', () => {

act(() => result.current.setIsPopoverOpen(true));
rerender();
await waitFor(() => {
expect(result.current.isPopoverOpen).toBe(true);
});

expect(result.current.isPopoverOpen).toBe(true);
});

describe('with test component', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React, { createContext, useContext, useMemo, useState } from 'react';
import React, {
createContext,
PropsWithChildren,
useContext,
useMemo,
useState,
} from 'react';
import PropTypes from 'prop-types';

import {
ModalPopoverContextType,
ModalPopoverProviderProps,
} from './ModalPopoverContext.types';
import { ModalPopoverContextType } from './ModalPopoverContext.types';

export const ModalPopoverContext = createContext<ModalPopoverContextType>({
isPopoverOpen: false,
Expand All @@ -22,9 +25,7 @@ export const useModalPopoverContext = (): ModalPopoverContextType => {
* Creates a Modal Popover context.
* Call `useModalPopoverContext` to access the popover state
*/
export const ModalPopoverProvider = ({
children,
}: ModalPopoverProviderProps) => {
export const ModalPopoverProvider = ({ children }: PropsWithChildren<{}>) => {
const [isPopoverOpen, setIsPopoverOpen] = useState<boolean>(false);

const providerValue = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,3 @@ export interface ModalPopoverContextType {
*/
setIsPopoverOpen: React.Dispatch<React.SetStateAction<boolean>>;
}

export interface ModalPopoverProviderProps {
children?: React.ReactNode;
}

0 comments on commit b25cea8

Please sign in to comment.