Skip to content

Unit Testing: Automatic Thoughts V3

goldyuva edited this page Jun 9, 2023 · 2 revisions
import { AutomaticThoughts } from "../../../src/architecture/business_layer/modules/AutomaticThoughts";
const thought ="I'm pretty";
const setTh ="I'm pretty sad";
const date = new Date(Date.now());
let auto = new AutomaticThoughts(thought);
const response = "rsponse with important data";
const responseDate = new Date(Date.now()+1000);

function formatSummaryOneThought(date:Date,thought:string)
{
    return "Thought from "+date.toString()+":\n"+thought;
}

function formatSummaryOneThoughtWithResponse(date:Date,thought:string,resDate:Date,response:string)
{
    return "Thought from "+date.toString()+":\n"+thought+ "\nResponse from "+new Date(resDate).getDay()+"/"+new Date(resDate).getMonth()+ "/"+new Date(resDate).getFullYear()+": "+response;
}

1. Automatic Thoughts Summary Tests:

describe("AutomaticThoughts Summary tests", () => {
    beforeEach(()=>{      
        auto = new AutomaticThoughts(thought);
    })
    test('checking getsummary with thought', () =>{
        expect(auto.getSummary())
        .toBe(formatSummaryOneThought(date,thought));
    });

    test('checking getsummary with set thought', () =>{
        auto.setThought(setTh);
        expect(auto.getSummary())
        .toBe(formatSummaryOneThought(date,setTh));
    });

    test('checking getsummary with response', () =>{
        expect(auto.getSummary())
        .toBe(formatSummaryOneThought(date,thought));
        auto.addRepsonse(responseDate,response);

        expect(auto.getSummary())
        .toBe(formatSummaryOneThoughtWithResponse(date,thought,responseDate,response));
    });
});

Test 1.1: Checking getsummary With Thought

We want to check if we get the same thought formatted as we put in the report.

We expect their results to be identical.

Test 1.2: Checking getsummary With Set Thought

After we set a new thought, We want to check if we get the same thought formatted in the updated report.

We expect their results to be identical.

Test 1.3: Checking getsummary With Response

We want to check if we get the same response formatted as we put in the report.

We expect their results to be identical.

Clone this wiki locally