Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create coverage.yml for CI for testing #27

Merged
merged 5 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
${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 @@
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 @@

${optionsString}
`,
sender: "bot",
typeOfQuestion: "operator",
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.OPERATOR,
answerOptions: Array.from(
{ length: operators.length },
(_, index) => index + 1
Expand All @@ -97,23 +97,23 @@
return displayMessage;
};

export const botFunctionParamsMessages = (
bot: Bot,
currentParam: string
): Message[] => {
const operators = bot?._data.columns.filter(
(col) => col._id === currentParam
)[0]?.operatorsArray;

const chosenOperator = operators[bot.currentOperatorIndex];
const params = chosenOperator.params;

const messages: Message[] = params.map((prm, index) => {
return {
id: index,
text: prm?.message ?? `Enter value for parameter ${prm?.name}:`,

Check warning on line 114 in src/app/general/resources.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
sender: "bot",
typeOfQuestion: "functionParams",
sender: Sender.BOT,

Check warning on line 115 in src/app/general/resources.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
typeOfQuestion: TypeOfQuestion.FUNCTION_PARAMS,
};
});
const messageWithoutFirst = messages.slice(1);
Expand Down Expand Up @@ -142,55 +142,55 @@

1. Yes
2. No`,
sender: "bot",
typeOfQuestion: "add",
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.ADD,
answerOptions: [1, 2],
},
];

export const botRestartMessages = (bot: Bot): Message[] => {
const startMsg = botMessages(bot).slice(-1)[0];
const restartSlot = bot?._messages?.slots.restartSlot ?? [];
const restartSlotArray = restartSlot.map((msg, index) =>
convertTextToMessage(
msg,
index,
bot?._messages.customMessages.continueMessage
)
);
return [
...restartSlotArray,
{
id: 0,
text: `To add another parameter, I will go through the same process as before.

${bot?._messages.customMessages.continueMessage}`,

Check warning on line 167 in src/app/general/resources.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
sender: "bot",
typeOfQuestion: "intro",
sender: Sender.BOT,

Check warning on line 168 in src/app/general/resources.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
typeOfQuestion: TypeOfQuestion.INTRO,
answerOptions: [1],
},
startMsg,
];
};

Check warning on line 174 in src/app/general/resources.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function

export const resultMsg = (bot: Bot, foundResults: boolean): Message[] => {
const resultSlot = bot?._messages?.slots.resultSlot ?? [];
const resultSlotArray = resultSlot.map((msg, index) =>
convertTextToMessage(
msg,
index,
bot?._messages.customMessages.continueMessage
)
);
return [
...resultSlotArray,
{
id: 0,
text: foundResults

Check warning on line 189 in src/app/general/resources.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
? bot?._messages?.customMessages.resultMessage

Check warning on line 190 in src/app/general/resources.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
: NO_RESULTS_FOUND,
sender: "bot" as sender,
typeOfQuestion: "result" as typeOfQuestion,
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.RESULT,
},
];
};

Check warning on line 196 in src/app/general/resources.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
Expand All @@ -205,8 +205,8 @@
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
Loading