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

[INCOMPLETE] Complete test for tabs interaction #75

Closed
wants to merge 5 commits into from
Closed
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
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,20 @@ yarn-error.log*

# Sentry Config File
.sentryclirc

# Created by https://www.gitignore.io/api/visualstudiocode
# Edit at https://www.gitignore.io/?templates=visualstudiocode

### VisualStudioCode ###
.vscode/
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

### VisualStudioCode Patch ###
# Ignore all local history of files
**/.history

# End of https://www.gitignore.io/api/visualstudiocode

6 changes: 1 addition & 5 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{
"recommendations": [
"arcanis.vscode-zipfs",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
}
40 changes: 40 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Next.js: debug server-side",
"type": "node-terminal",
"request": "launch",
"command": "yarn dev"
},
{
"name": "Next.js: debug client-side",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000"
},
{
"name": "Next.js: debug full stack",
"type": "node-terminal",
"request": "launch",
"command": "yarn dev",
"serverReadyAction": {
"pattern": "- Local:.+(https?://.+)",
"uriFormat": "%s",
"action": "debugWithChrome"
}
},
{
"name": "Next.js: tests",
"type": "node-terminal",
"request": "launch",
"command": "yarn test"
},
{
"name": "Next.js: watch tests",
"type": "node-terminal",
"request": "launch",
"command": "yarn test:watch"
}
]
}
15 changes: 10 additions & 5 deletions src/app/work/WorkTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useState, SyntheticEvent } from 'react';
import Box from '@mui/material/Box';
import Tabs from '@mui/material/Tabs';
import Tabs, { TabsProps } from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';

import { WorkItemType } from './constants';
Expand All @@ -17,27 +17,32 @@ type TabsOnChange = (event: SyntheticEvent, value: any) => void;

interface WorkTabsProps {
items: WorkItemType[];
scrollable: boolean;
}

const WorkTabs: React.FC<WorkTabsProps> = ({ items }) => {
const WorkTabs: React.FC<WorkTabsProps> = ({ items, scrollable }) => {
const [value, setValue] = useState(0);

const handleChange: TabsOnChange = (_, newValue) => {
setValue(newValue);
};

const scrollableProps: TabsProps = {
variant: 'scrollable',
scrollButtons: true,
allowScrollButtonsMobile: true,
};

return (
<Box sx={{ width: '100%' }}>
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<Tabs
value={value}
onChange={handleChange}
aria-label="work experience tabs"
variant="scrollable"
scrollButtons
allowScrollButtonsMobile
// https://mui.com/base-ui/react-tabs/#keyboard-navigation
selectionFollowsFocus
{...(scrollable && scrollableProps)}
>
{items.map((item, index) => {
return (
Expand Down
11 changes: 6 additions & 5 deletions src/app/work/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
screen,
renderSnapshotWithLayout,
} from 'test-utils';
// import userEvent from '@testing-library/user-event';
import userEvent from '@testing-library/user-event';

import WorkPage from './page';

Expand Down Expand Up @@ -46,10 +46,10 @@ describe('The Work Page', () => {
}
);

test('works as expected', () => {
// const user = userEvent.setup();
test('works as expected', async () => {
const user = userEvent.setup();

render(<WorkPage />);
render(<WorkPage scrollable={false} />);

const heading = screen.getByRole('heading', { level: 1 });
expect(heading).toBeVisible();
Expand All @@ -65,7 +65,8 @@ describe('The Work Page', () => {
expect(imperfectTab).toBeVisible();

// TODO https://github.com/nicholeuf/zen-site-next/issues/30
// await user.click(imperfectTab);
// This triggers an error, which only happens while under test
await user.click(imperfectTab);

// const imperfectHeading2 = screen.getByRole('heading', { level: 2 });
// expect(imperfectHeading2).toBeVisible();
Expand Down
8 changes: 6 additions & 2 deletions src/app/work/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ export const metadata: Metadata = {
title: 'Work',
};

const Work: React.FC = () => {
interface WorkProps {
scrollable?: boolean;
}

const Work: React.FC<WorkProps> = ({ scrollable = true }) => {
return (
<PageContainer data-testid="work-page">
<Typography variant="h1" gutterBottom>
Expand All @@ -24,7 +28,7 @@ const Work: React.FC = () => {
mentorship to colleagues, and collaborating within agile,
cross-functional teams.
</Typography>
<WorkTabs items={items} />
<WorkTabs items={items} scrollable={scrollable} />
</PageContainer>
);
};
Expand Down
Loading