Skip to content

Commit

Permalink
Merge pull request #27 from GoldenLabHuji:ShlomiShitrit-patch-1
Browse files Browse the repository at this point in the history
Create coverage.yml for CI for testing
  • Loading branch information
ShlomiShitrit authored Oct 10, 2024
2 parents 233bbb3 + f11932d commit f14baf7
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 70 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Jest coverage report
on:
pull_request:
branches:
- master
- main
jobs:
coverage:
permissions:
checks: write
pull-requests: write
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ArtiomTr/[email protected]
32 changes: 14 additions & 18 deletions src/app/__tests__/useInput.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ import "@testing-library/jest-dom/jest-globals";
import "@testing-library/jest-dom";
import { renderHook, act } from "@testing-library/react";
import useInput from "@/app/hooks/useInput";
import { Bot, DataType, Message } from "@/app/general/interfaces";
import { sender } from "@/app/general/types";
import {
botMessages,
botRestartMessages,
botAddMessages,
} from "@/app/general/resources";
import { Bot, Message } from "@/app/general/interfaces";
import { Sender, TypeOfQuestion, DataType } from "@/app/general/types";
import { botMessages, botAddMessages } from "@/app/general/resources";

// Mock data for testing
const botMock: Bot = {
Expand All @@ -23,15 +19,15 @@ const botMock: Bot = {
{
_id: "name",
displayName: "Name",
dataType: DataType.String,
dataType: DataType.STRING,
operatorsArray: [
{
id: "equals",
displayName: "equals",
params: [
{
isArray: false,
dataType: DataType.String,
dataType: DataType.STRING,
name: "cell",
},
],
Expand All @@ -42,7 +38,7 @@ const botMock: Bot = {
params: [
{
isArray: false,
dataType: DataType.String,
dataType: DataType.STRING,
name: "cell",
},
],
Expand Down Expand Up @@ -74,7 +70,7 @@ const botMock: Bot = {
params: [
{
isArray: false,
dataType: DataType.String,
dataType: DataType.STRING,
name: "cell",
},
],
Expand All @@ -85,7 +81,7 @@ const botMock: Bot = {
params: [
{
isArray: false,
dataType: DataType.String,
dataType: DataType.STRING,
name: "cell",
},
],
Expand All @@ -106,8 +102,8 @@ const currentMsgMock = {
{
id: 0,
text: "test bot message",
sender: "bot" as sender,
typeOfQuestion: "parameter",
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.PARAMETER,
answerOptions: [1],
} as Message,
],
Expand Down Expand Up @@ -165,8 +161,8 @@ describe("useInput Hook", () => {
{
id: 1,
text: "1",
sender: "user",
typeOfQuestion: "parameter",
sender: Sender.USER,
typeOfQuestion: TypeOfQuestion.PARAMETER,
},
]);

Expand Down Expand Up @@ -196,8 +192,8 @@ describe("useInput Hook", () => {
{
id: 1,
text: "Invalid input",
sender: "bot",
typeOfQuestion: "parameter",
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.PARAMETER,
answerOptions: [1],
},
]);
Expand Down
9 changes: 5 additions & 4 deletions src/app/components/Message/Message.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { render, screen } from "@testing-library/react";
import Message from "@/app/components/Message";
import { Colors, Message as IMessage } from "@/app/general/interfaces";
import { colorCodes } from "@/app/general/resources";
import { TypeOfQuestion, Sender } from "@/app/general/types";

// Mock props
const mockColors: Colors = {
Expand All @@ -14,15 +15,15 @@ const mockColors: Colors = {
const mockMessageBot: IMessage = {
id: 1,
text: "Hello, I am a bot",
sender: "bot",
typeOfQuestion: "intro",
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.INTRO,
};

const mockMessageUser: IMessage = {
id: 2,
text: "Hello, I am a user",
sender: "user",
typeOfQuestion: "result",
sender: Sender.USER,
typeOfQuestion: TypeOfQuestion.RESULT,
};

describe("Message Component", () => {
Expand Down
8 changes: 4 additions & 4 deletions src/app/general/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {
sender,
typeOfQuestion,
Sender,
TypeOfQuestion,
strOrNum,
DataType,
} from "@/app/general/types";

export interface Message {
id: number;
text: string;
sender: sender;
typeOfQuestion: typeOfQuestion;
sender: Sender;
typeOfQuestion: TypeOfQuestion;
answerOptions?: number[];
}

Expand Down
34 changes: 17 additions & 17 deletions src/app/general/resources.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Message, MessageSection, Bot } from "@/app/general/interfaces";
import { sender, typeOfQuestion } from "@/app/general/types";
import { Sender, TypeOfQuestion } from "@/app/general/types";
import { convertTextToMessage } from "@/app/general/utils";
import { NO_RESULTS_FOUND } from "@/app/general/constants";

Expand Down Expand Up @@ -29,8 +29,8 @@ export const botMessages = (bot: Bot): Message[] => {
${headersString}
Which property would you like to start with?`,
sender: "bot",
typeOfQuestion: "parameter",
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.PARAMETER,
answerOptions: Array.from(
{ length: headers.length },
(_, index) => index + 1
Expand Down Expand Up @@ -59,8 +59,8 @@ export const botOperatorMessages = (
text: `${chosenOperator?.message}
${bot?._messages.customMessages.continueMessage}`,
sender: "bot",
typeOfQuestion: "intro",
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.INTRO,
answerOptions: [1],
};

Expand All @@ -81,8 +81,8 @@ ${bot?._messages.customMessages.continueMessage}`,
${optionsString}
`,
sender: "bot",
typeOfQuestion: "operator",
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.OPERATOR,
answerOptions: Array.from(
{ length: operators.length },
(_, index) => index + 1
Expand Down Expand Up @@ -112,8 +112,8 @@ export const botFunctionParamsMessages = (
return {
id: index,
text: prm?.message ?? `Enter value for parameter ${prm?.name}:`,
sender: "bot",
typeOfQuestion: "functionParams",
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.FUNCTION_PARAMS,
};
});
const messageWithoutFirst = messages.slice(1);
Expand Down Expand Up @@ -142,8 +142,8 @@ export const botAddMessages: Message[] = [
1. Yes
2. No`,
sender: "bot",
typeOfQuestion: "add",
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.ADD,
answerOptions: [1, 2],
},
];
Expand All @@ -165,8 +165,8 @@ export const botRestartMessages = (bot: Bot): Message[] => {
text: `To add another parameter, I will go through the same process as before.
${bot?._messages.customMessages.continueMessage}`,
sender: "bot",
typeOfQuestion: "intro",
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.INTRO,
answerOptions: [1],
},
startMsg,
Expand All @@ -189,8 +189,8 @@ export const resultMsg = (bot: Bot, foundResults: boolean): Message[] => {
text: foundResults
? bot?._messages?.customMessages.resultMessage
: NO_RESULTS_FOUND,
sender: "bot" as sender,
typeOfQuestion: "result" as typeOfQuestion,
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.RESULT,
},
];
};
Expand All @@ -205,8 +205,8 @@ export const defaultMsgSection = [
export const emptyMessage: Message = {
id: 0,
text: "empty message",
sender: "bot",
typeOfQuestion: "functionParams",
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.FUNCTION_PARAMS,
};

export const colorCodes = {
Expand Down
30 changes: 20 additions & 10 deletions src/app/general/types.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import { Dispatch, SetStateAction } from "react";
import { Message } from "@/app/general/interfaces";

export type DataType = "string" | "numeric" | "factor";
export type sender = "bot" | "user";
export type typeOfQuestion =
| "parameter"
| "functionParams"
| "value"
| "operator"
| "add"
| "result"
| "intro";
export enum DataType {
STRING = "string",
NUMERIC = "numeric",
FACTOR = "factor",
}

export enum Sender {
BOT = "bot",
USER = "user",
}

export enum TypeOfQuestion {
PARAMETER = "parameter",
FUNCTION_PARAMS = "functionParams",
VALUE = "value",
OPERATOR = "operator",
ADD = "add",
RESULT = "result",
INTRO = "intro",
}

export type currentMsgType = {
state: Message[];
Expand Down
5 changes: 3 additions & 2 deletions src/app/general/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as fs from "fs";
import * as path from "path";
import { OPERATORS } from "@/app/operators/operators";
import { Message, Bot } from "@/app/general/interfaces";
import { Sender, TypeOfQuestion } from "@/app/general/types";

export function isNumberArray(value: any): value is number[] {
const isArray = Array.isArray(value);
Expand All @@ -24,8 +25,8 @@ export function convertTextToMessage(
return {
id: id,
text: text + "\n" + continueMessage,
sender: "bot",
typeOfQuestion: "intro",
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.INTRO,
answerOptions: [1],
};
}
Expand Down
17 changes: 11 additions & 6 deletions src/app/hooks/useEndChat.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { useRecoilState } from "recoil";
import { messagesSectionAtom } from "@/app/store/atoms";
import { Attribute, Bot, BotColumn } from "@/app/general/interfaces";
import { strOrNum } from "@/app/general/types";
import {
strOrNum,
TypeOfQuestion,
Sender,
DataType,
} from "@/app/general/types";

export default function useEndChat(bot: Bot) {
const [messages, _] = useRecoilState(messagesSectionAtom);
Expand All @@ -11,17 +16,17 @@ export default function useEndChat(bot: Bot) {

messages.forEach((msgSec) => {
const userFilteredMessages = msgSec?.messageSection.filter(
(msg) => msg && msg?.sender === "user"
(msg) => msg && msg?.sender === Sender.USER
);

const parametersMessages = userFilteredMessages.filter(
(msg) => msg.typeOfQuestion === "parameter"
(msg) => msg.typeOfQuestion === TypeOfQuestion.PARAMETER
);
const operatorsMessages = userFilteredMessages.filter(
(msg) => msg.typeOfQuestion === "operator"
(msg) => msg.typeOfQuestion === TypeOfQuestion.OPERATOR
);
const functionParamsMessages = userFilteredMessages.filter(
(msg) => msg.typeOfQuestion === "functionParams"
(msg) => msg.typeOfQuestion === TypeOfQuestion.FUNCTION_PARAMS
);

const parameter =
Expand All @@ -45,7 +50,7 @@ export default function useEndChat(bot: Bot) {

const functionParams: strOrNum[] = [];
functionParamsMessages.forEach((msg) => {
if (parameterDataType === "numeric")
if (parameterDataType === DataType.NUMERIC)
functionParams.push(Number(msg.text));
else functionParams.push(msg.text);
});
Expand Down
Loading

0 comments on commit f14baf7

Please sign in to comment.