PromucFlow_constructor/app/client/test/setup.ts

114 lines
2.7 KiB
TypeScript
Raw Normal View History

import { setupServer } from "msw/node";
import { handlers } from "./__mocks__/apiHandlers";
import "../src/polyfills/requestIdleCallback";
import { Crypto } from "@peculiar/webcrypto";
// since global crypto is immutable, we need to first delete it and then use the
// peculiar crypto lisrc/sagas/helper.test.tsb
delete global['crypto'];
global.crypto = new Crypto();
export const server = setupServer(...handlers);
jest.mock("api/Api", () => ({
__esModule: true,
default: class Api { },
}));
window.scrollTo = jest.fn();
Element.prototype.scrollIntoView = jest.fn();
Element.prototype.scrollBy = jest.fn();
feat: Improved App Navigation (#19312) ## TL;DR A new revamped experience for navigation for Appsmith users. ## Description Introduces new navigation styles with better default navigation - Top (Stacked), a variant for Top (Inline), and a collapsible Sidebar. Configure your app's navigation by navigating to the navigation settings tab inside the app settings pane and observe how your app with the selected navigation settings will look side by side as you change them. This PR pushes the v1 for EPIC #17766. Fixes #19157 Fixes #19158 Fixes #19174 Fixes #19173 Fixes #19160 Fixes #20712 Fixes #19161 Fixes #20554 Fixes #20938 Fixes #21129 ## Media <video src="https://user-images.githubusercontent.com/22471214/227187245-84e4e3fa-18e4-4690-8237-cfce29f432e5.mp4"></video> ## Type of change - New feature (non-breaking change which adds functionality) - This change requires a documentation update ## How Has This Been Tested? - Manual - Cypress ### Test Plan https://www.notion.so/appsmith/Test-Plan-a7883ae4980d470690de5c62a41dd168 ### Issues raised during DP testing https://docs.google.com/spreadsheets/d/1Kocq8h1H3EXlbqDgiNruzBr9MeNPyY26zct8IWYEY40/edit#gid=0 ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test --------- Co-authored-by: Pawan Kumar <pawan@appsmith.com>
2023-03-23 11:41:58 +00:00
jest.mock("../src/api/Api.ts", () => ({
__esModule: true,
default: class Api { },
feat: Improved App Navigation (#19312) ## TL;DR A new revamped experience for navigation for Appsmith users. ## Description Introduces new navigation styles with better default navigation - Top (Stacked), a variant for Top (Inline), and a collapsible Sidebar. Configure your app's navigation by navigating to the navigation settings tab inside the app settings pane and observe how your app with the selected navigation settings will look side by side as you change them. This PR pushes the v1 for EPIC #17766. Fixes #19157 Fixes #19158 Fixes #19174 Fixes #19173 Fixes #19160 Fixes #20712 Fixes #19161 Fixes #20554 Fixes #20938 Fixes #21129 ## Media <video src="https://user-images.githubusercontent.com/22471214/227187245-84e4e3fa-18e4-4690-8237-cfce29f432e5.mp4"></video> ## Type of change - New feature (non-breaking change which adds functionality) - This change requires a documentation update ## How Has This Been Tested? - Manual - Cypress ### Test Plan https://www.notion.so/appsmith/Test-Plan-a7883ae4980d470690de5c62a41dd168 ### Issues raised during DP testing https://docs.google.com/spreadsheets/d/1Kocq8h1H3EXlbqDgiNruzBr9MeNPyY26zct8IWYEY40/edit#gid=0 ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test --------- Co-authored-by: Pawan Kumar <pawan@appsmith.com>
2023-03-23 11:41:58 +00:00
}));
chore: add eslint package to handle linting (#37417) ## Description We are shifting the linter engine for jshint to eslint. This PR adds the package needed for the same and also adds the required configs. The eslint feature is behing a rollout feature flag, it's currently at 0% right now. > [!NOTE] > This PR is part of a series of [stacked diffs](https://newsletter.pragmaticengineer.com/p/stacked-diffs) and might have changes from it's parent PRs. Untill the blocking parent PRs are merged, this diff would show more changes than are relevant for this PR. Blocking PRs: - #36548 Fixes #37254 ## Automation /test js sanity ### :mag: Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/11965021215> > Commit: 579e4772f918936da292ba2815621ca80499c212 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11965021215&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.JS, @tag.Sanity` > Spec: > <hr>Fri, 22 Nov 2024 02:49:47 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Integrated ESLint support alongside existing JSHint functionality for enhanced linting capabilities. - Added a new dependency for ESLint linting. - **Improvements** - Enhanced error handling and reporting for linting errors, ensuring consistency across different linting tools. - Updated testing framework to accommodate multiple linter types without duplicating logic. - Introduced new functions for sanitizing and converting ESLint errors to the application's format. - Added support for structured cloning in the testing setup. - Improved logic for determining main actions and error handling in conditional expressions. - **Bug Fixes** - Improved logic for handling lint errors, particularly in differentiating between ESLint and JSHint errors. - **Documentation** - Updated comments for clarity on linting processes and configurations. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-22 08:56:05 +00:00
// Polyfill for `structuredClone` if not available
// This is needed for eslint jest tests
if (typeof global.structuredClone === "undefined") {
global.structuredClone = (obj) => {
return JSON.parse(JSON.stringify(obj));
};
}
beforeAll(() => {
window.IntersectionObserver = jest
.fn()
.mockImplementation((fn: (entry: any) => any) => {
return {
observe: () => {
fn([
{
isIntersecting: true,
boundingClientRect: {
top: 64,
left: 293,
},
intersectionRect: {
width: 1296,
height: 424,
top: 64,
left: 293,
},
},
]);
},
unobserve: jest.fn(),
disconnect: jest.fn(),
};
});
window.ResizeObserver = jest.fn().mockImplementation(() => {
return {
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
};
});
});
// establish API mocking before all tests
beforeAll(() => server.listen());
// reset any request handlers that are declared as a part of our tests
// (i.e. for testing one-time error scenarios)
afterEach(() => server.resetHandlers());
// clean up once the tests are done
afterAll(() => server.close());
// popper.js fix for jest tests
document.createRange = () => {
const range = new Range();
range.getBoundingClientRect = jest.fn();
range.getClientRects = () => {
return {
item: () => null,
length: 0,
[Symbol.iterator]: jest.fn(),
};
};
return range;
};
// jest events doesnt seem to be handling scrollTo
Element.prototype.scrollTo = () => { };
class WorkerStub {
url: string;
onmessage: CallableFunction;
constructor(stringUrl: string) {
this.url = stringUrl;
// eslint-disable-next-line @typescript-eslint/no-empty-function
this.onmessage = () => { };
}
postMessage(msg) {
this.onmessage(msg);
}
}
window.Worker = WorkerStub as any;