Merge branch 'react-practice-02' into feat/unit-test-for-function

This commit is contained in:
2023-11-27 09:39:55 +07:00
74 changed files with 981 additions and 231 deletions
+1
View File
@@ -13,6 +13,7 @@ dist-ssr
coverage coverage
*.local *.local
.vscode .vscode
coverage
.jest .jest
# Editor directories and files # Editor directories and files
+12 -5
View File
@@ -18,7 +18,9 @@ import {
initialState, initialState,
reducer, reducer,
} from '@context/UserRoomAvailableContext'; } from '@context/UserRoomAvailableContext';
import { useEffect, useReducer } from 'react'; import { useEffect, useMemo, useReducer } from 'react';
// Services
import { getUserNotBooked } from '@service/userServices'; import { getUserNotBooked } from '@service/userServices';
import { getRoomsAvailable } from '@service/roomServices'; import { getRoomsAvailable } from '@service/roomServices';
@@ -55,16 +57,21 @@ function App() {
load(); load();
}, []); }, []);
const store = useMemo(() => {
return { roomsAvailable, usersAvailable, dispatch };
}, [roomsAvailable, usersAvailable]);
return ( return (
<QueryClientProvider client={queryClient}> <QueryClientProvider client={queryClient}>
<StyleSheetManager shouldForwardProp={shouldForwardProp}> <StyleSheetManager shouldForwardProp={shouldForwardProp}>
<UserRoomAvailableContext.Provider <UserRoomAvailableContext.Provider value={store}>
value={{ roomsAvailable, usersAvailable, dispatch }}
>
<BrowserRouter> <BrowserRouter>
<Routes> <Routes>
<Route element={<AppLayout />}> <Route element={<AppLayout />}>
<Route index element={<Navigate replace to={PATH.DASHBOARD} />} /> <Route
index
element={<Navigate replace to={PATH.DASHBOARD} />}
/>
<Route path={PATH.DASHBOARD} element={<Dashboard />} /> <Route path={PATH.DASHBOARD} element={<Dashboard />} />
<Route path={PATH.USER} element={<User />} /> <Route path={PATH.USER} element={<User />} />
<Route path={PATH.ROOM} element={<Room />} /> <Route path={PATH.ROOM} element={<Room />} />
@@ -16,10 +16,10 @@ const variations: IVariations = {
background-color: var(--danger-btn-color); background-color: var(--danger-btn-color);
color: var(--light-text); color: var(--light-text);
`, `,
}; } as const;
interface IButtonStyle { interface IButtonStyle {
variations?: keyof IVariations; variations?: keyof typeof variations;
} }
const Button = styled.button<IButtonStyle>` const Button = styled.button<IButtonStyle>`
@@ -4,14 +4,14 @@ import { BrowserRouter } from 'react-router-dom';
// Components // Components
import AppLayout from '.'; import AppLayout from '.';
describe('AppLayout testing snapshot', () => { describe('AppLayout', () => {
const wrapper = renderer.create( const wrapper = renderer.create(
<BrowserRouter> <BrowserRouter>
<AppLayout /> <AppLayout />
</BrowserRouter> </BrowserRouter>
); );
test('render', () => { test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
}); });
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`AppLayout testing snapshot render 1`] = ` exports[`AppLayout Should render correctly 1`] = `
<div <div
className="sc-iCoHzw jFLeHb" className="sc-iCoHzw jFLeHb"
> >
@@ -1,17 +1,19 @@
import renderer from 'react-test-renderer' import renderer from 'react-test-renderer';
// Components // Components
import ButtonIcon from '.' import ButtonIcon from '.';
import { HiOutlineLogout } from 'react-icons/hi' import { HiOutlineLogout } from 'react-icons/hi';
describe('ButtonIcon testing snapshot', () => { describe('ButtonIcon', () => {
const wrapper = renderer.create(<ButtonIcon const wrapper = renderer.create(
<ButtonIcon
aria-label="Logout" aria-label="Logout"
icon={<HiOutlineLogout />} icon={<HiOutlineLogout />}
iconStyle={{ size: '23px' }} iconStyle={{ size: '23px' }}
/>) />
);
test('render', () => { test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot() expect(wrapper).toMatchSnapshot();
}) });
}) });
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ButtonIcon testing snapshot render 1`] = ` exports[`ButtonIcon Should render correctly 1`] = `
<button <button
className="sc-bdnyFh bxHnoO" className="sc-bdnyFh bxHnoO"
iconStyle={ iconStyle={
@@ -1,92 +1,5 @@
import { COLOR, SIZE } from '@constant/styles';
import { ReactNode } from 'react'; import { ReactNode } from 'react';
import styled, { css } from 'styled-components'; import { StyledButtonIcon } from './styled';
interface IStyledButtonIcon {
isHaveChildren: boolean;
style?: {
fontSize?: string;
backgroundColor?: string;
color?: string;
};
iconStyle?: {
color?: string;
size?: string;
};
}
const StyledButtonIcon = styled.button<IStyledButtonIcon>`
background: none;
padding: 10px;
transition: all 0.2s;
border: none;
${(props) =>
props.style?.fontSize &&
css`
font-size: ${props.style.fontSize};
`}
${(props) =>
props.style?.fontSize &&
css`
font-size: ${props.style.fontSize};
`}
${(props) =>
props.color &&
css`
font-size: ${props.color};
`}
${(props) =>
props.isHaveChildren
? css`
display: flex;
align-items: center;
gap: 10px;
text-align: left;
width: 100%;
`
: css`
border-radius: var(--radius-md);
`}
&:hover {
background-color: var(--hover-background-color);
}
& svg {
${(props) =>
props.iconStyle?.size &&
css`
width: ${props.iconStyle.size};
height: ${props.iconStyle.size};
`}
${(props) =>
props.iconStyle?.color &&
css`
color: ${props.iconStyle.color};
`}
transition: all 0.3s;
}
`;
StyledButtonIcon.defaultProps = {
style: {
fontSize: SIZE.DEFAULT,
backgroundColor: COLOR.DEFAULT,
color: COLOR.BLACK,
},
iconStyle: {
color: COLOR.BLACK,
size: SIZE.DEFAULT,
},
};
interface IButtonIcon { interface IButtonIcon {
icon: ReactNode; icon: ReactNode;
@@ -0,0 +1,90 @@
import styled, { css } from 'styled-components';
import { COLOR, SIZE } from '@constant/styles';
interface IStyledButtonIcon {
isHaveChildren: boolean;
style?: {
fontSize?: string;
backgroundColor?: string;
color?: string;
};
iconStyle?: {
color?: string;
size?: string;
};
}
const StyledButtonIcon = styled.button<IStyledButtonIcon>`
background: none;
padding: 10px;
transition: all 0.2s;
border: none;
${(props) =>
props.style?.fontSize &&
css`
font-size: ${props.style.fontSize};
`}
${(props) =>
props.style?.fontSize &&
css`
font-size: ${props.style.fontSize};
`}
${(props) =>
props.color &&
css`
font-size: ${props.color};
`}
${(props) =>
props.isHaveChildren
? css`
display: flex;
align-items: center;
gap: 10px;
text-align: left;
width: 100%;
`
: css`
border-radius: var(--radius-md);
`}
&:hover {
background-color: var(--hover-background-color);
}
& svg {
${(props) =>
props.iconStyle?.size &&
css`
width: ${props.iconStyle.size};
height: ${props.iconStyle.size};
`}
${(props) =>
props.iconStyle?.color &&
css`
color: ${props.iconStyle.color};
`}
transition: all 0.3s;
}
`;
StyledButtonIcon.defaultProps = {
style: {
fontSize: SIZE.DEFAULT,
backgroundColor: COLOR.DEFAULT,
color: COLOR.BLACK,
},
iconStyle: {
color: COLOR.BLACK,
size: SIZE.DEFAULT,
},
};
export { StyledButtonIcon };
@@ -3,12 +3,10 @@ import renderer from 'react-test-renderer';
// Components // Components
import ConfirmMessage from '.'; import ConfirmMessage from '.';
describe('ConfirmMessage testing snapshot', () => { describe('ConfirmMessage', () => {
const isDisable = true; const isDisable = true;
const message = 'Hello World!'; const message = 'Hello World!';
const handleOnConfirm = () => { const handleOnConfirm = jest.fn();
console.log('Confirm');
};
const wrapper = renderer.create( const wrapper = renderer.create(
<ConfirmMessage <ConfirmMessage
@@ -18,7 +16,7 @@ describe('ConfirmMessage testing snapshot', () => {
/> />
); );
test('render', () => { test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
}); });
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ConfirmMessage testing snapshot render 1`] = ` exports[`ConfirmMessage Should render correctly 1`] = `
<div <div
className="sc-bdnyFh dukbvo" className="sc-bdnyFh dukbvo"
> >
@@ -11,7 +11,7 @@ exports[`ConfirmMessage testing snapshot render 1`] = `
<button <button
className="sc-gtsqUy eZzwwl" className="sc-gtsqUy eZzwwl"
disabled={true} disabled={true}
onClick={[Function]} onClick={[MockFunction]}
variations="danger" variations="danger"
> >
Delete Delete
@@ -15,7 +15,6 @@ interface IConfirmMessage {
const ConfirmMessage = memo( const ConfirmMessage = memo(
({ message, disabled, onConfirm, onCloseModal }: IConfirmMessage) => { ({ message, disabled, onConfirm, onCloseModal }: IConfirmMessage) => {
return ( return (
<StyledConfirmDelete> <StyledConfirmDelete>
<p>{message}</p> <p>{message}</p>
@@ -1,4 +1,4 @@
import styled from "styled-components"; import styled from 'styled-components';
const StyledConfirmDelete = styled.div` const StyledConfirmDelete = styled.div`
width: 450px; width: 450px;
@@ -1,18 +1,17 @@
import renderer from 'react-test-renderer'; import renderer from 'react-test-renderer';
// Components
import Form from '.'; import Form from '.';
import Input from '@commonStyle/Input'; import Input from '@commonStyle/Input';
// Styled
import { FormBtn } from '@page/User/styled'; import { FormBtn } from '@page/User/styled';
describe('Form testing snapshot', () => { describe('Form ', () => {
const isDisable = true; const isDisable = true;
const errorMessage = 'This is error message'; const errorMessage = 'This is error message';
const handleOnSubmit = () => { const handleOnSubmit = jest.fn();
console.log('Confirm'); const handleOnClick = jest.fn();
};
const handleOnClick = () => {
console.log('On Click');
};
const wrapper = renderer.create( const wrapper = renderer.create(
<Form onSubmit={handleOnSubmit}> <Form onSubmit={handleOnSubmit}>
@@ -35,7 +34,7 @@ describe('Form testing snapshot', () => {
</Form> </Form>
); );
test('render', () => { test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
}); });
@@ -1,9 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Form testing snapshot render 1`] = ` exports[`Form Should render correctly 1`] = `
<form <form
className="sc-bdnyFh bzxSLR" className="sc-bdnyFh bzxSLR"
onSubmit={[Function]} onSubmit={[MockFunction]}
> >
<div <div
className="sc-dlniIP gZHESL" className="sc-dlniIP gZHESL"
@@ -61,7 +61,7 @@ exports[`Form testing snapshot render 1`] = `
</button> </button>
<button <button
className="sc-gKAaef sc-jrsKJM gbgZUe KLoQf" className="sc-gKAaef sc-jrsKJM gbgZUe KLoQf"
onClick={[Function]} onClick={[MockFunction]}
type="button" type="button"
variations="secondary" variations="secondary"
> >
@@ -1,10 +1,12 @@
import renderer from 'react-test-renderer' import renderer from 'react-test-renderer';
import Header from '.'
describe('Header testing snapshot', () => { // Components
const wrapper = renderer.create(<Header accountName='Nezumi' />) import Header from '.';
test('render', () => { describe('Header', () => {
expect(wrapper).toMatchSnapshot() const wrapper = renderer.create(<Header accountName="Nezumi" />);
})
}) test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot();
});
});
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Header testing snapshot render 1`] = ` exports[`Header Should render correctly 1`] = `
<header <header
className="sc-dlniIP cClxoS" className="sc-dlniIP cClxoS"
> >
@@ -1,11 +1,12 @@
import renderer from 'react-test-renderer'; import renderer from 'react-test-renderer';
// Components
import HeaderMenu from '.'; import HeaderMenu from '.';
describe('HeaderMenu testing snapshot', () => { describe('HeaderMenu', () => {
const wrapper = renderer.create(<HeaderMenu />); const wrapper = renderer.create(<HeaderMenu />);
test('render', () => { test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
}); });
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`HeaderMenu testing snapshot render 1`] = ` exports[`HeaderMenu Should render correctly 1`] = `
<ul <ul
className="sc-gtsqUy gOWXQs" className="sc-gtsqUy gOWXQs"
> >
@@ -1,13 +1,12 @@
import renderer from 'react-test-renderer'; import renderer from 'react-test-renderer';
// Components
import Menus from '.'; import Menus from '.';
import { RiEditBoxFill, RiDeleteBin2Line } from 'react-icons/ri'; import { RiEditBoxFill, RiDeleteBin2Line } from 'react-icons/ri';
describe('Menus snapshot testing', () => { describe('Menus', () => {
const id = '123'; const id = '123';
const handleOnClick = () => { const handleOnClick = jest.fn();
console.log('Click');
};
const wrapper = renderer.create( const wrapper = renderer.create(
<Menus> <Menus>
@@ -26,7 +25,7 @@ describe('Menus snapshot testing', () => {
</Menus> </Menus>
); );
test('render', () => { test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
}); });
@@ -1,12 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Menus snapshot testing render 1`] = ` exports[`Menus Should render correctly 1`] = `
<div <div
className="sc-bdnyFh cumhtC" className="sc-gtsqUy lbsvcs"
> >
<button <button
aria-label="Menu item 123" aria-label="Menu item 123"
className="sc-dlniIP jergss" className="sc-hKFymg cjUckY"
onClick={[Function]} onClick={[Function]}
> >
<svg <svg
@@ -5,6 +5,7 @@ import { HiEllipsisVertical } from 'react-icons/hi2';
// Hooks // Hooks
import { useOutsideClick } from '@hook/useOutsideClick'; import { useOutsideClick } from '@hook/useOutsideClick';
import ButtonIcon from '@component/ButtonIcon';
// Styled // Styled
import { StyledMenu, StyledList, StyledToggle } from './styled'; import { StyledMenu, StyledList, StyledToggle } from './styled';
@@ -14,7 +15,8 @@ import MenusContext from '@context/MenuContext';
// Types // Types
import { Nullable } from '@type/common'; import { Nullable } from '@type/common';
import ButtonIcon from '@component/ButtonIcon';
// Constants
import { COLOR } from '@constant/styles'; import { COLOR } from '@constant/styles';
interface IButton { interface IButton {
@@ -1,11 +1,12 @@
import renderer from 'react-test-renderer'; import renderer from 'react-test-renderer';
// Components
import Message from '.'; import Message from '.';
describe('Message testing snapshot', () => { describe('Message', () => {
const wrapper = renderer.create(<Message>This is a message!</Message>); const wrapper = renderer.create(<Message>This is a message!</Message>);
test('render', () => { test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
}); });
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Message testing snapshot render 1`] = ` exports[`Message Should render correctly 1`] = `
<p <p
className="sc-bdnyFh fIKUZt" className="sc-bdnyFh fIKUZt"
> >
@@ -4,7 +4,7 @@ import renderer from 'react-test-renderer';
import Modal from '.'; import Modal from '.';
import Button from '@commonStyle/Button'; import Button from '@commonStyle/Button';
describe('Modal testing snapshot', () => { describe('Modal', () => {
const wrapper = renderer.create( const wrapper = renderer.create(
<Modal> <Modal>
<Modal.Open <Modal.Open
@@ -19,7 +19,7 @@ describe('Modal testing snapshot', () => {
</Modal> </Modal>
); );
test('render', () => { test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
}); });
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Modal testing snapshot render 1`] = ` exports[`Modal Should render correctly 1`] = `
<button <button
className="sc-eCAqax jeAcqZ" className="sc-eCAqax jeAcqZ"
onClick={[Function]} onClick={[Function]}
@@ -1,17 +1,17 @@
import renderer from 'react-test-renderer'; import renderer from 'react-test-renderer';
import { BrowserRouter } from 'react-router-dom';
// Components // Components
import Nav from '.'; import Nav from '.';
import { BrowserRouter } from 'react-router-dom';
describe('Nav testing snapshot', () => { describe('Nav', () => {
const wrapper = renderer.create( const wrapper = renderer.create(
<BrowserRouter> <BrowserRouter>
<Nav /> <Nav />
</BrowserRouter> </BrowserRouter>
); );
test('render', () => { test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
}); });
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Nav testing snapshot render 1`] = ` exports[`Nav Should render correctly 1`] = `
<nav <nav
className="sc-bdnyFh gGCifp" className="sc-bdnyFh gGCifp"
> >
@@ -1,9 +1,10 @@
import renderer from 'react-test-renderer'; import renderer from 'react-test-renderer';
import Order from '.';
import { BrowserRouter } from 'react-router-dom'; import { BrowserRouter } from 'react-router-dom';
describe('<Order.test />', () => { // Components
import Order from '.';
describe('Order', () => {
const options = [ const options = [
{ {
value: 'Value 1', value: 'Value 1',
@@ -21,7 +22,7 @@ describe('<Order.test />', () => {
</BrowserRouter> </BrowserRouter>
); );
test('render', () => { test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
}); });
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Order.test /> render 1`] = ` exports[`Order Should render correctly 1`] = `
<div <div
className="sc-bdnyFh aZFGz" className="sc-bdnyFh aZFGz"
> >
@@ -1,9 +1,10 @@
import renderer from 'react-test-renderer'; import renderer from 'react-test-renderer';
import Search from '.';
import { BrowserRouter } from 'react-router-dom'; import { BrowserRouter } from 'react-router-dom';
describe('Search testing snapshot', () => { // Components
import Search from '.';
describe('Search', () => {
const placeHolder = 'Search placeholder...'; const placeHolder = 'Search placeholder...';
const wrapper = renderer.create( const wrapper = renderer.create(
<BrowserRouter> <BrowserRouter>
@@ -11,7 +12,7 @@ describe('Search testing snapshot', () => {
</BrowserRouter> </BrowserRouter>
); );
test('render', () => { test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
}); });
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Search testing snapshot render 1`] = ` exports[`Search Should render correctly 1`] = `
<input <input
className="sc-bdnyFh eAgOPb" className="sc-bdnyFh eAgOPb"
onChange={[Function]} onChange={[Function]}
@@ -1,11 +1,13 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { useSearchParams } from 'react-router-dom';
// Styled // Styled
import { StyledSearch } from './styled'; import { StyledSearch } from './styled';
// Hooks // Hooks
import { useDebounce } from '@hook/useDebounce'; import { useDebounce } from '@hook/useDebounce';
import { useSearchParams } from 'react-router-dom';
// Types
import { Nullable } from '@type/common'; import { Nullable } from '@type/common';
interface ISearch { interface ISearch {
@@ -1,8 +1,9 @@
import renderer from 'react-test-renderer'; import renderer from 'react-test-renderer';
// Components
import Select from '.'; import Select from '.';
describe('Select testing snapshot', () => { describe('Select', () => {
const options = [ const options = [
{ {
label: 'Option 1', label: 'Option 1',
@@ -14,9 +15,7 @@ describe('Select testing snapshot', () => {
} }
]; ];
const value = 'Temp value'; const value = 'Temp value';
const handleOnChange = () => { const handleOnChange = jest.fn();
console.log('On change');
}
const wrapper = renderer.create( const wrapper = renderer.create(
<Select <Select
@@ -27,7 +26,7 @@ describe('Select testing snapshot', () => {
/> />
); );
test('render', () => { test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
}); });
@@ -1,10 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Select testing snapshot render 1`] = ` exports[`Select Should render correctly 1`] = `
<select <select
aria-label="Sort" aria-label="Sort"
className="sc-bdnyFh dqXTRP" className="sc-bdnyFh dqXTRP"
onChange={[Function]} onChange={[MockFunction]}
value="Temp value" value="Temp value"
> >
<option <option
@@ -4,14 +4,14 @@ import { BrowserRouter } from 'react-router-dom';
// Components // Components
import Sidebar from '.'; import Sidebar from '.';
describe('Sidebar testing snapshot', () => { describe('Sidebar', () => {
const wrapper = renderer.create( const wrapper = renderer.create(
<BrowserRouter> <BrowserRouter>
<Sidebar heading="Hotel Management" /> <Sidebar heading="Hotel Management" />
</BrowserRouter> </BrowserRouter>
); );
test('render', () => { test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
}); });
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Sidebar testing snapshot render 1`] = ` exports[`Sidebar Should render correctly 1`] = `
<aside <aside
className="sc-dlniIP dfcuiS" className="sc-dlniIP dfcuiS"
> >
@@ -1,9 +1,10 @@
import renderer from 'react-test-renderer'; import renderer from 'react-test-renderer';
import SortBy from '.';
import { BrowserRouter } from 'react-router-dom'; import { BrowserRouter } from 'react-router-dom';
describe('<SortBy.test />', () => { // Components
import SortBy from '.';
describe('SortBy', () => {
const options = [ const options = [
{ {
label: 'Option 1', label: 'Option 1',
@@ -20,7 +21,7 @@ describe('<SortBy.test />', () => {
</BrowserRouter> </BrowserRouter>
); );
test('render', () => { test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
}); });
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<SortBy.test /> render 1`] = ` exports[`SortBy Should render correctly 1`] = `
<select <select
aria-label="Sort" aria-label="Sort"
className="sc-bdnyFh dqXTRP" className="sc-bdnyFh dqXTRP"
@@ -1,13 +1,16 @@
import renderer from 'react-test-renderer'; import renderer from 'react-test-renderer';
// Components
import Table from '.'; import Table from '.';
// Types
import { IUser } from '@type/users'; import { IUser } from '@type/users';
interface ITableRow { interface ITableRow {
user: IUser; user: IUser;
} }
describe('Table testing snapshot', () => { describe('Table', () => {
const columnName = ['Column 1', 'Column 2']; const columnName = ['Column 1', 'Column 2'];
const tempUser: IUser[] = [ const tempUser: IUser[] = [
{ {
@@ -23,7 +26,7 @@ describe('Table testing snapshot', () => {
isBooked: false, isBooked: false,
}, },
]; ];
const TableRow = ({user}: ITableRow) => { const TableRow = ({ user }: ITableRow) => {
const { id, name, phone, isBooked } = user; const { id, name, phone, isBooked } = user;
return ( return (
@@ -35,7 +38,7 @@ describe('Table testing snapshot', () => {
</Table.Row> </Table.Row>
); );
}; };
const renderRow = (user: IUser) => <TableRow user={user} key={user.id}/> const renderRow = (user: IUser) => <TableRow user={user} key={user.id} />;
const wrapper = renderer.create( const wrapper = renderer.create(
<Table columns="10% 35% 30% 15% 10%"> <Table columns="10% 35% 30% 15% 10%">
@@ -44,7 +47,7 @@ describe('Table testing snapshot', () => {
</Table> </Table>
); );
test('render', () => { test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
}); });
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Table testing snapshot render 1`] = ` exports[`Table Should render correctly 1`] = `
<div <div
className="sc-bdnyFh eEibLN" className="sc-bdnyFh eEibLN"
> >
@@ -1,11 +1,12 @@
import renderer from 'react-test-renderer'; import renderer from 'react-test-renderer';
// Components
import Toast from '.'; import Toast from '.';
describe('Toast testing snapshot', () => { describe('Toast', () => {
const wrapper = renderer.create(<Toast />); const wrapper = renderer.create(<Toast />);
test('render', () => { test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
}); });
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Toast testing snapshot render 1`] = ` exports[`Toast Should render correctly 1`] = `
<div <div
onMouseEnter={[Function]} onMouseEnter={[Function]}
onMouseLeave={[Function]} onMouseLeave={[Function]}
-16
View File
@@ -43,20 +43,6 @@ const ROOM_PAGE = {
], ],
}; };
const INIT_VALUE_USER_FORM = {
name: '',
id: 0,
identifiedCode: '',
phone: '',
};
const INIT_VALUE_ROOM_FORM = {
name: '',
id: 0,
price: 0,
discount: 0,
};
const FORM = { const FORM = {
EDIT: 'edit', EDIT: 'edit',
DELETE: 'delete', DELETE: 'delete',
@@ -76,6 +62,4 @@ export {
FORM, FORM,
REGEX, REGEX,
ORDERBY_OPTIONS, ORDERBY_OPTIONS,
INIT_VALUE_USER_FORM,
INIT_VALUE_ROOM_FORM,
}; };
-2
View File
@@ -2,5 +2,3 @@ export const DASHBOARD = '/dashboard';
export const USER = '/user'; export const USER = '/user';
export const ROOM = '/room'; export const ROOM = '/room';
export const OTHER_PATH = '*'; export const OTHER_PATH = '*';
export const USER_PATH = 'users';
export const ROOM_PATH = 'rooms';
@@ -1,6 +1,8 @@
import { IDataState } from '@type/common';
import { Dispatch, createContext } from 'react'; import { Dispatch, createContext } from 'react';
// Types
import { IDataState } from '@type/common';
interface IUserRoomState { interface IUserRoomState {
usersAvailable: IDataState[]; usersAvailable: IDataState[];
roomsAvailable: IDataState[]; roomsAvailable: IDataState[];
@@ -36,16 +38,19 @@ const initialState: IUserRoomState = {
const reducer = (state: IUserRoomState, action: IAction) => { const reducer = (state: IUserRoomState, action: IAction) => {
switch (action.type) { switch (action.type) {
case 'initRoom': case 'initRoom':
return { return {
...state, ...state,
roomsAvailable: action.payload, roomsAvailable: action.payload,
}; };
case 'initUser': case 'initUser':
return { return {
...state, ...state,
usersAvailable: action.payload, usersAvailable: action.payload,
}; };
case 'addUser': { case 'addUser': {
const tempArr = state.usersAvailable; const tempArr = state.usersAvailable;
const itemExist = state.usersAvailable.find( const itemExist = state.usersAvailable.find(
@@ -61,6 +66,7 @@ const reducer = (state: IUserRoomState, action: IAction) => {
usersAvailable: tempArr, usersAvailable: tempArr,
}; };
} }
case 'updateUserName': { case 'updateUserName': {
const tempArr = state.usersAvailable; const tempArr = state.usersAvailable;
@@ -77,6 +83,7 @@ const reducer = (state: IUserRoomState, action: IAction) => {
usersAvailable: tempArr, usersAvailable: tempArr,
}; };
} }
case 'removeUser': case 'removeUser':
return { return {
...state, ...state,
@@ -84,6 +91,7 @@ const reducer = (state: IUserRoomState, action: IAction) => {
(item) => item.id !== action.payload[0].id (item) => item.id !== action.payload[0].id
), ),
}; };
case 'addRoom': { case 'addRoom': {
const tempArr = state.roomsAvailable; const tempArr = state.roomsAvailable;
const itemExist = state.roomsAvailable.find( const itemExist = state.roomsAvailable.find(
@@ -99,6 +107,7 @@ const reducer = (state: IUserRoomState, action: IAction) => {
roomsAvailable: tempArr, roomsAvailable: tempArr,
}; };
} }
case 'updateRoomName': { case 'updateRoomName': {
const tempArr = state.roomsAvailable; const tempArr = state.roomsAvailable;
@@ -115,6 +124,7 @@ const reducer = (state: IUserRoomState, action: IAction) => {
roomsAvailable: tempArr, roomsAvailable: tempArr,
}; };
} }
case 'removeRoom': case 'removeRoom':
return { return {
...state, ...state,
@@ -122,6 +132,7 @@ const reducer = (state: IUserRoomState, action: IAction) => {
(item) => item.id !== action.payload[0].id (item) => item.id !== action.payload[0].id
), ),
}; };
default: default:
throw new Error('Action unknown'); throw new Error('Action unknown');
} }
@@ -6,6 +6,8 @@ import { createRoom as createRoomFn } from '@service/roomServices';
// Constants // Constants
import { ADD_SUCCESS } from '@constant/messages'; import { ADD_SUCCESS } from '@constant/messages';
// Hooks
import { useUserRoomAvailable } from '@hook/useUserRoomAvailable'; import { useUserRoomAvailable } from '@hook/useUserRoomAvailable';
/** /**
@@ -6,6 +6,8 @@ import { updateRoom as updateRoomFn } from '@service/roomServices';
// Constants // Constants
import { UPDATE_SUCCESS } from '@constant/messages'; import { UPDATE_SUCCESS } from '@constant/messages';
// Hooks
import { useUserRoomAvailable } from '@hook/useUserRoomAvailable'; import { useUserRoomAvailable } from '@hook/useUserRoomAvailable';
/** /**
@@ -1,6 +1,8 @@
import { UserRoomAvailableContext } from '@context/UserRoomAvailableContext';
import { useContext } from 'react'; import { useContext } from 'react';
// Contexts
import { UserRoomAvailableContext } from '@context/UserRoomAvailableContext';
const useUserRoomAvailable = () => { const useUserRoomAvailable = () => {
const context = useContext(UserRoomAvailableContext); const context = useContext(UserRoomAvailableContext);
@@ -6,6 +6,8 @@ import { createUser as createUserFn } from '@service/userServices';
// Constants // Constants
import { ADD_SUCCESS } from '@constant/messages'; import { ADD_SUCCESS } from '@constant/messages';
// Hooks
import { useUserRoomAvailable } from '@hook/useUserRoomAvailable'; import { useUserRoomAvailable } from '@hook/useUserRoomAvailable';
/** /**
@@ -6,6 +6,8 @@ import { updateUser as updateUserFn } from '@service/userServices';
// Messages // Messages
import { UPDATE_SUCCESS } from '@constant/messages'; import { UPDATE_SUCCESS } from '@constant/messages';
// Hooks
import { useUserRoomAvailable } from '@hook/useUserRoomAvailable'; import { useUserRoomAvailable } from '@hook/useUserRoomAvailable';
/** /**
+5 -5
View File
@@ -1,9 +1,9 @@
import toast from "react-hot-toast"; import toast from 'react-hot-toast';
import { useQuery } from "@tanstack/react-query"; import { useQuery } from '@tanstack/react-query';
import { useSearchParams } from "react-router-dom"; import { useSearchParams } from 'react-router-dom';
// Services // Services
import { getAllUsers } from "@service/userServices"; import { getAllUsers } from '@service/userServices';
/** /**
* Fetch data of users from database * Fetch data of users from database
@@ -13,7 +13,7 @@ const useUsers = () => {
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
const sortByValue = searchParams.get('sortBy') || 'id'; const sortByValue = searchParams.get('sortBy') || 'id';
const orderByValue = searchParams.get('orderBy') || 'asc'; const orderByValue = searchParams.get('orderBy') || 'asc';
const phoneSearch = searchParams.get('search') || '' const phoneSearch = searchParams.get('search') || '';
const { const {
isLoading, isLoading,
+3 -1
View File
@@ -1,6 +1,8 @@
import { useUserRoomAvailable } from '@hook/useUserRoomAvailable';
import styled from 'styled-components'; import styled from 'styled-components';
// Hooks
import { useUserRoomAvailable } from '@hook/useUserRoomAvailable';
const StyledDashboard = styled.main` const StyledDashboard = styled.main`
padding: 20px; padding: 20px;
`; `;
@@ -0,0 +1,22 @@
import { BrowserRouter } from 'react-router-dom';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import renderer from 'react-test-renderer';
// Components
import RoomForm from '../RoomForm';
describe('RoomForm', () => {
const queryClient = new QueryClient();
const wrapper = renderer.create(
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<RoomForm />
</BrowserRouter>
</QueryClientProvider>
);
test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot();
});
});
@@ -0,0 +1,28 @@
import renderer from 'react-test-renderer';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
// Types
import { IRoom } from '@type/rooms';
// Components
import RoomRow from '../RoomRow';
describe('RoomRow', () => {
const tempRoom: IRoom = {
id: 1,
name: 'Temp Room',
price: 250,
status: true,
};
const queryClient = new QueryClient();
const wrapper = renderer.create(
<QueryClientProvider client={queryClient}>
<RoomRow room={tempRoom} key={tempRoom.id} />
</QueryClientProvider>
);
test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot();
});
});
@@ -0,0 +1,22 @@
import renderer from 'react-test-renderer';
import { BrowserRouter } from 'react-router-dom';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
// Components
import RoomTable from '../RoomTable';
describe('RoomTable', () => {
const queryClient = new QueryClient();
const wrapper = renderer.create(
<BrowserRouter>
<QueryClientProvider client={queryClient}>
<RoomTable />
</QueryClientProvider>
</BrowserRouter>
);
test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot();
});
});
@@ -0,0 +1,67 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`RoomForm Should render correctly 1`] = `
<form
className="sc-dlniIP bCPNqw"
onSubmit={[Function]}
>
<div
className="sc-eCAqax eozPUK"
>
<label
className="sc-jSFipO cMYxin"
>
Name
</label>
<div>
<input
className="sc-gtsqUy fGZPSU"
id="name"
name="name"
onBlur={[Function]}
onChange={[Function]}
type="text"
/>
</div>
</div>
<div
className="sc-eCAqax eozPUK"
>
<label
className="sc-jSFipO cMYxin"
>
Price
</label>
<div>
<input
className="sc-gtsqUy fGZPSU"
id="price"
name="price"
onBlur={[Function]}
onChange={[Function]}
type="text"
/>
</div>
</div>
<div
className="sc-hKFymg dteuGK"
>
<button
className="sc-bdnyFh sc-iCoHzw hHmoPp jAHgeA"
disabled={false}
name="submit"
type="submit"
variations="primary"
>
Add
</button>
<button
className="sc-bdnyFh sc-iCoHzw bjdOKm jAHgeA"
type="button"
variations="secondary"
>
Close
</button>
</div>
</form>
`;
@@ -0,0 +1,53 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`RoomRow Should render correctly 1`] = `
<div
className="sc-crzpnZ sc-bqGGcD gIMFtm jqrNRF"
>
<div>
1
</div>
<div>
Temp Room
</div>
<div>
$250.00
</div>
<div>
Unavailable
</div>
<div>
<div
className="sc-fnVZQs CCxtf"
>
<button
aria-label="Menu item 1"
className="sc-bkbjWr fCztjK"
onClick={[Function]}
>
<svg
aria-hidden="true"
fill="currentColor"
height="1em"
stroke="currentColor"
strokeWidth="0"
style={
{
"color": undefined,
}
}
viewBox="0 0 24 24"
width="1em"
xmlns="http://www.w3.org/2000/svg"
>
<path
clipRule="evenodd"
d="M10.5 6a1.5 1.5 0 113 0 1.5 1.5 0 01-3 0zm0 6a1.5 1.5 0 113 0 1.5 1.5 0 01-3 0zm0 6a1.5 1.5 0 113 0 1.5 1.5 0 01-3 0z"
fillRule="evenodd"
/>
</svg>
</button>
</div>
</div>
</div>
`;
@@ -0,0 +1,63 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`RoomTable Should render correctly 1`] = `
<div
className="sc-iJCSeZ crZyCc"
type="vertical"
>
<div
className="sc-lmgPJu cuMSiO"
>
<div
className="sc-crzpnZ iahNiP"
>
<button
active={true}
className="sc-dItHI guVVWw"
disabled={true}
onClick={[Function]}
>
Ascending
</button>
<button
active={false}
className="sc-dItHI fIRqtD"
disabled={false}
onClick={[Function]}
>
Descending
</button>
</div>
<select
aria-label="Sort"
className="sc-iqAbyq czAJZn"
onChange={[Function]}
value=""
>
<option
value="id"
>
Sort by id
</option>
<option
value="name"
>
Sort by name
</option>
<option
value="price"
>
Sort by price
</option>
</select>
<input
className="sc-kEqXeH jMVPeG"
onChange={[Function]}
placeholder="Search by name..."
/>
</div>
<div
className="sc-giAruI hMNXks"
/>
</div>
`;
@@ -0,0 +1,84 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Room Should render correctly 1`] = `
<main
className="sc-iwaiBT gPCYSC"
>
<div
className="sc-iJCSeZ jDHUlN"
type="horizontal"
>
<h2
className="sc-cxNGUP ffcGOQ"
>
List Room
</h2>
<button
className="sc-bqGGcD cVmQmy"
onClick={[Function]}
variations="primary"
>
Add room
</button>
</div>
<div
className="sc-iJCSeZ crZyCc"
type="vertical"
>
<div
className="sc-lmgPJu cuMSiO"
>
<div
className="sc-crzpnZ iahNiP"
>
<button
active={true}
className="sc-dItHI guVVWw"
disabled={true}
onClick={[Function]}
>
Ascending
</button>
<button
active={false}
className="sc-dItHI fIRqtD"
disabled={false}
onClick={[Function]}
>
Descending
</button>
</div>
<select
aria-label="Sort"
className="sc-iqAbyq czAJZn"
onChange={[Function]}
value=""
>
<option
value="id"
>
Sort by id
</option>
<option
value="name"
>
Sort by name
</option>
<option
value="price"
>
Sort by price
</option>
</select>
<input
className="sc-kEqXeH jMVPeG"
onChange={[Function]}
placeholder="Search by name..."
/>
</div>
<div
className="sc-giAruI hMNXks"
/>
</div>
</main>
`;
@@ -0,0 +1,22 @@
import Room from '..';
import { BrowserRouter } from 'react-router-dom';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
// Components
import renderer from 'react-test-renderer';
describe('Room', () => {
const queryClient = new QueryClient();
const wrapper = renderer.create(
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<Room />
</BrowserRouter>
</QueryClientProvider>
);
test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot();
});
});
+1 -1
View File
@@ -1,5 +1,5 @@
// Components // Components
import RoomTable from './RomTable'; import RoomTable from './RoomTable';
import RoomForm from './RoomForm'; import RoomForm from './RoomForm';
import Modal from '@component/Modal'; import Modal from '@component/Modal';
@@ -0,0 +1,22 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { BrowserRouter } from 'react-router-dom';
import renderer from 'react-test-renderer';
// Components
import UserForm from '../UserForm';
describe('UserForm', () => {
const queryClient = new QueryClient();
const wrapper = renderer.create(
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<UserForm />
</BrowserRouter>
</QueryClientProvider>
);
test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot();
});
});
@@ -0,0 +1,27 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import renderer from 'react-test-renderer';
// Types
import { IUser } from '@type/users';
// Components
import UserRow from '../UserRow';
describe('UserRow', () => {
const tempUser: IUser = {
id: 1,
name: 'Temp Room',
phone: '0324421232',
isBooked: false,
};
const queryClient = new QueryClient();
const wrapper = renderer.create(
<QueryClientProvider client={queryClient}>
<UserRow user={tempUser} />
</QueryClientProvider>
);
test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot();
});
});
@@ -0,0 +1,22 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { BrowserRouter } from 'react-router-dom';
import renderer from 'react-test-renderer';
// Components
import RoomTable from '@page/Room/RoomTable';
describe('UserTable', () => {
const queryClient = new QueryClient();
const wrapper = renderer.create(
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<RoomTable />
</BrowserRouter>
</QueryClientProvider>
);
test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot();
});
});
@@ -0,0 +1,67 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`UserForm Should render correctly 1`] = `
<form
className="sc-gtsqUy jMGskL"
onSubmit={[Function]}
>
<div
className="sc-hKFymg frexHr"
>
<label
className="sc-eCAqax dnXnhF"
>
Full Name
</label>
<div>
<input
className="sc-bdnyFh gejiRq"
id="name"
name="name"
onBlur={[Function]}
onChange={[Function]}
type="text"
/>
</div>
</div>
<div
className="sc-hKFymg frexHr"
>
<label
className="sc-eCAqax dnXnhF"
>
Phone
</label>
<div>
<input
className="sc-bdnyFh gejiRq"
id="phone"
name="phone"
onBlur={[Function]}
onChange={[Function]}
type="text"
/>
</div>
</div>
<div
className="sc-dlniIP hBqqvG"
>
<button
className="sc-gKAaef sc-jrsKJM gifCOZ KLoQf"
disabled={true}
name="submit"
type="submit"
variations="primary"
>
Add
</button>
<button
className="sc-gKAaef sc-jrsKJM gbgZUe KLoQf"
type="button"
variations="secondary"
>
Close
</button>
</div>
</form>
`;
@@ -0,0 +1,53 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`UserRow Should render correctly 1`] = `
<div
className="sc-jSFipO sc-iCoHzw hTfHNc eWZMfB"
>
<div>
1
</div>
<div>
Temp Room
</div>
<div>
0324421232
</div>
<div>
No
</div>
<div>
<div
className="sc-jrsKJM cdPhia"
>
<button
aria-label="Menu item 1"
className="sc-iqAbyq fyjyXl"
onClick={[Function]}
>
<svg
aria-hidden="true"
fill="currentColor"
height="1em"
stroke="currentColor"
strokeWidth="0"
style={
{
"color": undefined,
}
}
viewBox="0 0 24 24"
width="1em"
xmlns="http://www.w3.org/2000/svg"
>
<path
clipRule="evenodd"
d="M10.5 6a1.5 1.5 0 113 0 1.5 1.5 0 01-3 0zm0 6a1.5 1.5 0 113 0 1.5 1.5 0 01-3 0zm0 6a1.5 1.5 0 113 0 1.5 1.5 0 01-3 0z"
fillRule="evenodd"
/>
</svg>
</button>
</div>
</div>
</div>
`;
@@ -0,0 +1,63 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`UserTable Should render correctly 1`] = `
<div
className="sc-iJCSeZ crZyCc"
type="vertical"
>
<div
className="sc-lmgPJu cuMSiO"
>
<div
className="sc-crzpnZ iahNiP"
>
<button
active={true}
className="sc-dItHI guVVWw"
disabled={true}
onClick={[Function]}
>
Ascending
</button>
<button
active={false}
className="sc-dItHI fIRqtD"
disabled={false}
onClick={[Function]}
>
Descending
</button>
</div>
<select
aria-label="Sort"
className="sc-iqAbyq czAJZn"
onChange={[Function]}
value=""
>
<option
value="id"
>
Sort by id
</option>
<option
value="name"
>
Sort by name
</option>
<option
value="price"
>
Sort by price
</option>
</select>
<input
className="sc-kEqXeH jMVPeG"
onChange={[Function]}
placeholder="Search by name..."
/>
</div>
<div
className="sc-giAruI hMNXks"
/>
</div>
`;
@@ -0,0 +1,84 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`User Should render correctly 1`] = `
<main
className="sc-fKgKDd iDHRyD"
>
<div
className="sc-lmgPJu bFEqIE"
type="horizontal"
>
<h2
className="sc-bCwene htGYaf"
>
List User
</h2>
<button
className="sc-kfYpNk QIeuT"
onClick={[Function]}
variations="primary"
>
Add user
</button>
</div>
<div
className="sc-lmgPJu hehIVl"
type="vertical"
>
<div
className="sc-iwaiBT eOzYWb"
>
<div
className="sc-crzpnZ iahNiP"
>
<button
active={true}
className="sc-dItHI guVVWw"
disabled={true}
onClick={[Function]}
>
Ascending
</button>
<button
active={false}
className="sc-dItHI fIRqtD"
disabled={false}
onClick={[Function]}
>
Descending
</button>
</div>
<select
aria-label="Sort"
className="sc-iqAbyq czAJZn"
onChange={[Function]}
value=""
>
<option
value="id"
>
Sort by id
</option>
<option
value="name"
>
Sort by name
</option>
<option
value="phone"
>
Sort by phone
</option>
</select>
<input
className="sc-kEqXeH jMVPeG"
onChange={[Function]}
placeholder="Search by phone..."
/>
</div>
<div
className="sc-iJCSeZ gDbWTd"
/>
</div>
</main>
`;
@@ -0,0 +1,22 @@
import renderer from 'react-test-renderer';
import { BrowserRouter } from 'react-router-dom';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
// Components
import User from '..';
describe('User', () => {
const queryClient = new QueryClient();
const wrapper = renderer.create(
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<User />
</BrowserRouter>
</QueryClientProvider>
);
test('Should render correctly', () => {
expect(wrapper).toMatchSnapshot();
});
});
@@ -1,9 +1,9 @@
// Types // Types
import { IRoom } from '@type/rooms'; import { IRoom } from '@type/rooms';
import { IDataState } from '@type/common';
// Services // Services
import supabase from './supabaseService'; import supabase from './supabaseService';
import { IDataState } from '@type/common';
// Constants // Constants
const ROOMS_TABLE = 'rooms'; const ROOMS_TABLE = 'rooms';
@@ -25,7 +25,7 @@ const getAllRooms = async (
.from(ROOMS_TABLE) .from(ROOMS_TABLE)
.select('*') .select('*')
.order(sortBy, { ascending: orderBy === 'asc' }) .order(sortBy, { ascending: orderBy === 'asc' })
.like('name', `%${roomName}%`); .ilike('name', `%${roomName}%`);
if (error) { if (error) {
console.error(error.message); console.error(error.message);
@@ -1,8 +1,10 @@
import { createClient } from "@supabase/supabase-js"; import { createClient } from '@supabase/supabase-js';
import { Database } from "@type/supabase";
// Types
import { Database } from '@type/supabase';
// Constants // Constants
import { supabaseKey, supabaseUrl } from "@constant/config"; import { supabaseKey, supabaseUrl } from '@constant/config';
const supabase = createClient<Database>(supabaseUrl, supabaseKey!); const supabase = createClient<Database>(supabaseUrl, supabaseKey!);
@@ -1,9 +1,9 @@
// Types // Types
import { IUser } from '@type/users'; import { IUser } from '@type/users';
import { IDataState } from '@type/common';
// Services // Services
import supabase from './supabaseService'; import supabase from './supabaseService';
import { IDataState } from '@type/common';
const USERS_TABLE = 'users'; const USERS_TABLE = 'users';
const ERROR_FETCHING = "Users can't be loaded!"; const ERROR_FETCHING = "Users can't be loaded!";
@@ -65,7 +65,7 @@ const getAllUsers = async (
.from(USERS_TABLE) .from(USERS_TABLE)
.select('*') .select('*')
.order(sortBy, { ascending: orderBy === 'asc' }) .order(sortBy, { ascending: orderBy === 'asc' })
.like('phone', `%${phoneSearch}%`); .ilike('phone', `%${phoneSearch}%`);
if (error) { if (error) {
console.error(error.message); console.error(error.message);