Skip to content

Commit

Permalink
обновить все зависимости
Browse files Browse the repository at this point in the history
  • Loading branch information
dima117 committed Nov 21, 2022
1 parent 963dd11 commit 247b41f
Show file tree
Hide file tree
Showing 14 changed files with 28,811 additions and 16,094 deletions.
7 changes: 3 additions & 4 deletions e2e/example.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { test, expect } from "@playwright/test";

test('по адресу /about должна открываться страница "о проекте"', async ({ page }) => {
test('по адресу /about открывается страница "о проекте"', async ({ page }) => {
await page.goto("/about");

await expect(page.getByTestId('page-title')).toHaveText('About');
await expect(page.getByTestId("page-title")).toHaveText("About");
});

test("если добавить элемент, он появляется в списке", async ({ page }) => {
Expand All @@ -12,8 +12,7 @@ test("если добавить элемент, он появляется в с
await page.getByTestId("input-add").type("Сделать домашку");
await page.getByTestId("button-add").click();

const list = page.getByTestId("list");
const items = list.getByTestId("list-item");
const items = page.getByTestId("list-item");
const allTexts = await items.allTextContents();

await expect(allTexts).toContain("Сделать домашку");
Expand Down
44,460 changes: 28,582 additions & 15,878 deletions package-lock.json

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,43 @@
"homepage": ".",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"@types/jest": "^26.0.23",
"@types/node": "^12.20.15",
"@types/react": "^17.0.11",
"@types/react-dom": "^17.0.8",
"jest-teamcity": "^1.9.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^14.4.3",
"@types/jest": "^27.5.2",
"@types/node": "^18.11.9",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"jest-teamcity": "^1.11.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-helmet": "^6.1.0",
"react-redux": "^7.2.4",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-redux": "^8.0.5",
"react-router": "^6.4.3",
"react-router-dom": "^6.4.3",
"react-scripts": "^5.0.1",
"redux": "^4.1.0",
"redux": "^4.2.0",
"redux-observable": "^2.0.0",
"rxjs": "^7.1.0",
"typescript": "^4.3.4",
"rxjs": "^7.5.7",
"typescript": "^4.9.3",
"web-vitals": "^1.1.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"e2e": "playwright test --project=chromium",
"test": "react-scripts test",
"e2e": "playwright test --project=chromium && playwright show-report",
"test-ci": "CI=true npm test -- --reporters=\"default\" --reporters=\"jest-html-reporter\" --reporters=\"jest-teamcity\""
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
],
"rules": {
"testing-library/prefer-screen-queries": "off"
}
},
"browserslist": {
"production": [
Expand All @@ -52,11 +55,8 @@
]
},
"devDependencies": {
"@playwright/test": "^1.27.1",
"@playwright/test": "^1.28.0",
"@types/react-helmet": "^6.1.5",
"@types/react-redux": "^7.1.16",
"@types/react-router": "^5.1.15",
"@types/react-router-dom": "^5.1.7",
"jest-html-reporter": "^3.4.1"
"jest-html-reporter": "^3.7.0"
}
}
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const config: PlaywrightTestConfig = {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'http://localhost:3000',
baseURL: "http://localhost:3000",

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
Expand Down
43 changes: 22 additions & 21 deletions src/Application.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { FC } from 'react';
import { Switch, Route, Link } from 'react-router-dom';
import { FC } from "react";
import { Routes, Route, Link } from "react-router-dom";

import { About } from './pages/About';
import { Home } from './pages/Home';
import { About } from "./pages/About";
import { Home } from "./pages/Home";

export const Application: FC = () => {
return (
<div>
<nav>
<Link data-testid="link-home" to="/">Home</Link>
<Link to="/about">About</Link>
</nav>
<Switch>
<Route path="/about">
<About />
</Route>
<Route path="/">
<Home />
</Route>
</Switch>
</div>
);
}
const home = <Home />;
const about = <About />;

return (
<div>
<nav>
<Link data-testid="link-home" to="/">
Home
</Link>
<Link to="/about">About</Link>
</nav>
<Routes>
<Route path="/about" element={about} />
<Route path="/" element={home} />
</Routes>
</div>
);
};
37 changes: 21 additions & 16 deletions src/components/TodoItem.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import { FC, useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { ApplicationState, setDone } from '../store';
import { FC, useCallback } from "react";
import { useDispatch, useSelector } from "react-redux";
import { ApplicationState, setDone } from "../store";

export const TodoItem: FC<{ index: number }> = props => {
const { index } = props;
export const TodoItem: FC<{ index: number }> = (props) => {
const { index } = props;

const dispatch = useDispatch();
const text = useSelector((state: ApplicationState) => state.items[index]);
const done = useSelector((state: ApplicationState) => state.done[index]);
const dispatch = useDispatch();
const text = useSelector((state: ApplicationState) => state.items[index]);
const done = useSelector((state: ApplicationState) =>
Boolean(state.done[index])
);

const onChange = useCallback(() => dispatch(setDone(index, !done)), [index, done, dispatch]);
const onChange = useCallback(
() => dispatch(setDone(index, !done)),
[index, done, dispatch]
);

return (
<div data-testid="list-item" className={done ? "done" : ""}>
<input type="checkbox" checked={done} onChange={onChange} />
{text}
</div>
);
}
return (
<div data-testid="list-item" className={done ? "done" : ""}>
<input type="checkbox" checked={done} onChange={onChange} />
{text}
</div>
);
};
60 changes: 33 additions & 27 deletions src/components/TodoList.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
import { FC, useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { ApplicationState, addItem, setText } from '../store';
import { TodoItem } from './TodoItem';
import { ChangeEvent, FC, useCallback } from "react";
import { useDispatch, useSelector } from "react-redux";
import { ApplicationState, addItem, setText } from "../store";
import { TodoItem } from "./TodoItem";

export const TodoList: FC = () => {
const dispatch = useDispatch();

const items = useSelector((state: ApplicationState) => state.items);
const text = useSelector((state: ApplicationState) => state.text);

const onChange = useCallback(({ target }) => {
dispatch(setText(target.value));
}, [dispatch]);
const dispatch = useDispatch();

const onClick = useCallback(() => {
dispatch(addItem(text));
}, [dispatch, text]);
const items = useSelector((state: ApplicationState) => state.items);
const text = useSelector((state: ApplicationState) => state.text);

return (
<div>
<div>
<input data-testid="input-add" value={text} onChange={onChange} />
<button data-testid="button-add" onClick={onClick}>Добавить</button>
</div>
<div data-testid="list" className="list">
{items.map((text, i) => <TodoItem key={i} index={i} />)}
</div>
</div>
);
}
const onChange = useCallback(
({ target }: ChangeEvent<HTMLInputElement>) => {
dispatch(setText(target.value));
},
[dispatch]
);

const onClick = useCallback(() => {
dispatch(addItem(text));
}, [dispatch, text]);

return (
<div>
<div>
<input data-testid="input-add" value={text} onChange={onChange} />
<button data-testid="button-add" onClick={onClick}>
Добавить
</button>
</div>
<div data-testid="list" className="list">
{items.map((text, i) => (
<TodoItem key={i} index={i} />
))}
</div>
</div>
);
};
77 changes: 35 additions & 42 deletions src/example.test.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,46 @@
import { it, expect } from '@jest/globals';
import { render, within } from '@testing-library/react';
import { BrowserRouter } from 'react-router-dom';
import { Router } from 'react-router';
import { createMemoryHistory } from 'history';
import { it, expect } from "@jest/globals";
import { render } from "@testing-library/react";
import events from "@testing-library/user-event";

import { Provider } from 'react-redux';
import { BrowserRouter } from "react-router-dom";
import { MemoryRouter } from "react-router";
import { Provider } from "react-redux";

import { initStore } from './store';
import { Application } from './Application';
import events from '@testing-library/user-event';
import { initStore } from "./store";
import { Application } from "./Application";

it('по адресу /about должна открываться страница "о проекте"', () => {
const history = createMemoryHistory({
initialEntries: ['/about'],
initialIndex: 0
});

const store = initStore();
const application = (
<Router history={history} >
<Provider store={store} >
<Application />
</Provider>
</Router>
);

const { getByTestId } = render(application);

expect(getByTestId('page-title').textContent).toEqual('About');
const store = initStore();
const application = (
<MemoryRouter initialEntries={["/about"]} initialIndex={0}>
<Provider store={store}>
<Application />
</Provider>
</MemoryRouter>
);

const { getByTestId } = render(application);

expect(getByTestId("page-title").textContent).toEqual("About");
});

it("если добавить элемент, он появляется в списке", async () => {
const store = initStore();
const application = (
<BrowserRouter>
<Provider store={store}>
<Application />
</Provider>
</BrowserRouter>
);

it('если добавить элемент, он появляется в списке', () => {
const store = initStore();
const application = (
<BrowserRouter>
<Provider store={store} >
<Application />
</Provider>
</BrowserRouter>
);
const { getByTestId, getAllByTestId } = render(application);

const { getByTestId } = render(application);
events.type(getByTestId('input-add'), 'Сделать домашку');
events.click(getByTestId('button-add'))
await events.type(getByTestId("input-add"), "Сделать домашку");

const list = getByTestId('list');
const items = within(list).getAllByTestId('list-item');
await events.click(getByTestId("button-add"));

expect(items.map(el => el.textContent)).toContain('Сделать домашку');
// screen.logTestingPlaygroundURL();
const items = getAllByTestId("list-item");

expect(items.map((el) => el.textContent)).toContain("Сделать домашку");
});
4 changes: 2 additions & 2 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ body {
padding: 20px;
}

input, a {
input,
a {
margin-right: 8px;
}

Expand All @@ -13,4 +14,3 @@ input, a {
.list {
margin-top: 12px;
}

Loading

0 comments on commit 247b41f

Please sign in to comment.