From cb082ecbbafad3b9852203a3de4469e9d54d65aa Mon Sep 17 00:00:00 2001 From: Angelo Veltens Date: Wed, 13 Apr 2022 22:19:22 +0200 Subject: [PATCH] show setup button when pod provider url is not configured --- src/content/PageContent.spec.tsx | 28 +++++++++++++++++++++++++++- src/content/PageContent.tsx | 5 ++++- src/content/SetupButton.spec.tsx | 20 ++++++++++++++++++++ src/content/SetupButton.tsx | 23 +++++++++++++++++++++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/content/SetupButton.spec.tsx create mode 100644 src/content/SetupButton.tsx diff --git a/src/content/PageContent.spec.tsx b/src/content/PageContent.spec.tsx index 08a5a37..3647153 100644 --- a/src/content/PageContent.spec.tsx +++ b/src/content/PageContent.spec.tsx @@ -1,6 +1,6 @@ +import React from 'react'; import { ISessionInfo } from '@inrupt/solid-client-authn-browser'; import { render, screen } from '@testing-library/react'; -import React from 'react'; import { PageContent } from './PageContent'; import { useSessionInfo } from './useSessionInfo'; @@ -12,6 +12,32 @@ describe('PageContent', () => { isLoggedIn: false, }); }); + describe('without provider url', () => { + it('shows setup button', () => { + render( + null} + /> + ); + const setupButton = screen.queryByText('Get started'); + expect(setupButton).toBeInTheDocument(); + }); + }); + describe('when not logged in', () => { + it('shows login button', () => { + render( + null} + /> + ); + const loginButton = screen.queryByText('Login'); + expect(loginButton).toBeInTheDocument(); + }); + }); describe('close icon', () => { it('is present', () => { render( diff --git a/src/content/PageContent.tsx b/src/content/PageContent.tsx index 203ff2d..09368e5 100644 --- a/src/content/PageContent.tsx +++ b/src/content/PageContent.tsx @@ -1,6 +1,7 @@ import { ISessionInfo } from '@inrupt/solid-client-authn-browser'; import React from 'react'; import { LoginButton } from './LoginButton'; +import { SetupButton } from './SetupButton'; import { ToolbarContainer } from './ToolbarContainer'; import { useSessionInfo } from './useSessionInfo'; @@ -31,8 +32,10 @@ export const PageContent = ({

WebClip

{currentSessionInfo.isLoggedIn ? ( - ) : ( + ) : providerUrl ? ( + ) : ( + )} ); diff --git a/src/content/SetupButton.spec.tsx b/src/content/SetupButton.spec.tsx new file mode 100644 index 0000000..81f666d --- /dev/null +++ b/src/content/SetupButton.spec.tsx @@ -0,0 +1,20 @@ +import React from 'react'; +import { fireEvent, render, screen } from '@testing-library/react'; +import { MessageType } from '../messages'; +import { sendMessage } from './sendMessage'; +import { SetupButton } from './SetupButton'; + +jest.mock('./sendMessage'); + +describe('SetupButton', () => { + it('triggers open option page message and calls close when clicked', () => { + const close = jest.fn(); + render(); + const button = screen.getByText('Get started'); + fireEvent.click(button); + expect(sendMessage).toHaveBeenCalledWith({ + type: MessageType.OPEN_OPTIONS, + }); + expect(close).toHaveBeenCalled(); + }); +}); diff --git a/src/content/SetupButton.tsx b/src/content/SetupButton.tsx new file mode 100644 index 0000000..76c0c4d --- /dev/null +++ b/src/content/SetupButton.tsx @@ -0,0 +1,23 @@ +import React from 'react'; +import { Button } from '../components/Button'; +import { MessageType } from '../messages'; +import { sendMessage } from './sendMessage'; + +interface Props { + close: () => void; +} + +export const SetupButton = ({ close }: Props) => { + return ( + + ); +};