Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
hutamatr authored Feb 18, 2023
2 parents 38695e6 + 7981ab5 commit bce28cd
Show file tree
Hide file tree
Showing 39 changed files with 1,449 additions and 140 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
'eslint:recommended',
'plugin:react/recommended',
'plugin:prettier/recommended',
'plugin:jest-dom/recommended',
'prettier',
],
overrides: [],
Expand Down
50 changes: 29 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
{
"name": "todo-list",
"version": "1.0.3",
"version": "1.1.2",
"private": true,
"engines": {
"node": "18.14.0"
},
"dependencies": {
"@tanstack/react-query": "^4.20.4",
"@tanstack/react-query-devtools": "^4.20.4",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^13.2.1",
"axios": "^0.27.2",
"@tanstack/react-query": "^4.24.4",
"@tanstack/react-query-devtools": "^4.24.4",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^14.4.3",
"axios": "^1.3.2",
"baffle": "^0.3.6",
"daisyui": "^2.24.0",
"daisyui": "^2.50.0",
"moment": "^2.29.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hot-toast": "^2.4.0",
"react-icons": "^4.4.0",
"react-nice-avatar": "^1.2.4",
"react-router-dom": "^6.3.0",
"react-icons": "^4.7.1",
"react-nice-avatar": "^1.3.1",
"react-router-dom": "^6.8.1",
"react-scripts": "5.0.1",
"react-toggle-dark-mode": "^1.1.1",
"web-vitals": "^2.1.0"
"web-vitals": "^3.1.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"lint": "eslint .",
"lint:fix": "eslint . --fix && yarn format",
"lint:strict": "eslint --max-warnings=0 .",
"format": "prettier --write './**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc.json",
"format:check": "prettier -c './**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc.json"
"format:check": "prettier -c './**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc.json",
"test-coverage": "yarn test --coverage --watchAll --collectCoverageFrom='src/components/**/*.{ts,tsx}' --collectCoverageFrom='!src/components/**/*.{types,stories,constants,test,spec}.{ts,tsx}'"
},
"browserslist": {
"production": [
Expand All @@ -51,15 +52,22 @@
"devDependencies": {
"@babel/eslint-parser": "^7.19.1",
"@babel/preset-react": "^7.18.6",
"autoprefixer": "^10.4.8",
"eslint": "^8.32.0",
"autoprefixer": "^10.4.13",
"eslint": "^8.34.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-jest-dom": "^4.0.3",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.32.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-unused-imports": "^2.0.0",
"postcss": "^8.4.16",
"prettier": "^2.7.1",
"prettier-plugin-tailwindcss": "^0.1.13",
"tailwindcss": "^3.1.8"
"msw": "^1.0.1",
"postcss": "^8.4.21",
"prettier": "^2.8.4",
"prettier-plugin-tailwindcss": "^0.2.2",
"tailwindcss": "^3.2.6"
},
"jest": {
"transformIgnorePatterns": [
"node_modules/(?!axios)/"
]
}
}
4 changes: 2 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="modal-backdrop"></div>
<div id="modal-card"></div>
<div id="modal-backdrop" data-testid="portal-backdrop"></div>
<div id="modal-card" data-testid="'portal-card"></div>
<div id="root"></div>
</body>
</html>
4 changes: 2 additions & 2 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Routes, Route } from 'react-router-dom';

import Layout from 'components/Layout/Layout';
import LayoutWithOutNav from 'components/Layout/LayoutWithOutNav';
import LayoutWithoutNav from 'components/Layout/LayoutWithoutNav';
import HomePage from 'pages/Home.page';
import RequireAuth from 'components/Auth/RequireAuth';
import Register from 'pages/Register.page';
Expand All @@ -15,7 +15,7 @@ import NotFound from 'pages/NotFound.page';
const App = () => {
return (
<Routes>
<Route element={<LayoutWithOutNav />}>
<Route element={<LayoutWithoutNav />}>
<Route path="register" element={<Register />} />
<Route path="login" element={<Login />} />
<Route path="*" element={<NotFound />} />
Expand Down
31 changes: 31 additions & 0 deletions src/components/Category/CategoryForm.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { render, screen, userEventSetup, act } from 'test-utils';
import CategoryForm from './CategoryForm';

describe('Category Form Component', () => {
test('render correctly', () => {
render(<CategoryForm />);

const categoryNameInputElement = screen.getByRole('textbox', {
name: /category name/i,
});
const createCategoryButtonElement = screen.getByRole('button', {
name: /create category/i,
});
const cancelButtonElement = screen.getByRole('button', { name: /cancel/i });

expect(categoryNameInputElement).toBeInTheDocument();
expect(createCategoryButtonElement).toBeInTheDocument();
expect(cancelButtonElement).toBeInTheDocument();
});

test('input category name correctly', async () => {
const { user } = userEventSetup(<CategoryForm />);

const categoryNameInputElement = screen.getByRole('textbox', {
name: /category name/i,
});

await act(() => user.type(categoryNameInputElement, 'learning'));
expect(categoryNameInputElement).toHaveValue('learning');
});
});
11 changes: 11 additions & 0 deletions src/components/Category/CategoryFormModal.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { render, screen } from 'test-utils';
import CategoryFormModal from './CategoryFormModal';

describe('Category Form Modal Component', () => {
test('not show modal on first render', () => {
render(<CategoryFormModal />);

const categoryHeadingElement = screen.queryByRole('heading', { level: 1 });
expect(categoryHeadingElement).not.toBeInTheDocument();
});
});
32 changes: 32 additions & 0 deletions src/components/Category/CategoryItem.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { render, screen } from 'test-utils';

import CategoryItem from './CategoryItem';

describe('Category Item Component', () => {
test('render correctly', () => {
render(<CategoryItem name={'category-1'} />);

const categoryImageElement = screen.getByRole('img', {
name: /category\-img/i,
});
const categoryNameElement = screen.getByText(/category-1/i);

expect(categoryImageElement).toBeInTheDocument();
expect(categoryNameElement).toBeInTheDocument();
});

// test('delete category correctly', async () => {
// const { user } = userEventSetup(<CategoryItem />);

// const categoryNameElement = await screen.findByText(/rickie/i);
// const deleteButtonElement = await screen.findByRole('button');

// await user.click(deleteButtonElement);

// await waitForElementToBeRemoved(() => {
// screen.queryByText(/rickie/i);
// });

// expect(categoryNameElement).not.toBeInTheDocument();
// });
});
40 changes: 40 additions & 0 deletions src/components/Dashboard/DashboardFormCategory.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { render, screen } from 'test-utils';

import DashboardFormCategory from './DashboardFormCategory';
import { categoriesData } from 'mocks/testingData';

describe('Dashboard Form Category Component', () => {
test('render category list correctly', async () => {
render(<DashboardFormCategory dataCategories={categoriesData} />);

const categoriesListElement = await screen.findAllByRole('listitem');

expect(categoriesListElement).toHaveLength(5);
});

test('if category not added render warning', () => {
render(<DashboardFormCategory isCategoryNotAdded={true} />);

const categoryNotAddedElement = screen.getByText(
/category must be added!/i
);

expect(categoryNotAddedElement).toBeInTheDocument();
});

test('render loading', () => {
render(<DashboardFormCategory isLoadingCategories={true} />);

const loadingElement = screen.getByText(/loading/i);

expect(loadingElement).toBeInTheDocument();
});

test('render add category button correctly', () => {
render(<DashboardFormCategory />);

const buttonElement = screen.getByRole('button', { name: /add category/i });

expect(buttonElement).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion src/components/Home/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const Home = ({ username }) => {
</span>
</h2>
</div>
<img src={todoImage} alt="todo" className="w-40" />
<img src={todoImage} alt="todo" className="w-40" loading="lazy" />
</div>
<ul className="grid grid-cols-2 gap-4 lg:grid-cols-3">
{filterIconName.map((item, index) => {
Expand Down
39 changes: 39 additions & 0 deletions src/components/Home/Home.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { render, screen } from 'test-utils';

import Home from './Home';

describe('Home Component', () => {
test('render username correctly', () => {
render(<Home username={'hutamatr'} />);

const usernameElement = screen.getByRole('heading', {
name: /hello, hutamatr/i,
});
const textElement = screen.getByText(/what do you want to do today?/i);

expect(usernameElement).toBeInTheDocument();
expect(textElement).toBeInTheDocument();
});

test('render initial total todos correctly', () => {
render(<Home />);

const totalTodosElement = screen.getByRole('heading', { level: 2 });

expect(totalTodosElement).toHaveTextContent(/you have 0 list todo/i);
});

test('render image correctly', () => {
render(<Home />);

const totalTodosImageElement = screen.getByAltText(/todo/i);
const categoryImageElement = screen.getByAltText(/category/i);
const doneImageElement = screen.getByAltText(/done/i);
const inProgressImageElement = screen.getByAltText(/in progress/i);

expect(totalTodosImageElement).toBeInTheDocument();
expect(categoryImageElement).toBeInTheDocument();
expect(doneImageElement).toBeInTheDocument();
expect(inProgressImageElement).toBeInTheDocument();
});
});
15 changes: 15 additions & 0 deletions src/components/Layout/Layout.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { render, screen } from 'test-utils';

import Layout from './Layout';

describe('Layout Component', () => {
test('render correctly', () => {
render(<Layout />);

const headerElement = screen.getByRole('banner');
const mainElement = screen.getByRole('main');

expect(headerElement).toBeInTheDocument();
expect(mainElement).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { LoginFormContext } from 'context/Context';
import todoImageOne from 'assets/images/Todo-list-pana.webp';
import todoImageTwo from 'assets/images/task-login.webp';

const LayoutWithOutNav = () => {
const LayoutWithoutNav = () => {
const { onLoginScreen } = useContext(LoginFormContext);

useEffect(() => {}, [onLoginScreen]);
Expand Down Expand Up @@ -44,4 +44,4 @@ const LayoutWithOutNav = () => {
);
};

export default LayoutWithOutNav;
export default LayoutWithoutNav;
21 changes: 21 additions & 0 deletions src/components/Layout/LayoutWithoutNav.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { render, screen } from 'test-utils';

import LayoutWithoutNav from './LayoutWithoutNav';

describe('Layout Without Nav Component', () => {
test('render correctly', () => {
render(<LayoutWithoutNav />);

const mainElement = screen.getByRole('main');

expect(mainElement).toBeInTheDocument();
});

test('render image correctly', () => {
render(<LayoutWithoutNav />);

const figureElement = screen.getByRole('figure');

expect(figureElement).toBeInTheDocument();
});
});
7 changes: 4 additions & 3 deletions src/components/Navigation/Navigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ const Navigation = () => {
const [viewMenu, setMenuView] = useState(false);
const { logout } = useAuth();

const menuIsActive = ({ isActive }) =>
isActive ? 'border-b-2 border-b-orange-100' : '';
const menuIsActive = ({ isActive }) => {
return isActive ? 'border-b-2 border-b-orange-100' : '';
};

const menuViewHandler = () => setMenuView((prevState) => !prevState);

Expand Down Expand Up @@ -92,7 +93,7 @@ const Navigation = () => {
</NavLink>
</li>
{/* eslint-disable-next-line prettier/prettier */}
<div className="dropdown dropdown-end">
<div className="dropdown-end dropdown">
<ProfilePicture
classPhoto="btn-sm hidden sm:block cursor-pointer"
tabIndex={0}
Expand Down
30 changes: 30 additions & 0 deletions src/components/Navigation/Navigation.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { render, screen } from 'test-utils';

import Navigation from './Navigation';

describe('Navigation Component', () => {
test('render correctly', () => {
render(<Navigation />);

const navigationElement = screen.getByRole('navigation');
const ulElement = screen.getAllByRole('list');
const liElement = screen.getAllByRole('listitem');

const listItems = liElement.map((item) => item.textContent);

expect(navigationElement).toBeInTheDocument();
expect(ulElement).toHaveLength(2);
expect(liElement).toHaveLength(7);
expect(listItems).toMatchInlineSnapshot(`
Array [
"Home",
"Dashboard",
"Category",
"Profile",
"Logout",
"Profile",
"Logout",
]
`);
});
});
Loading

0 comments on commit bce28cd

Please sign in to comment.