chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] 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
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] 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: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
import type { AppState } from "@appsmith/reducers" ;
2023-03-04 07:25:54 +00:00
import { all } from "@redux-saga/core/effects" ;
2022-08-26 13:13:48 +00:00
import lodash from "lodash" ;
2021-08-12 05:45:38 +00:00
import React from "react" ;
2022-08-26 13:13:48 +00:00
import { MemoryRouter } from "react-router-dom" ;
import * as dataTreeSelectors from "selectors/dataTreeSelectors" ;
import * as utilities from "selectors/editorSelectors" ;
import store from "store" ;
2021-08-12 05:45:38 +00:00
import {
buildChildren ,
widgetCanvasFactory ,
} from "test/factories/WidgetFactoryUtils" ;
import { sagasToRunForTests } from "test/sagas" ;
import {
MockApplication ,
2022-08-19 10:10:36 +00:00
mockCreateCanvasWidget ,
2021-08-12 05:45:38 +00:00
mockGetCanvasWidgetDsl ,
2022-12-01 06:30:50 +00:00
mockGetPagePermissions ,
2022-08-19 10:10:36 +00:00
mockGetWidgetEvalValues ,
2021-08-12 05:45:38 +00:00
syntheticTestMouseEvent ,
} from "test/testCommon" ;
2022-08-26 13:13:48 +00:00
import { UpdatedEditor } from "test/testMockedWidgets" ;
import { act , fireEvent , render } from "test/testUtils" ;
2022-01-13 13:21:57 +00:00
import { generateReactKey } from "utils/generators" ;
2022-08-26 13:13:48 +00:00
import { getAbsolutePixels } from "utils/helpers" ;
2022-05-26 04:52:55 +00:00
import * as useDynamicAppLayoutHook from "utils/hooks/useDynamicAppLayout" ;
2022-08-26 13:13:48 +00:00
import * as widgetRenderUtils from "utils/widgetRenderUtils" ;
import GlobalHotKeys from "./GlobalHotKeys" ;
2023-02-21 13:38:16 +00:00
import * as uiSelectors from "selectors/ui" ;
2021-09-22 07:18:46 +00:00
const renderNestedComponent = ( ) = > {
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] 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
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] 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: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
const initialState = store . getState ( ) as unknown as Partial < AppState > ;
2021-09-22 07:18:46 +00:00
const canvasId = "canvas-id" ;
const containerId = "container-id" ;
const children : any = buildChildren ( [
{
2022-01-18 07:52:24 +00:00
type : "INPUT_WIDGET_V2" ,
2021-09-22 07:18:46 +00:00
dragDisabled : true ,
leftColumn : 0 ,
topRow : 1 ,
parentId : canvasId ,
rightColumn : 5 ,
bottomRow : 2 ,
text : "DRAG DISABLED INPUT" ,
} ,
{
type : "TEXT_WIDGET" ,
leftColumn : 0 ,
parentId : canvasId ,
rightColumn : 5 ,
bottomRow : 3 ,
topRow : 2 ,
text : "LABEL" ,
widgetId : "text-widget" ,
} ,
] ) ;
const canvasWidgetChildren : any = buildChildren ( [
{
type : "CANVAS_WIDGET" ,
parentId : containerId ,
widgetId : canvasId ,
children ,
} ,
] ) ;
const containerWidgetChildren : any = buildChildren ( [
{
type : "CONTAINER_WIDGET" ,
children : canvasWidgetChildren ,
parentId : "0" ,
widgetId : containerId ,
} ,
] ) ;
const dsl : any = widgetCanvasFactory . build ( {
children : containerWidgetChildren ,
} ) ;
return render (
2022-04-07 05:39:15 +00:00
< MemoryRouter
initialEntries = { [ "/app/applicationSlug/pageSlug-page_id/edit" ] }
>
2021-09-22 07:18:46 +00:00
< MockApplication >
< GlobalHotKeys >
2022-08-26 13:13:48 +00:00
< UpdatedEditor dsl = { dsl } / >
2021-09-22 07:18:46 +00:00
< / GlobalHotKeys >
< / MockApplication >
< / MemoryRouter > ,
{ initialState , sagasToRun : sagasToRunForTests } ,
) ;
} ;
2021-08-12 05:45:38 +00:00
describe ( "Drag and Drop widgets into Main container" , ( ) = > {
const mockGetIsFetchingPage = jest . spyOn ( utilities , "getIsFetchingPage" ) ;
const spyGetCanvasWidgetDsl = jest . spyOn ( utilities , "getCanvasWidgetDsl" ) ;
2022-08-19 10:10:36 +00:00
jest
. spyOn ( widgetRenderUtils , "createCanvasWidget" )
. mockImplementation ( mockCreateCanvasWidget ) ;
jest
. spyOn ( dataTreeSelectors , "getWidgetEvalValues" )
. mockImplementation ( mockGetWidgetEvalValues ) ;
jest
. spyOn ( utilities , "computeMainContainerWidget" )
. mockImplementation ( ( widget ) = > widget as any ) ;
2022-05-26 04:52:55 +00:00
jest
. spyOn ( useDynamicAppLayoutHook , "useDynamicAppLayout" )
2022-06-21 13:57:34 +00:00
. mockImplementation ( ( ) = > true ) ;
2021-08-12 05:45:38 +00:00
2022-03-25 10:43:26 +00:00
const pushState = jest . spyOn ( window . history , "pushState" ) ;
pushState . mockImplementation ( ( state : any , title : any , url : any ) = > {
window . document . title = title ;
window . location . pathname = url ;
} ) ;
2021-08-12 05:45:38 +00:00
// These need to be at the top to avoid imports not being mocked. ideally should be in setup.ts but will override for all other tests
beforeAll ( ( ) = > {
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] 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
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] 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: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
const mockGenerator = function * ( ) {
2021-08-12 05:45:38 +00:00
yield all ( [ ] ) ;
} ;
const debounceMocked = jest . spyOn ( lodash , "debounce" ) ;
debounceMocked . mockImplementation ( ( fn : any ) = > fn ) ;
// top avoid the first middleware run which wud initiate all sagas.
jest . mock ( "sagas" , ( ) = > ( {
rootSaga : mockGenerator ,
} ) ) ;
// only the deafault exports are mocked to avoid overriding utilities exported out of them. defaults are marked to avoid worker initiation and page api calls in tests.
jest . mock ( "sagas/EvaluationsSaga" , ( ) = > ( {
. . . jest . requireActual ( "sagas/EvaluationsSaga" ) ,
default : mockGenerator ,
} ) ) ;
jest . mock ( "sagas/PageSagas" , ( ) = > ( {
. . . jest . requireActual ( "sagas/PageSagas" ) ,
default : mockGenerator ,
} ) ) ;
} ) ;
it ( "Drag to move widgets" , ( ) = > {
const children : any = buildChildren ( [
{
type : "TABS_WIDGET" ,
topRow : 5 ,
bottomRow : 5 ,
leftColumn : 5 ,
rightColumn : 5 ,
2023-02-21 13:38:16 +00:00
widgetId : "tabsWidgetId" ,
2021-08-12 05:45:38 +00:00
} ,
] ) ;
const dsl : any = widgetCanvasFactory . build ( {
children ,
} ) ;
spyGetCanvasWidgetDsl . mockImplementation ( mockGetCanvasWidgetDsl ) ;
mockGetIsFetchingPage . mockImplementation ( ( ) = > false ) ;
const component = render (
2022-04-07 05:39:15 +00:00
< MemoryRouter
initialEntries = { [ "/app/applicationSlug/pageSlug-page_id/edit" ] }
>
2021-08-12 05:45:38 +00:00
< MockApplication >
< GlobalHotKeys >
2022-08-26 13:13:48 +00:00
< UpdatedEditor dsl = { dsl } / >
2021-08-12 05:45:38 +00:00
< / GlobalHotKeys >
< / MockApplication >
< / MemoryRouter > ,
{ initialState : store.getState ( ) , sagasToRun : sagasToRunForTests } ,
) ;
const propPane = component . queryByTestId ( "t--propertypane" ) ;
expect ( propPane ) . toBeNull ( ) ;
const canvasWidgets = component . queryAllByTestId ( "test-widget" ) ;
expect ( canvasWidgets . length ) . toBe ( 1 ) ;
const tabsWidget : any = component . container . querySelector (
".t--draggable-tabswidget" ,
) ;
const tab : any = component . container . querySelector ( ".t--widget-tabswidget" ) ;
const initPositions = {
left : tab.style.left ,
top : tab.style.top ,
} ;
2021-09-22 07:18:46 +00:00
act ( ( ) = > {
fireEvent . mouseOver ( tabsWidget ) ;
} ) ;
2023-02-21 13:38:16 +00:00
jest
. spyOn ( uiSelectors , "getSelectedWidgets" )
. mockReturnValue ( [ "tabsWidgetId" ] ) ;
2021-08-12 05:45:38 +00:00
act ( ( ) = > {
fireEvent . dragStart ( tabsWidget ) ;
} ) ;
2022-01-25 15:28:31 +00:00
const mainCanvas : any = component . queryByTestId ( "div-dragarena-0" ) ;
2021-08-12 05:45:38 +00:00
act ( ( ) = > {
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mousemove" , {
bubbles : true ,
cancelable : true ,
} ) ,
{
offsetX : 0 ,
offsetY : 0 ,
} ,
) ,
) ;
} ) ;
act ( ( ) = > {
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mousemove" , {
bubbles : true ,
cancelable : true ,
} ) ,
{
offsetX : - 50 ,
offsetY : - 50 ,
} ,
) ,
) ;
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mouseup" , {
bubbles : true ,
cancelable : true ,
} ) ,
) ,
) ;
} ) ;
const movedTab : any = component . container . querySelector (
".t--widget-tabswidget" ,
) ;
const finalPositions = {
left : movedTab.style.left ,
top : movedTab.style.top ,
} ;
expect ( finalPositions . left ) . not . toEqual ( initPositions . left ) ;
expect ( finalPositions . top ) . not . toEqual ( initPositions . top ) ;
} ) ;
it ( "When widgets are moved out of main container bounds move them back to previous position" , ( ) = > {
const children : any = buildChildren ( [
{
type : "TABS_WIDGET" ,
topRow : 5 ,
bottomRow : 5 ,
leftColumn : 5 ,
rightColumn : 5 ,
} ,
] ) ;
const dsl : any = widgetCanvasFactory . build ( {
children ,
} ) ;
spyGetCanvasWidgetDsl . mockImplementation ( mockGetCanvasWidgetDsl ) ;
mockGetIsFetchingPage . mockImplementation ( ( ) = > false ) ;
const component = render (
2022-04-07 05:39:15 +00:00
< MemoryRouter
initialEntries = { [ "/app/applicationSlug/pageSlug-page_id/edit" ] }
>
2021-08-12 05:45:38 +00:00
< MockApplication >
< GlobalHotKeys >
2022-08-26 13:13:48 +00:00
< UpdatedEditor dsl = { dsl } / >
2021-08-12 05:45:38 +00:00
< / GlobalHotKeys >
< / MockApplication >
< / MemoryRouter > ,
{ initialState : store.getState ( ) , sagasToRun : sagasToRunForTests } ,
) ;
const propPane = component . queryByTestId ( "t--propertypane" ) ;
expect ( propPane ) . toBeNull ( ) ;
const canvasWidgets = component . queryAllByTestId ( "test-widget" ) ;
expect ( canvasWidgets . length ) . toBe ( 1 ) ;
const tabsWidget : any = component . container . querySelector (
".t--draggable-tabswidget" ,
) ;
const tab : any = component . container . querySelector ( ".t--widget-tabswidget" ) ;
const initPositions = {
left : tab.style.left ,
top : tab.style.top ,
} ;
2021-09-22 07:18:46 +00:00
act ( ( ) = > {
fireEvent . mouseOver ( tabsWidget ) ;
} ) ;
2021-08-12 05:45:38 +00:00
act ( ( ) = > {
fireEvent . dragStart ( tabsWidget ) ;
} ) ;
2022-01-25 15:28:31 +00:00
const mainCanvas : any = component . queryByTestId ( "div-dragarena-0" ) ;
2021-08-12 05:45:38 +00:00
act ( ( ) = > {
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mousemove" , {
bubbles : true ,
cancelable : true ,
} ) ,
{
offsetX : 0 ,
offsetY : 0 ,
} ,
) ,
) ;
} ) ;
act ( ( ) = > {
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mousemove" , {
bubbles : true ,
cancelable : true ,
} ) ,
{
offsetX : - 500 ,
offsetY : - 500 ,
} ,
) ,
) ;
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mouseup" , {
bubbles : true ,
cancelable : true ,
} ) ,
) ,
) ;
} ) ;
const movedTab : any = component . container . querySelector (
".t--widget-tabswidget" ,
) ;
const finalPositions = {
left : movedTab.style.left ,
top : movedTab.style.top ,
} ;
expect ( finalPositions . left ) . toEqual ( initPositions . left ) ;
expect ( finalPositions . top ) . toEqual ( initPositions . top ) ;
} ) ;
2023-03-04 07:25:54 +00:00
// ToDO(Ashok): Check with Rahul if this test case is still relevant post reflow.
2021-08-12 05:45:38 +00:00
2023-03-04 07:25:54 +00:00
// it("When widgets are colliding with other widgets move them back to previous position", () => {
// const children: any = buildChildren([
// {
// type: "TABS_WIDGET",
// topRow: 5,
// bottomRow: 15,
// leftColumn: 5,
// rightColumn: 15,
// },
// {
// type: "TABLE_WIDGET",
// topRow: 15,
// bottomRow: 25,
// leftColumn: 5,
// rightColumn: 15,
// },
// ]);
// const dsl: any = widgetCanvasFactory.build({
// children,
// });
// spyGetCanvasWidgetDsl.mockImplementation(mockGetCanvasWidgetDsl);
// mockGetIsFetchingPage.mockImplementation(() => false);
2021-09-22 07:18:46 +00:00
2023-03-04 07:25:54 +00:00
// const component = render(
// <MemoryRouter
// initialEntries={["/app/applicationSlug/pageSlug-page_id/edit"]}
// >
// <MockApplication>
// <GlobalHotKeys>
// <UpdatedEditor dsl={dsl} />
// </GlobalHotKeys>
// </MockApplication>
// </MemoryRouter>,
// { initialState: store.getState(), sagasToRun: sagasToRunForTests },
// );
// const propPane = component.queryByTestId("t--propertypane");
// expect(propPane).toBeNull();
// const canvasWidgets = component.queryAllByTestId("test-widget");
// expect(canvasWidgets.length).toBe(2);
// const tabsWidget: any = component.container.querySelector(
// ".t--draggable-tabswidget",
// );
// const tab: any = component.container.querySelector(".t--widget-tabswidget");
// const initPositions = {
// left: tab.style.left,
// top: tab.style.top,
// };
2021-09-22 07:18:46 +00:00
2023-03-04 07:25:54 +00:00
// act(() => {
// fireEvent.mouseOver(tabsWidget);
// });
2021-08-12 05:45:38 +00:00
2023-03-04 07:25:54 +00:00
// act(() => {
// fireEvent.dragStart(tabsWidget);
// });
// const mainCanvas: any = component.queryByTestId("div-dragarena-0");
// act(() => {
// fireEvent(
// mainCanvas,
// syntheticTestMouseEvent(
// new MouseEvent("mousemove", {
// bubbles: true,
// cancelable: true,
// }),
// {
// offsetX: 0,
// offsetY: 0,
// },
// ),
// );
// });
// act(() => {
// fireEvent(
// mainCanvas,
// syntheticTestMouseEvent(
// new MouseEvent("mousemove", {
// bubbles: true,
// cancelable: true,
// }),
// {
// offsetX: 0,
// offsetY: 50,
// },
// ),
// );
// fireEvent(
// mainCanvas,
// syntheticTestMouseEvent(
// new MouseEvent("mouseup", {
// bubbles: true,
// cancelable: true,
// }),
// ),
// );
// });
// const movedTab: any = component.container.querySelector(
// ".t--widget-tabswidget",
// );
// const finalPositions = {
// left: movedTab.style.left,
// top: movedTab.style.top,
// };
// expect(finalPositions.left).toEqual(initPositions.left);
// expect(finalPositions.top).toEqual(initPositions.top);
// });
2021-08-12 05:45:38 +00:00
it ( "When widgets are out of bottom most bounds of parent canvas, canvas has to expand" , ( ) = > {
const children : any = buildChildren ( [
{
type : "TABS_WIDGET" ,
topRow : 5 ,
bottomRow : 15 ,
leftColumn : 5 ,
rightColumn : 15 ,
} ,
{
type : "TABLE_WIDGET" ,
topRow : 15 ,
bottomRow : 25 ,
leftColumn : 5 ,
rightColumn : 15 ,
2023-02-21 13:38:16 +00:00
widgetId : "tableWidgetId" ,
2021-08-12 05:45:38 +00:00
} ,
] ) ;
const dsl : any = widgetCanvasFactory . build ( {
children ,
} ) ;
dsl . bottomRow = 250 ;
2022-08-19 10:10:36 +00:00
2021-08-12 05:45:38 +00:00
spyGetCanvasWidgetDsl . mockImplementation ( mockGetCanvasWidgetDsl ) ;
mockGetIsFetchingPage . mockImplementation ( ( ) = > false ) ;
const component = render (
2022-04-07 05:39:15 +00:00
< MemoryRouter
initialEntries = { [ "/app/applicationSlug/pageSlug-page_id/edit" ] }
>
2021-08-12 05:45:38 +00:00
< MockApplication >
< GlobalHotKeys >
2022-08-26 13:13:48 +00:00
< UpdatedEditor dsl = { dsl } / >
2021-08-12 05:45:38 +00:00
< / GlobalHotKeys >
< / MockApplication >
< / MemoryRouter > ,
{ initialState : store.getState ( ) , sagasToRun : sagasToRunForTests } ,
) ;
const propPane = component . queryByTestId ( "t--propertypane" ) ;
expect ( propPane ) . toBeNull ( ) ;
const canvasWidgets = component . queryAllByTestId ( "test-widget" ) ;
expect ( canvasWidgets . length ) . toBe ( 2 ) ;
const tabsWidget : any = component . container . querySelector (
".t--draggable-tablewidget" ,
) ;
2021-09-22 07:18:46 +00:00
act ( ( ) = > {
fireEvent . mouseOver ( tabsWidget ) ;
} ) ;
2023-02-21 13:38:16 +00:00
jest
. spyOn ( uiSelectors , "getSelectedWidgets" )
. mockReturnValue ( [ "tableWidgetId" ] ) ;
2021-08-12 05:45:38 +00:00
act ( ( ) = > {
fireEvent . dragStart ( tabsWidget ) ;
} ) ;
2022-01-25 15:28:31 +00:00
const mainCanvas : any = component . queryByTestId ( "div-dragarena-0" ) ;
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] 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
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] 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: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
const dropTarget : any =
component . container . getElementsByClassName ( "t--drop-target" ) [ 0 ] ;
2021-08-12 05:45:38 +00:00
let initialLength = dropTarget . style . height ;
act ( ( ) = > {
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mousemove" , {
bubbles : true ,
cancelable : true ,
} ) ,
{
offsetX : 0 ,
offsetY : 0 ,
} ,
) ,
) ;
} ) ;
act ( ( ) = > {
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mousemove" , {
bubbles : true ,
cancelable : true ,
} ) ,
{
offsetX : 0 ,
offsetY : 300 ,
// min height - (component height + bottom row)
} ,
) ,
) ;
} ) ;
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] 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
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] 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: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
let updatedDropTarget : any =
component . container . getElementsByClassName ( "t--drop-target" ) [ 0 ] ;
2021-08-12 05:45:38 +00:00
let updatedLength = updatedDropTarget . style . height ;
expect ( initialLength ) . not . toEqual ( updatedLength ) ;
initialLength = updatedLength ;
const amountMovedY = 300 ;
act ( ( ) = > {
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mousemove" , {
bubbles : true ,
cancelable : true ,
} ) ,
{
offsetX : 0 ,
offsetY : 300 + amountMovedY ,
} ,
) ,
) ;
} ) ;
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] 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
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] 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: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
updatedDropTarget =
component . container . getElementsByClassName ( "t--drop-target" ) [ 0 ] ;
2021-08-12 05:45:38 +00:00
updatedLength = updatedDropTarget . style . height ;
expect ( getAbsolutePixels ( initialLength ) + amountMovedY ) . toEqual (
getAbsolutePixels ( updatedLength ) ,
) ;
} ) ;
it ( "Drag and Drop widget into an empty canvas" , ( ) = > {
const children : any = buildChildren ( [ ] ) ;
const dsl : any = widgetCanvasFactory . build ( {
children ,
} ) ;
spyGetCanvasWidgetDsl . mockImplementation ( mockGetCanvasWidgetDsl ) ;
mockGetIsFetchingPage . mockImplementation ( ( ) = > false ) ;
2022-12-01 06:30:50 +00:00
jest
. spyOn ( utilities , "getPagePermissions" )
. mockImplementation ( mockGetPagePermissions ) ;
2021-08-12 05:45:38 +00:00
const component = render (
2022-04-07 05:39:15 +00:00
< MemoryRouter
initialEntries = { [ "/app/applicationSlug/pageSlug-page_id/edit" ] }
>
2021-08-12 05:45:38 +00:00
< MockApplication >
< GlobalHotKeys >
2022-08-26 13:13:48 +00:00
< UpdatedEditor dsl = { dsl } / >
2021-08-12 05:45:38 +00:00
< / GlobalHotKeys >
< / MockApplication >
< / MemoryRouter > ,
{ initialState : store.getState ( ) , sagasToRun : sagasToRunForTests } ,
) ;
const propPane = component . queryByTestId ( "t--propertypane" ) ;
expect ( propPane ) . toBeNull ( ) ;
const canvasWidgets = component . queryAllByTestId ( "test-widget" ) ;
// empty canvas
expect ( canvasWidgets . length ) . toBe ( 0 ) ;
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] 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
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] 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: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
const allAddEntityButtons : any =
component . container . querySelectorAll ( ".t--entity-add-btn" ) ;
2021-08-12 05:45:38 +00:00
const widgetAddButton = allAddEntityButtons [ 1 ] ;
act ( ( ) = > {
fireEvent . click ( widgetAddButton ) ;
} ) ;
2021-10-18 14:03:44 +00:00
const containerButton : any = component . queryAllByText ( "Container" ) ;
2021-08-12 05:45:38 +00:00
act ( ( ) = > {
2021-10-18 14:03:44 +00:00
fireEvent . dragStart ( containerButton [ 0 ] ) ;
2021-08-12 05:45:38 +00:00
} ) ;
2022-01-25 15:28:31 +00:00
const mainCanvas : any = component . queryByTestId ( "div-dragarena-0" ) ;
2021-08-12 05:45:38 +00:00
act ( ( ) = > {
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mousemove" , {
bubbles : true ,
cancelable : true ,
} ) ,
{
offsetX : 200 ,
offsetY : 200 ,
} ,
) ,
) ;
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mousemove" , {
bubbles : true ,
cancelable : true ,
} ) ,
{
offsetX : 200 ,
offsetY : 200 ,
} ,
) ,
) ;
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mouseup" , {
bubbles : true ,
cancelable : true ,
} ) ,
{
offsetX : 200 ,
offsetY : 200 ,
} ,
) ,
) ;
} ) ;
const newlyAddedCanvas = component . container . querySelectorAll (
"div[type='CONTAINER_WIDGET']" ,
) ;
expect ( newlyAddedCanvas . length ) . toBe ( 1 ) ;
} ) ;
2021-09-22 07:18:46 +00:00
it ( "Disallow drag if widget not focused" , ( ) = > {
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] 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
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] 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: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
const initialState = store . getState ( ) as unknown as Partial < AppState > ;
2022-01-13 13:21:57 +00:00
const containerId = generateReactKey ( ) ;
const canvasId = generateReactKey ( ) ;
2021-09-22 07:18:46 +00:00
2022-01-13 13:21:57 +00:00
const canvasWidget = buildChildren ( [
{
type : "CANVAS_WIDGET" ,
parentId : containerId ,
children : [ ] ,
widgetId : canvasId ,
dropDisabled : true ,
} ,
] ) ;
const containerChildren : any = buildChildren ( [
2021-09-22 07:18:46 +00:00
{
type : "CONTAINER_WIDGET" ,
2022-01-13 13:21:57 +00:00
children : canvasWidget ,
widgetId : containerId ,
2021-09-22 07:18:46 +00:00
parentId : "0" ,
} ,
] ) ;
const dsl : any = widgetCanvasFactory . build ( {
2022-01-13 13:21:57 +00:00
children : containerChildren ,
2021-09-22 07:18:46 +00:00
} ) ;
spyGetCanvasWidgetDsl . mockImplementation ( mockGetCanvasWidgetDsl ) ;
mockGetIsFetchingPage . mockImplementation ( ( ) = > false ) ;
const component = render (
2022-04-07 05:39:15 +00:00
< MemoryRouter
initialEntries = { [ "/app/applicationSlug/pageSlug-page_id/edit" ] }
>
2021-09-22 07:18:46 +00:00
< MockApplication >
< GlobalHotKeys >
2022-08-26 13:13:48 +00:00
< UpdatedEditor dsl = { dsl } / >
2021-09-22 07:18:46 +00:00
< / GlobalHotKeys >
< / MockApplication >
< / MemoryRouter > ,
{ initialState , sagasToRun : sagasToRunForTests } ,
) ;
const widget : any = component . container . querySelector (
".t--widget-containerwidget" ,
) ;
const draggableWidget : any = component . container . querySelector (
".t--draggable-containerwidget" ,
) ;
const canvasWidgets = component . queryAllByTestId ( "test-widget" ) ;
expect ( canvasWidgets . length ) . toBe ( 1 ) ;
const initWidgetPosition = {
left : widget.style.left ,
top : widget.style.top ,
} ;
2023-02-21 13:38:16 +00:00
jest
. spyOn ( uiSelectors , "getSelectedWidgets" )
. mockReturnValue ( [ containerId ] ) ;
2021-09-22 07:18:46 +00:00
act ( ( ) = > {
fireEvent . dragStart ( draggableWidget ) ;
} ) ;
2022-01-25 15:28:31 +00:00
let mainCanvas : any = component . queryByTestId ( "div-dragarena-0" ) ;
2021-09-22 07:18:46 +00:00
expect ( mainCanvas ) . toBeNull ( ) ;
// Focus on widget and drag
act ( ( ) = > {
fireEvent . mouseOver ( draggableWidget ) ;
} ) ;
act ( ( ) = > {
fireEvent . dragStart ( draggableWidget ) ;
} ) ;
2022-01-25 15:28:31 +00:00
mainCanvas = component . queryByTestId ( "div-dragarena-0" ) ;
2021-09-22 07:18:46 +00:00
act ( ( ) = > {
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mousemove" , {
bubbles : true ,
cancelable : true ,
} ) ,
{
2021-11-23 08:01:46 +00:00
offsetX : 100 ,
offsetY : 100 ,
2021-09-22 07:18:46 +00:00
} ,
) ,
) ;
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mouseup" , {
bubbles : true ,
cancelable : true ,
} ) ,
) ,
) ;
} ) ;
const movedWidget : any = component . container . querySelector (
".t--widget-containerwidget" ,
) ;
const finalWidgetPosition = {
left : movedWidget.style.left ,
top : movedWidget.style.top ,
} ;
expect ( finalWidgetPosition ) . not . toStrictEqual ( initWidgetPosition ) ;
} ) ;
afterAll ( ( ) = > jest . resetModules ( ) ) ;
} ) ;
describe ( "Drag in a nested container" , ( ) = > {
const mockGetIsFetchingPage = jest . spyOn ( utilities , "getIsFetchingPage" ) ;
const spyGetCanvasWidgetDsl = jest . spyOn ( utilities , "getCanvasWidgetDsl" ) ;
// These need to be at the top to avoid imports not being mocked. ideally should be in setup.ts but will override for all other tests
beforeAll ( ( ) = > {
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] 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
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] 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: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
const mockGenerator = function * ( ) {
2021-09-22 07:18:46 +00:00
yield all ( [ ] ) ;
} ;
const debounceMocked = jest . spyOn ( lodash , "debounce" ) ;
debounceMocked . mockImplementation ( ( fn : any ) = > fn ) ;
// top avoid the first middleware run which wud initiate all sagas.
jest . mock ( "sagas" , ( ) = > ( {
rootSaga : mockGenerator ,
} ) ) ;
// only the deafault exports are mocked to avoid overriding utilities exported out of them. defaults are marked to avoid worker initiation and page api calls in tests.
jest . mock ( "sagas/EvaluationsSaga" , ( ) = > ( {
. . . jest . requireActual ( "sagas/EvaluationsSaga" ) ,
default : mockGenerator ,
} ) ) ;
jest . mock ( "sagas/PageSagas" , ( ) = > ( {
. . . jest . requireActual ( "sagas/PageSagas" ) ,
default : mockGenerator ,
} ) ) ;
} ) ;
it ( "container drags when focused on" , ( ) = > {
spyGetCanvasWidgetDsl . mockImplementation ( mockGetCanvasWidgetDsl ) ;
mockGetIsFetchingPage . mockImplementation ( ( ) = > false ) ;
const component = renderNestedComponent ( ) ;
2023-02-21 13:38:16 +00:00
jest
. spyOn ( uiSelectors , "getSelectedWidgets" )
. mockReturnValue ( [ "container-id" ] ) ;
2021-09-22 07:18:46 +00:00
const containerWidget : any = component . container . querySelector (
".t--widget-containerwidget" ,
) ;
const draggableContainerWidget : any = component . container . querySelector (
".t--draggable-containerwidget" ,
) ;
const canvasWidgets = component . queryAllByTestId ( "test-widget" ) ;
expect ( canvasWidgets . length ) . toBe ( 3 ) ;
const initContainerWidgetPosition = {
left : containerWidget.style.left ,
top : containerWidget.style.top ,
} ;
act ( ( ) = > {
fireEvent . mouseOver ( draggableContainerWidget ) ;
} ) ;
act ( ( ) = > {
fireEvent . dragStart ( draggableContainerWidget ) ;
} ) ;
2022-01-25 15:28:31 +00:00
const mainCanvas : any = component . queryByTestId ( "div-dragarena-0" ) ;
2021-09-22 07:18:46 +00:00
act ( ( ) = > {
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mousemove" , {
bubbles : true ,
cancelable : true ,
} ) ,
{
offsetX : 100 ,
offsetY : 100 ,
} ,
) ,
) ;
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mouseup" , {
bubbles : true ,
cancelable : true ,
} ) ,
) ,
) ;
} ) ;
const movedContainerWidget : any = component . container . querySelector (
".t--widget-containerwidget" ,
) ;
const finalContainerWidgetPositions = {
left : movedContainerWidget.style.left ,
top : movedContainerWidget.style.top ,
} ;
expect ( finalContainerWidgetPositions ) . not . toStrictEqual (
initContainerWidgetPosition ,
) ;
} ) ;
it ( "nested widget drags when focused on" , ( ) = > {
spyGetCanvasWidgetDsl . mockImplementation ( mockGetCanvasWidgetDsl ) ;
mockGetIsFetchingPage . mockImplementation ( ( ) = > false ) ;
const component = renderNestedComponent ( ) ;
2023-02-21 13:38:16 +00:00
jest
. spyOn ( uiSelectors , "getSelectedWidgets" )
. mockReturnValue ( [ "text-widget" ] ) ;
2021-09-22 07:18:46 +00:00
const textWidget : any = component . container . querySelector (
".t--widget-textwidget" ,
) ;
const draggableTextWidget : any = component . container . querySelector (
".t--draggable-textwidget" ,
) ;
const canvasWidgets = component . queryAllByTestId ( "test-widget" ) ;
expect ( canvasWidgets . length ) . toBe ( 3 ) ;
const initTextWidgetPosition = {
left : textWidget.style.left ,
top : textWidget.style.top ,
} ;
act ( ( ) = > {
fireEvent . mouseOver ( draggableTextWidget ) ;
} ) ;
act ( ( ) = > {
fireEvent . dragStart ( draggableTextWidget ) ;
} ) ;
2022-01-25 15:28:31 +00:00
const mainCanvas : any = component . queryByTestId ( "div-dragarena-0" ) ;
2021-09-22 07:18:46 +00:00
act ( ( ) = > {
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mousemove" , {
bubbles : true ,
cancelable : true ,
} ) ,
{
offsetX : 500 ,
offsetY : 500 ,
} ,
) ,
) ;
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mouseup" , {
bubbles : true ,
cancelable : true ,
} ) ,
) ,
) ;
} ) ;
const movedTextWidget : any = component . container . querySelector (
".t--widget-textwidget" ,
) ;
const finalTextWidgetPositions = {
left : movedTextWidget.style.left ,
top : movedTextWidget.style.top ,
} ;
expect ( finalTextWidgetPositions ) . not . toStrictEqual ( initTextWidgetPosition ) ;
} ) ;
it ( "does not let disabledWidget drag and parent widget position stays same" , ( ) = > {
spyGetCanvasWidgetDsl . mockImplementation ( mockGetCanvasWidgetDsl ) ;
mockGetIsFetchingPage . mockImplementation ( ( ) = > false ) ;
const component = renderNestedComponent ( ) ;
const inputWidget : any = component . container . querySelector (
2022-01-18 07:52:24 +00:00
".t--widget-inputwidgetv2" ,
2021-09-22 07:18:46 +00:00
) ;
const draggableInputWidget : any = component . container . querySelector (
2022-01-18 07:52:24 +00:00
".t--draggable-inputwidgetv2" ,
2021-09-22 07:18:46 +00:00
) ;
const draggableContainerWidget : any = component . container . querySelector (
".t--draggable-containerwidget" ,
) ;
const containerWidget : any = component . container . querySelector (
".t--widget-containerwidget" ,
) ;
const initContainerWidgetPosition = {
left : containerWidget.style.left ,
top : containerWidget.style.top ,
} ;
const initInputWidgetPosition = {
left : inputWidget.style.left ,
top : inputWidget.style.top ,
} ;
const canvasWidgets = component . queryAllByTestId ( "test-widget" ) ;
expect ( canvasWidgets . length ) . toBe ( 3 ) ;
act ( ( ) = > {
fireEvent . mouseOver ( draggableContainerWidget ) ;
} ) ;
act ( ( ) = > {
fireEvent . mouseOver ( draggableInputWidget ) ;
} ) ;
act ( ( ) = > {
fireEvent . dragStart ( draggableInputWidget ) ;
} ) ;
2022-01-25 15:28:31 +00:00
const mainCanvas : any = component . queryByTestId ( "div-dragarena-0" ) ;
2021-09-22 07:18:46 +00:00
if ( mainCanvas ) {
act ( ( ) = > {
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mousemove" , {
bubbles : true ,
cancelable : true ,
} ) ,
{
offsetX : 500 ,
offsetY : 500 ,
} ,
) ,
) ;
fireEvent (
mainCanvas ,
syntheticTestMouseEvent (
new MouseEvent ( "mouseup" , {
bubbles : true ,
cancelable : true ,
} ) ,
) ,
) ;
} ) ;
}
const movedInputWidget : any = component . container . querySelector (
2022-01-18 07:52:24 +00:00
".t--widget-inputwidgetv2" ,
2021-09-22 07:18:46 +00:00
) ;
const finalInputWidgetPositions = {
left : movedInputWidget.style.left ,
top : movedInputWidget.style.top ,
} ;
const movedContainerWidget : any = component . container . querySelector (
".t--widget-containerwidget" ,
) ;
const finalContainerWidgetPositions = {
left : movedContainerWidget.style.left ,
top : movedContainerWidget.style.top ,
} ;
expect ( finalInputWidgetPositions ) . toStrictEqual ( initInputWidgetPosition ) ;
expect ( initContainerWidgetPosition ) . toStrictEqual (
finalContainerWidgetPositions ,
) ;
} ) ;
2021-08-12 05:45:38 +00:00
afterAll ( ( ) = > jest . resetModules ( ) ) ;
} ) ;