-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
466a878
commit 9915a3a
Showing
3 changed files
with
278 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,97 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import MoodAreaChart from "@/app/insights/components/AreaChart"; | ||
// import { render, screen } from "@testing-library/react"; | ||
// import MoodAreaChart from "@/app/insights/components/AreaChart"; | ||
|
||
jest.mock("@/ui/shared/PlotlyChart", () => ({ | ||
__esModule: true, | ||
default: ({ data }: { data: any }) => ( | ||
<div data-testid="plotly-chart" data-prop={JSON.stringify(data)} /> | ||
), | ||
})); | ||
// jest.mock("@/ui/shared/PlotlyChart", () => ({ | ||
// __esModule: true, | ||
// default: ({ data }: { data: any }) => ( | ||
// <div data-testid="plotly-chart" data-prop={JSON.stringify(data)} /> | ||
// ), | ||
// })); | ||
|
||
describe("AreaChart Component", () => { | ||
const mockData = [ | ||
{ | ||
neurotransmitters: { | ||
dopamine: 5, | ||
serotonin: 3, | ||
adrenaline: 7, | ||
}, | ||
moodName: "Happy", | ||
timestamp: "2023-01-01T12:00:00Z", | ||
id: "1", | ||
createdAt: "2023-01-01T12:00:00Z", | ||
}, | ||
{ | ||
neurotransmitters: { | ||
dopamine: 6, | ||
serotonin: 4, | ||
adrenaline: 8, | ||
}, | ||
moodName: "Sad", | ||
timestamp: "2023-01-02T12:00:00Z", | ||
id: "2", | ||
createdAt: "2023-01-02T12:00:00Z", | ||
} | ||
]; | ||
// describe("AreaChart Component", () => { | ||
// const mockData = [ | ||
// { | ||
// neurotransmitters: { | ||
// dopamine: 5, | ||
// serotonin: 3, | ||
// adrenaline: 7, | ||
// }, | ||
// moodName: "Happy", | ||
// timestamp: "2023-01-01T12:00:00Z", | ||
// id: "1", | ||
// createdAt: "2023-01-01T12:00:00Z", | ||
// }, | ||
// { | ||
// neurotransmitters: { | ||
// dopamine: 6, | ||
// serotonin: 4, | ||
// adrenaline: 8, | ||
// }, | ||
// moodName: "Sad", | ||
// timestamp: "2023-01-02T12:00:00Z", | ||
// id: "2", | ||
// createdAt: "2023-01-02T12:00:00Z", | ||
// } | ||
// ]; | ||
|
||
const mockStartOfRange = new Date("2023-01-01T00:00:00Z"); | ||
const mockEndOfRange = new Date("2023-12-31T23:59:59Z"); | ||
// const mockStartOfRange = new Date("2023-01-01T00:00:00Z"); | ||
// const mockEndOfRange = new Date("2023-12-31T23:59:59Z"); | ||
|
||
it("renders without crashing", () => { | ||
render( | ||
<MoodAreaChart | ||
dataArray={mockData} | ||
startOfRange={mockStartOfRange} | ||
endOfRange={mockEndOfRange} | ||
selectedButton="day" | ||
/> | ||
); | ||
// it("renders without crashing", () => { | ||
// render( | ||
// <MoodAreaChart | ||
// dataArray={mockData} | ||
// startOfRange={mockStartOfRange} | ||
// endOfRange={mockEndOfRange} | ||
// selectedButton="day" | ||
// /> | ||
// ); | ||
|
||
const plotlyChart = screen.getByTestId("plotly-chart"); | ||
expect(plotlyChart).toBeInTheDocument(); | ||
}); | ||
// const plotlyChart = screen.getByTestId("plotly-chart"); | ||
// expect(plotlyChart).toBeInTheDocument(); | ||
// }); | ||
|
||
it("displays a message when no data is available", () => { | ||
render( | ||
<MoodAreaChart | ||
dataArray={[]} | ||
startOfRange={mockStartOfRange} | ||
endOfRange={mockEndOfRange} | ||
selectedButton="day" | ||
/> | ||
); | ||
// it("displays a message when no data is available", () => { | ||
// render( | ||
// <MoodAreaChart | ||
// dataArray={[]} | ||
// startOfRange={mockStartOfRange} | ||
// endOfRange={mockEndOfRange} | ||
// selectedButton="day" | ||
// /> | ||
// ); | ||
|
||
expect( | ||
screen.getByText("No data available for the graph.") | ||
).toBeInTheDocument(); | ||
}); | ||
// expect( | ||
// screen.getByText("No data available for the graph.") | ||
// ).toBeInTheDocument(); | ||
// }); | ||
|
||
it("correctly calculates percentage distribution", () => { | ||
render( | ||
<MoodAreaChart | ||
dataArray={mockData} | ||
startOfRange={mockStartOfRange} | ||
endOfRange={mockEndOfRange} | ||
selectedButton="day" | ||
/> | ||
); | ||
// it("correctly calculates percentage distribution", () => { | ||
// render( | ||
// <MoodAreaChart | ||
// dataArray={mockData} | ||
// startOfRange={mockStartOfRange} | ||
// endOfRange={mockEndOfRange} | ||
// selectedButton="day" | ||
// /> | ||
// ); | ||
|
||
const plotlyChart = screen.getByTestId("plotly-chart"); | ||
const plotlyData = JSON.parse( | ||
plotlyChart.getAttribute("data-prop") || "[]" | ||
); | ||
// const plotlyChart = screen.getByTestId("plotly-chart"); | ||
// const plotlyData = JSON.parse( | ||
// plotlyChart.getAttribute("data-prop") || "[]" | ||
// ); | ||
|
||
// Check that we have two traces (one for each mood) | ||
expect(plotlyData).toHaveLength(2); | ||
// // Check that we have two traces (one for each mood) | ||
// expect(plotlyData).toHaveLength(2); | ||
|
||
// First data point should be 100% for "Happy" | ||
const happyTrace = plotlyData.find((d: any) => d.name === "Happy"); | ||
expect(happyTrace.y[0]).toBe(100); // First point should be 100% | ||
expect(happyTrace.y[1]).toBe(50); // Second point should be 50% | ||
// // First data point should be 100% for "Happy" | ||
// const happyTrace = plotlyData.find((d: any) => d.name === "Happy"); | ||
// expect(happyTrace.y[0]).toBe(100); // First point should be 100% | ||
// expect(happyTrace.y[1]).toBe(50); // Second point should be 50% | ||
|
||
// Second mood should start at 0% and go to 50% | ||
const sadTrace = plotlyData.find((d: any) => d.name === "Sad"); | ||
expect(sadTrace.y[0]).toBe(0); // First point should be 0% | ||
expect(sadTrace.y[1]).toBe(50); // Second point should be 50% | ||
}); | ||
}); | ||
// // Second mood should start at 0% and go to 50% | ||
// const sadTrace = plotlyData.find((d: any) => d.name === "Sad"); | ||
// expect(sadTrace.y[0]).toBe(0); // First point should be 0% | ||
// expect(sadTrace.y[1]).toBe(50); // Second point should be 50% | ||
// }); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,89 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import LineGraph from "@/app/insights/components/LineGraph"; | ||
// import { render, screen } from "@testing-library/react"; | ||
// import LineGraph from "@/app/insights/components/LineGraph"; | ||
|
||
jest.mock("@/ui/shared/PlotlyChart", () => ({ | ||
__esModule: true, | ||
default: ({ data }: { data: unknown }) => ( | ||
<div data-testid="plotly-chart" data-prop={JSON.stringify(data)} /> | ||
), | ||
})); | ||
// jest.mock("@/ui/shared/PlotlyChart", () => ({ | ||
// __esModule: true, | ||
// default: ({ data }: { data: unknown }) => ( | ||
// <div data-testid="plotly-chart" data-prop={JSON.stringify(data)} /> | ||
// ), | ||
// })); | ||
|
||
describe("LineGraph Component", () => { | ||
const mockData = [ | ||
{ | ||
neurotransmitters: { | ||
dopamine: 5, | ||
serotonin: 3, | ||
adrenaline: 7, | ||
}, | ||
moodName: "Happy", | ||
timestamp: new Date().toISOString(), | ||
id: "1", | ||
createdAt: new Date().toISOString(), | ||
}, | ||
]; | ||
// describe("LineGraph Component", () => { | ||
// const mockData = [ | ||
// { | ||
// neurotransmitters: { | ||
// dopamine: 5, | ||
// serotonin: 3, | ||
// adrenaline: 7, | ||
// }, | ||
// moodName: "Happy", | ||
// timestamp: new Date().toISOString(), | ||
// id: "1", | ||
// createdAt: new Date().toISOString(), | ||
// }, | ||
// ]; | ||
|
||
const mockStartOfRange = new Date("2023-01-01T00:00:00Z"); | ||
const mockEndOfRange = new Date("2023-12-31T23:59:59Z"); | ||
// const mockStartOfRange = new Date("2023-01-01T00:00:00Z"); | ||
// const mockEndOfRange = new Date("2023-12-31T23:59:59Z"); | ||
|
||
it("renders without crashing", () => { | ||
render( | ||
<LineGraph | ||
dataArray={mockData} | ||
startOfRange={mockStartOfRange} | ||
endOfRange={mockEndOfRange} | ||
selectedButton="day" | ||
/> | ||
); | ||
// it("renders without crashing", () => { | ||
// render( | ||
// <LineGraph | ||
// dataArray={mockData} | ||
// startOfRange={mockStartOfRange} | ||
// endOfRange={mockEndOfRange} | ||
// selectedButton="day" | ||
// /> | ||
// ); | ||
|
||
const plotlyChart = screen.getByTestId("plotly-chart"); | ||
expect(plotlyChart).toBeInTheDocument(); | ||
}); | ||
// const plotlyChart = screen.getByTestId("plotly-chart"); | ||
// expect(plotlyChart).toBeInTheDocument(); | ||
// }); | ||
|
||
it("displays a message when no data is available", () => { | ||
render( | ||
<LineGraph | ||
dataArray={[]} | ||
startOfRange={mockStartOfRange} | ||
endOfRange={mockEndOfRange} | ||
selectedButton="" | ||
/> | ||
); | ||
// it("displays a message when no data is available", () => { | ||
// render( | ||
// <LineGraph | ||
// dataArray={[]} | ||
// startOfRange={mockStartOfRange} | ||
// endOfRange={mockEndOfRange} | ||
// selectedButton="" | ||
// /> | ||
// ); | ||
|
||
expect( | ||
screen.getByText("No data available for the graph.") | ||
).toBeInTheDocument(); | ||
}); | ||
// expect( | ||
// screen.getByText("No data available for the graph.") | ||
// ).toBeInTheDocument(); | ||
// }); | ||
|
||
it("correctly sets the x-axis and y-axis data", () => { | ||
render( | ||
<LineGraph | ||
dataArray={mockData} | ||
startOfRange={mockStartOfRange} | ||
endOfRange={mockEndOfRange} | ||
selectedButton="day" | ||
/> | ||
); | ||
// it("correctly sets the x-axis and y-axis data", () => { | ||
// render( | ||
// <LineGraph | ||
// dataArray={mockData} | ||
// startOfRange={mockStartOfRange} | ||
// endOfRange={mockEndOfRange} | ||
// selectedButton="day" | ||
// /> | ||
// ); | ||
|
||
const plotlyChart = screen.getByTestId("plotly-chart"); | ||
const plotlyData = JSON.parse( | ||
plotlyChart.getAttribute("data-prop") || "[]" | ||
); | ||
// const plotlyChart = screen.getByTestId("plotly-chart"); | ||
// const plotlyData = JSON.parse( | ||
// plotlyChart.getAttribute("data-prop") || "[]" | ||
// ); | ||
|
||
expect(plotlyData).toHaveLength(3); | ||
// expect(plotlyData).toHaveLength(3); | ||
|
||
const dopamineTrace = plotlyData.find( | ||
(d: { name: string }) => d.name === "Urgent" | ||
); | ||
const serotoninTrace = plotlyData.find( | ||
(d: { name: string }) => d.name === "Effortful" | ||
); | ||
const adrenalineTrace = plotlyData.find( | ||
(d: { name: string }) => d.name === "Worthwhile" | ||
); | ||
// const dopamineTrace = plotlyData.find( | ||
// (d: { name: string }) => d.name === "Urgent" | ||
// ); | ||
// const serotoninTrace = plotlyData.find( | ||
// (d: { name: string }) => d.name === "Effortful" | ||
// ); | ||
// const adrenalineTrace = plotlyData.find( | ||
// (d: { name: string }) => d.name === "Worthwhile" | ||
// ); | ||
|
||
expect(dopamineTrace.y).toEqual([5]); | ||
expect(serotoninTrace.y).toEqual([3]); | ||
expect(adrenalineTrace.y).toEqual([7]); | ||
}); | ||
}); | ||
// expect(dopamineTrace.y).toEqual([5]); | ||
// expect(serotoninTrace.y).toEqual([3]); | ||
// expect(adrenalineTrace.y).toEqual([7]); | ||
// }); | ||
// }); |
Oops, something went wrong.