diff --git a/src/app/components/ButtonGroup/ButtonGroup.style.ts b/src/app/components/ButtonGroup/ButtonGroup.style.ts new file mode 100644 index 0000000..058a09f --- /dev/null +++ b/src/app/components/ButtonGroup/ButtonGroup.style.ts @@ -0,0 +1,13 @@ +export const styles = { + button: { + width: "22%", + height: "90%", + fontSize: "11px", + borderRadius: "15px", + margin: "3px", + }, + buttonsContainer: { + width: "30%", + height: "90%", + }, +}; diff --git a/src/app/components/ButtonGroup/ButtonGroup.test.tsx b/src/app/components/ButtonGroup/ButtonGroup.test.tsx new file mode 100644 index 0000000..5843521 --- /dev/null +++ b/src/app/components/ButtonGroup/ButtonGroup.test.tsx @@ -0,0 +1,53 @@ +import "@testing-library/jest-dom/jest-globals"; +import "@testing-library/jest-dom"; +import { render, screen, fireEvent } from "@testing-library/react"; +import ButtonGroup from "@/app/components/ButtonGroup"; +import { ButtonGroupProps } from "@/app/general/interfaces"; + +describe("ButtonGroup Component", () => { + const mockButtons = [ + { text: "Button 1", onClick: jest.fn() }, + { text: "Button 2", onClick: jest.fn() }, + { text: "Button 3", onClick: jest.fn() }, + ]; + + const defaultProps: ButtonGroupProps = { + buttonList: mockButtons, + buttonStyle: { color: "red" }, + containerStyle: { backgroundColor: "blue" }, + }; + + it("renders all buttons correctly", () => { + render(); + + mockButtons.forEach((button) => { + expect(screen.getByText(button.text)).toBeInTheDocument(); + }); + }); + + it("applies custom container styles", () => { + const { container } = render(); + + const boxElement = container.querySelector("div"); + expect(boxElement).toHaveStyle("background-color: blue"); + }); + + it("applies custom button styles", () => { + render(); + + const buttonElements = screen.getAllByRole("button"); + buttonElements.forEach((button) => { + expect(button).toHaveStyle("color: red"); + }); + }); + + it("calls the correct onClick handler when a button is clicked", () => { + render(); + + const buttons = screen.getAllByRole("button"); + buttons.forEach((button, index) => { + fireEvent.click(button); + expect(mockButtons[index].onClick).toHaveBeenCalledTimes(1); + }); + }); +}); diff --git a/src/app/components/ButtonGroup/ButtonGroup.tsx b/src/app/components/ButtonGroup/ButtonGroup.tsx new file mode 100644 index 0000000..7c23b84 --- /dev/null +++ b/src/app/components/ButtonGroup/ButtonGroup.tsx @@ -0,0 +1,26 @@ +"use client"; +import { ButtonGroupProps } from "@/app/general/interfaces"; +import { styles } from "./ButtonGroup.style"; +import { Box } from "@mui/material"; +import CustomButton from "@/app/components/CustomButton"; + +export default function ButtonGroup({ + buttonList, + buttonStyle, + containerStyle, +}: ButtonGroupProps) { + return ( + + {buttonList.map((button, index) => ( + + ))} + + ); +} diff --git a/src/app/components/ButtonGroup/index.ts b/src/app/components/ButtonGroup/index.ts new file mode 100644 index 0000000..c2127bc --- /dev/null +++ b/src/app/components/ButtonGroup/index.ts @@ -0,0 +1,3 @@ +import ButtonGroup from './ButtonGroup' + +export default ButtonGroup; \ No newline at end of file diff --git a/src/app/components/ChatBox/ChatBox.style.ts b/src/app/components/ChatBox/ChatBox.style.ts index ad44ead..6bb36c8 100755 --- a/src/app/components/ChatBox/ChatBox.style.ts +++ b/src/app/components/ChatBox/ChatBox.style.ts @@ -4,5 +4,6 @@ export const styles = { backgroundColor: "background.default", width: "500px", alignSelf: "center", + marginBottom: 3, }, }; diff --git a/src/app/components/Header/Header.style.ts b/src/app/components/Header/Header.style.ts index 38579d4..9f8dc4d 100644 --- a/src/app/components/Header/Header.style.ts +++ b/src/app/components/Header/Header.style.ts @@ -12,12 +12,20 @@ export const styles = { }, button: { width: "22%", - height: "80%", - fontSize: "14px", + height: "90%", + fontSize: "11px", borderRadius: "15px", - margin: "5px", + margin: "3px", }, buttonsContainer: { width: "30%", + height: "90%", + }, + rightAlign: { + textAlign: "right", + width: "36%", + }, + rightButton: { + width: "18%", }, }; diff --git a/src/app/components/Header/Header.tsx b/src/app/components/Header/Header.tsx index 895fdab..22606d9 100644 --- a/src/app/components/Header/Header.tsx +++ b/src/app/components/Header/Header.tsx @@ -4,7 +4,7 @@ import { styles } from "./Header.style"; import { Box, Typography, Link } from "@mui/material"; import Table from "@/app/components/Table"; import Dialog from "@/app/components/Dialog"; -import CustomButton from "@/app/components/CustomButton"; +import ButtonGroup from "@/app/components/ButtonGroup"; import { HeaderProps, NameAndDescription, @@ -39,19 +39,21 @@ export default function Header({ bot }: HeaderProps) { const csv = convertToCSV(rows); - const buttons = [ + const dataButtons = [ { onClick: () => setOpenAttribute(true), text: HEADER_BUTTONS_TEXTS.attributes, }, { onClick: () => setOpenData(true), text: HEADER_BUTTONS_TEXTS.data }, - { onClick: () => setOpenHelp(true), text: HEADER_BUTTONS_TEXTS.help }, - { onClick: () => setOpenMail(true), text: HEADER_BUTTONS_TEXTS.mail }, { onClick: () => downloadCSV(csv, "data.csv"), text: HEADER_BUTTONS_TEXTS.download, }, ]; + const helpButtons = [ + { onClick: () => setOpenHelp(true), text: HEADER_BUTTONS_TEXTS.help }, + { onClick: () => setOpenMail(true), text: HEADER_BUTTONS_TEXTS.mail }, + ]; const dialogs = [ { @@ -96,16 +98,17 @@ export default function Header({ bot }: HeaderProps) { return ( - - {buttons.map((button, index) => ( - - ))} - + {bot?._details.name as string} + {dialogs.map((dialog, index) => ( { rows: T[]; headers: string[]; } + +export interface ButtonList extends TextProp { + onClick: () => void; +} + +export interface ButtonGroupProps { + buttonList: ButtonList[]; + buttonStyle?: generalObject; + containerStyle?: generalObject; +} diff --git a/src/app/general/types.ts b/src/app/general/types.ts index 3c8f887..32febf9 100755 --- a/src/app/general/types.ts +++ b/src/app/general/types.ts @@ -22,19 +22,12 @@ export enum TypeOfQuestion { INTRO = "intro", } -export type currentMsgType = { - state: Message[]; - setState: Dispatch>; -}; - -export type currentQIndexType = { - state: number; - setState: Dispatch>; -}; - -export type strParamType = { - state: boolean; - setState: Dispatch>; +type State = { + state: T; + setState: Dispatch>; }; +export type currentMsgType = State; +export type currentQIndexType = State; +export type strParamType = State; export type strOrNum = string | number;