Unit Testing: Automatic Thoughts Response V3 - CBTYoung/Documentation GitHub Wiki

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 Response 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 Response

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 Response

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.