Skip to content

Commit

Permalink
chore: Split derived.test.js to separate files. (#38162)
Browse files Browse the repository at this point in the history
## Description
This PR started with this goal:
- Deleted the unreadable `derived.test.js` (4668 lines) file and split
each suite to its file.
- Moved all `derived.js` related specs in widget folder to __tests__
folder

Later we found that `testRegex` in `jest.config` will treat anything
inside `__tests__` as runnable, so we modify this rule and are moving to
a consistent naming for our unit tests(any file ending with `.test.` or
`.spec.`

This refactor aims to improve maintainability and ensure that the table
widget's derived properties are thoroughly tested.


Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags=""

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!WARNING]
> Tests have not run on the HEAD
b3168bb yet
> <hr>Tue, 17 Dec 2024 10:20:54 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
	- Expanded properties for table widget configuration.
- Introduced sample data constants for column schemas and processed
table data.

- **Bug Fixes**
- Improved validation tests for editable cells and row selection
functions.

- **Tests**
- Added comprehensive test suites for various table widget
functionalities, including filtering, sorting, and row selection.
	- Introduced tests for handling HTML content within table columns.
	- Added tests for new functions related to row updates and indices.
- Enhanced test coverage for existing utility functions and table
properties.

- **Chores**
- Updated import paths to reflect a new directory structure across
various test files.
- Modified Jest configuration for improved readability and regex
adjustments.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
rahulbarwal authored Dec 17, 2024

Unverified

This user has not yet uploaded their public signing key.
1 parent 8415e16 commit 5d213dd
Showing 25 changed files with 4,720 additions and 4,681 deletions.
11 changes: 6 additions & 5 deletions app/client/jest.config.js
Original file line number Diff line number Diff line change
@@ -23,17 +23,19 @@ module.exports = {
before: [
{
path: "node_modules/ts-jest-mock-import-meta",
options: { metaObjectReplacement: { url: "https://www.url.com" } },
options: {
metaObjectReplacement: { url: "https://www.url.com" },
},
},
],
},
}
},
],
},
testEnvironment: "jsdom",
testTimeout: 9000,
setupFilesAfterEnv: ["<rootDir>/test/setup.ts"],
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(tsx|ts|js)?$",
testRegex: "\\.(test|spec)\\.(tsx|ts|js)?$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node", "css"],
moduleDirectories: ["node_modules", "src", "test"],
transformIgnorePatterns: [
@@ -68,8 +70,7 @@ module.exports = {
"<rootDir>/node_modules/@blueprintjs/select/lib/esnext",
"@appsmith/ads": "<rootDir>/node_modules/@appsmith/ads",
"^canvas$": "jest-canvas-mock",
"^entities/(.*)$": "<rootDir>/src/entities/$1", // Match 'entities/*'

"^entities/(.*)$": "<rootDir>/src/entities/$1", // Match 'entities/*'
},
globals: {
APPSMITH_FEATURE_CONFIGS: {
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ResponsiveBehavior } from "layoutSystems/common/utils/constants";
import TableWidgetV2 from ".";
import type { TableWidgetProps } from "../constants";
import TableWidgetV2 from "..";
import type { TableWidgetProps } from "../../constants";

describe("TableWidgetV2 getWidgetView", () => {
const tableWidgetProps: TableWidgetProps = {
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
export const samplePrimaryColumns = {
step: {
index: 0,
width: 150,
id: "step",
originalId: "step",
alias: "step",
horizontalAlignment: "LEFT",
verticalAlignment: "CENTER",
columnType: "text",
textSize: "0.875rem",
enableFilter: true,
enableSort: true,
isVisible: true,
isCellVisible: true,
isCellEditable: false,
isDerived: false,
label: "step",
computedValue: ["#1", "#2", "#3"],
labelColor: "#FFFFFF",
cellBackground: "",
textColor: "",
fontStyle: "",
},
task: {
index: 1,
width: 150,
id: "task",
originalId: "task",
alias: "task",
horizontalAlignment: "LEFT",
verticalAlignment: "CENTER",
columnType: "text",
textSize: "0.875rem",
enableFilter: true,
enableSort: true,
isVisible: true,
isCellVisible: true,
isCellEditable: false,
isDerived: false,
label: "task",
computedValue: [
"Drop a table",
"Create a query fetch_users with the Mock DB",
"Bind the query using => fetch_users.data",
],
labelColor: "#FFFFFF",
cellBackground: "",
textColor: "",
fontStyle: "",
},
status: {
index: 2,
width: 150,
id: "status",
originalId: "status",
alias: "status",
horizontalAlignment: "LEFT",
verticalAlignment: "CENTER",
columnType: "text",
textSize: "0.875rem",
enableFilter: true,
enableSort: true,
isVisible: true,
isCellVisible: true,
isCellEditable: false,
isDerived: false,
label: "status",
computedValue: ["✅", "--", "--"],
labelColor: "#FFFFFF",
cellBackground: "",
textColor: "",
fontStyle: "",
},
action: {
index: 3,
width: 150,
id: "action",
originalId: "action",
alias: "action",
horizontalAlignment: "LEFT",
verticalAlignment: "CENTER",
columnType: "button",
textSize: "0.875rem",
enableFilter: true,
enableSort: true,
isVisible: true,
isCellVisible: true,
isCellEditable: false,
isDisabled: false,
isDerived: false,
label: "action",
onClick:
"{{currentRow.step === '#1' ? showAlert('Done', 'success') : currentRow.step === '#2' ? navigateTo('https://docs.appsmith.com/core-concepts/connecting-to-data-sources/querying-a-database',undefined,'NEW_WINDOW') : navigateTo('https://docs.appsmith.com/core-concepts/displaying-data-read/display-data-tables',undefined,'NEW_WINDOW')}}",
computedValue: ["", "", ""],
labelColor: "#FFFFFF",
buttonColor: ["#553DE9", "#553DE9", "#553DE9"],
borderRadius: ["0.375rem", "0.375rem", "0.375rem"],
boxShadow: ["none", "none", "none"],
buttonLabel: ["Action", "Action", "Action"],
buttonVariant: "PRIMARY",
},
customColumn1: {
allowCellWrapping: false,
index: 4,
width: 150,
originalId: "customColumn1",
id: "customColumn1",
alias: "customColumn1",
horizontalAlignment: "LEFT",
verticalAlignment: "CENTER",
columnType: "menuButton",
textSize: "0.875rem",
enableFilter: true,
enableSort: true,
isVisible: true,
isDisabled: false,
isCellEditable: false,
isEditable: false,
isCellVisible: true,
isDerived: true,
label: "menu",
isSaveVisible: true,
isDiscardVisible: true,
computedValue: "",
buttonStyle: "rgb(3, 179, 101)",
labelColor: "#FFFFFF",
menuColor: ["#553DE9", "#553DE9", "#553DE9"],
borderRadius: ["0.375rem", "0.375rem", "0.375rem"],
boxShadow: ["none", "none", "none"],
customAlias: "",
menuButtonLabel: ["Open Menu", "Open Menu", "Open Menu"],
menuVariant: "PRIMARY",
menuButtoniconName: "",
},
customColumn2: {
allowCellWrapping: false,
index: 5,
width: 150,
originalId: "customColumn2",
id: "customColumn2",
alias: "customColumn2",
horizontalAlignment: "LEFT",
verticalAlignment: "CENTER",
columnType: "iconButton",
textSize: "0.875rem",
enableFilter: true,
enableSort: true,
isVisible: true,
isDisabled: false,
isCellEditable: false,
isEditable: false,
isCellVisible: true,
isDerived: true,
label: "icon",
isSaveVisible: true,
isDiscardVisible: true,
computedValue: "",
buttonStyle: "rgb(3, 179, 101)",
labelColor: "#FFFFFF",
buttonColor: ["#553DE9", "#553DE9", "#553DE9"],
borderRadius: ["0.375rem", "0.375rem", "0.375rem"],
boxShadow: ["none", "none", "none"],
customAlias: "",
buttonVariant: "PRIMARY",
iconName: "add",
},
};
export const sampleProcessedTableData = [
{
step: "#1",
task: "Drop a table",
status: "✅",
action: "",
__originalIndex__: 0,
},
{
step: "#2",
task: "Create a query fetch_users with the Mock DB",
status: "--",
action: "",
__originalIndex__: 1,
},
{
step: "#3",
task: "Bind the query using => fetch_users.data",
status: "--",
action: "",
__originalIndex__: 2,
},
];
Loading

0 comments on commit 5d213dd

Please sign in to comment.