From 784c5dfc7d1394d04bee1ba95929d56244ac1072 Mon Sep 17 00:00:00 2001 From: pjanik Date: Wed, 7 Aug 2024 19:22:31 +0200 Subject: [PATCH] fix: fix Cypress and Jest tests, add Jest test [PT-188007060] --- __mocks__/fileMock.js | 1 + cypress/e2e/workspace.test.ts | 3 ++- cypress/support/elements/app-elements.ts | 2 +- package.json | 2 +- src/components/App.test.tsx | 11 ----------- src/test/setupTests.ts | 10 ++++++++++ src/utils/daylight-utils.test.ts | 19 +++++++++++++++++++ 7 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 __mocks__/fileMock.js delete mode 100755 src/components/App.test.tsx create mode 100644 src/utils/daylight-utils.test.ts diff --git a/__mocks__/fileMock.js b/__mocks__/fileMock.js new file mode 100644 index 0000000..86059f3 --- /dev/null +++ b/__mocks__/fileMock.js @@ -0,0 +1 @@ +module.exports = 'test-file-stub'; diff --git a/cypress/e2e/workspace.test.ts b/cypress/e2e/workspace.test.ts index 6cf6bed..dd6b84c 100644 --- a/cypress/e2e/workspace.test.ts +++ b/cypress/e2e/workspace.test.ts @@ -7,7 +7,8 @@ context("Test the overall app", () => { describe("Desktop functionalities", () => { it("renders with text", () => { - ae.getApp().should("have.text", "Hello World"); + // Check if the text includes "Location" + ae.getApp().should("contain.text", "Location"); }); }); }); diff --git a/cypress/support/elements/app-elements.ts b/cypress/support/elements/app-elements.ts index d620d7c..8d58211 100644 --- a/cypress/support/elements/app-elements.ts +++ b/cypress/support/elements/app-elements.ts @@ -1,5 +1,5 @@ export const AppElements = { getApp() { - return cy.get(".app"); + return cy.get(".App"); } }; diff --git a/package.json b/package.json index 0029b71..28c3528 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ ], "moduleNameMapper": { "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/__mocks__/fileMock.js", - "\\.(css|less|sass)$": "identity-obj-proxy" + "\\.(css|less|sass|scss)$": "identity-obj-proxy" }, "moduleFileExtensions": [ "ts", diff --git a/src/components/App.test.tsx b/src/components/App.test.tsx deleted file mode 100755 index 051b351..0000000 --- a/src/components/App.test.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import React from "react"; -import { App } from "./App"; -import { render, screen } from "@testing-library/react"; - -describe("test load app", () => { - it("renders without crashing", () => { - render(); - expect(screen.getByText("CODAP Day Length Plugin 3")).toBeDefined(); - }); -}); - diff --git a/src/test/setupTests.ts b/src/test/setupTests.ts index d0de870..f190b0f 100644 --- a/src/test/setupTests.ts +++ b/src/test/setupTests.ts @@ -1 +1,11 @@ import "@testing-library/jest-dom"; +import $ from "jquery"; + +declare global { + interface Window { + $: typeof $; + jQuery: typeof $; + } +} + +window.$ = window.jQuery = $; diff --git a/src/utils/daylight-utils.test.ts b/src/utils/daylight-utils.test.ts new file mode 100644 index 0000000..09c1767 --- /dev/null +++ b/src/utils/daylight-utils.test.ts @@ -0,0 +1,19 @@ +import { getSunrayAngleInDegrees } from "./daylight-utils" + +describe("getSunrayAngleInDegrees", () => { + it("should return the correct sunray angle in degrees", () => { + const dayNum = 172; + const earthTilt = 23.5; + const lat = 37.7749; + const result = getSunrayAngleInDegrees(dayNum, earthTilt, lat); + expect(result).toBeCloseTo(75.7251); + }); + + it("should return the correct sunray angle in degrees (90deg case)", () => { + const dayNum = 171; + const earthTilt = 23.5; + const lat = 23.5; + const result = getSunrayAngleInDegrees(dayNum, earthTilt, lat); + expect(result).toBeCloseTo(90); + }); +});