Skip to content

Commit

Permalink
fix: fix Cypress and Jest tests, add Jest test [PT-188007060]
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanik committed Aug 7, 2024
1 parent 110c94e commit 784c5df
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 14 deletions.
1 change: 1 addition & 0 deletions __mocks__/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'test-file-stub';
3 changes: 2 additions & 1 deletion cypress/e2e/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
});
2 changes: 1 addition & 1 deletion cypress/support/elements/app-elements.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const AppElements = {
getApp() {
return cy.get(".app");
return cy.get(".App");
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|less|sass)$": "identity-obj-proxy"
"\\.(css|less|sass|scss)$": "identity-obj-proxy"
},
"moduleFileExtensions": [
"ts",
Expand Down
11 changes: 0 additions & 11 deletions src/components/App.test.tsx

This file was deleted.

10 changes: 10 additions & 0 deletions src/test/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
import "@testing-library/jest-dom";
import $ from "jquery";

declare global {
interface Window {
$: typeof $;
jQuery: typeof $;
}
}

window.$ = window.jQuery = $;
19 changes: 19 additions & 0 deletions src/utils/daylight-utils.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 784c5df

Please sign in to comment.