Unit Testing: Automatic Thoughts Response V2 - 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;
}
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));
});
});