Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URO-209: add additional content and tests to orcidlink #215

Merged
merged 13 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 15 additions & 90 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"@typescript-eslint/eslint-plugin": "^5.55.0",
"@typescript-eslint/parser": "^5.46.1",
"babel-plugin-named-exports-order": "^0.0.2",
"core-js": "3.37.1",
"eslint-plugin-prettier": "^3.4.0",
"husky": "^7.0.1",
"prettier": "^2.3.2",
Expand All @@ -96,6 +97,9 @@
"stylelint-config-standard": "^22.0.0",
"webpack": "^5.75.0"
},
"overrides": {
"@testing-library/dom": "^9.0.1"
},
"engines": {
"node": ">=20.11.1"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/app/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
usePageTracking,
} from '../common/hooks';
import ORCIDLinkFeature from '../features/orcidlink';
import ORCIDLinkCreateLink from '../features/orcidlink/CreateLink';

export const LOGIN_ROUTE = '/legacy/login';
export const ROOT_REDIRECT_ROUTE = '/narratives';
Expand Down Expand Up @@ -83,6 +84,9 @@ const Routes: FC = () => {
<Route path="/orcidlink">
<Route index element={<Authed element={<ORCIDLinkFeature />} />} />
</Route>
<Route path="/orcidlink/link">
<Route index element={<Authed element={<ORCIDLinkCreateLink />} />} />
</Route>

{/* IFrame Fallback Routes */}
<Route path="/fallback">
Expand Down
135 changes: 135 additions & 0 deletions src/features/orcidlink/CreateLink/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Provider } from 'react-redux';
import { MemoryRouter, Route, Routes } from 'react-router-dom';
import { createTestStore } from '../../../app/store';
import { INITIAL_STORE_STATE } from '../test/data';
import CreateLinkIndex from './index';

describe('The CreateLink component', () => {
const user = userEvent.setup();
let debugLogSpy: jest.SpyInstance;
beforeEach(() => {
jest.resetAllMocks();
});
beforeEach(() => {
debugLogSpy = jest.spyOn(console, 'debug');
});

async function expectAccordion(
container: HTMLElement,
titleText: string,
contentText: string
) {
expect(container).toHaveTextContent(titleText);

const faq1Content = await screen.findByText(new RegExp(contentText), {
exact: false,
});

expect(faq1Content).not.toBeVisible();

const faq1Title = await screen.findByText(new RegExp(titleText), {
exact: false,
});
await user.click(faq1Title);

await waitFor(() => {
expect(faq1Content).toBeVisible();
});
}

it('renders placeholder content', () => {
const { container } = render(
<Provider store={createTestStore(INITIAL_STORE_STATE)}>
<MemoryRouter initialEntries={['/foo']}>
<CreateLinkIndex />
</MemoryRouter>
</Provider>
);

expect(container).toHaveTextContent('Create Your KBase ORCID® Link');
expect(container).toHaveTextContent('FAQs');
expect(document.title).toBe('KBase: ORCID Link - Create Link');
});

it('cancel button returns to the ORCID Link home page', async () => {
const user = userEvent.setup();
let fakeHomeCalled = false;
function FakeHome() {
fakeHomeCalled = true;
return <div>FAKE HOME</div>;
}
const { container } = render(
<Provider store={createTestStore(INITIAL_STORE_STATE)}>
<MemoryRouter initialEntries={['/orcidlink/link']}>
<Routes>
<Route path={'orcidlink/link'} element={<CreateLinkIndex />} />
<Route path={'orcidlink'} element={<FakeHome />} />
</Routes>
</MemoryRouter>
</Provider>
);

expect(container).toHaveTextContent('Create Your KBase ORCID® Link');
expect(container).toHaveTextContent('FAQs');
expect(document.title).toBe('KBase: ORCID Link - Create Link');

const cancelButton = await screen.findByText('Cancel');
await user.click(cancelButton);

await waitFor(() => {
expect(fakeHomeCalled).toBe(true);
});
});

it('cancel button returns to the ORCID Link home page', async () => {
const user = userEvent.setup();
const { container } = render(
<Provider store={createTestStore(INITIAL_STORE_STATE)}>
<MemoryRouter initialEntries={['/orcidlink/link']}>
<Routes>
<Route path={'orcidlink/link'} element={<CreateLinkIndex />} />
</Routes>
</MemoryRouter>
</Provider>
);

expect(container).toHaveTextContent('Create Your KBase ORCID® Link');
expect(container).toHaveTextContent('FAQs');
expect(document.title).toBe('KBase: ORCID Link - Create Link');

const continueButton = await screen.findByText('Continue to ORCID®');
await user.click(continueButton);

await waitFor(() => {
expect(debugLogSpy).toHaveBeenCalledWith(
'WILL START THE LINKING PROCESS'
);
});
});

it('faq accordions are present and work', async () => {
const { container } = render(
<Provider store={createTestStore(INITIAL_STORE_STATE)}>
<MemoryRouter initialEntries={['/orcidlink/link']}>
<Routes>
<Route path={'orcidlink/link'} element={<CreateLinkIndex />} />
</Routes>
</MemoryRouter>
</Provider>
);

expectAccordion(
container,
"What if I don't have an ORCID® Account",
"But what if you don't have an ORCID® account?"
);

expectAccordion(
container,
'But I already log in with ORCID®',
'Your ORCID® sign-in link is only used to obtain your ORCID® iD during sign-in'
);
});
});
Loading
Loading