-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Added warning message in response pane while prepared statement is on #36407
Merged
albinAppsmith
merged 6 commits into
release
from
action-redesign/prepared-statement-warning
Sep 23, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
46410cc
feat: Added warning message in response pane while prepared statement…
albinAppsmith 5ed0dfa
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
albinAppsmith cc19110
feat: Added unit test for prepared statement warning
albinAppsmith 1ad67e1
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
albinAppsmith 9d451ab
fix: codemirror suggetion
albinAppsmith debc9f3
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
albinAppsmith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
235 changes: 235 additions & 0 deletions
235
app/client/src/pages/Editor/QueryEditor/QueryResponseTab.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,235 @@ | ||
import React from "react"; | ||
import { render } from "@testing-library/react"; | ||
import { Provider } from "react-redux"; | ||
import configureStore from "redux-mock-store"; | ||
import QueryResponseTab from "./QueryResponseTab"; | ||
import { ENTITY_TYPE } from "ee/entities/AppsmithConsole/utils"; | ||
import type { Action } from "entities/Action"; | ||
import { unitTestBaseMockStore } from "layoutSystems/common/dropTarget/unitTestUtils"; | ||
import { EditorViewMode } from "ee/entities/IDE/constants"; | ||
import { lightTheme } from "selectors/themeSelectors"; | ||
import { ThemeProvider } from "styled-components"; | ||
import { BrowserRouter as Router } from "react-router-dom"; | ||
|
||
// Mock store | ||
const mockStore = configureStore([]); | ||
|
||
const defaultProps = { | ||
actionName: "Test Action", | ||
actionSource: { | ||
name: "test source", | ||
id: "test-source-id", | ||
type: ENTITY_TYPE.ACTION, | ||
}, | ||
currentActionConfig: { | ||
id: "test-action-id", | ||
name: "Test Action", | ||
actionConfiguration: { pluginSpecifiedTemplates: [{ value: true }] }, | ||
userPermissions: ["execute"], | ||
} as Action, | ||
isRunning: false, | ||
onRunClick: jest.fn(), | ||
runErrorMessage: "", | ||
}; | ||
|
||
const storeData = { | ||
...unitTestBaseMockStore, | ||
evaluations: { | ||
tree: {}, | ||
}, | ||
entities: { | ||
plugins: { | ||
list: [], | ||
}, | ||
datasources: { | ||
structure: {}, | ||
}, | ||
}, | ||
ui: { | ||
...unitTestBaseMockStore.ui, | ||
users: { | ||
featureFlag: { | ||
data: {}, | ||
overriddenFlags: {}, | ||
}, | ||
}, | ||
ide: { | ||
view: EditorViewMode.FullScreen, | ||
}, | ||
debugger: { | ||
context: { | ||
errorCount: 0, | ||
}, | ||
}, | ||
queryPane: { | ||
debugger: { | ||
open: true, | ||
responseTabHeight: 200, | ||
selectedTab: "response", | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
describe("QueryResponseTab", () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let store: any; | ||
|
||
beforeEach(() => { | ||
store = mockStore(storeData); | ||
}); | ||
|
||
/** Test use prepared statement warning **/ | ||
it("1. Prepared statement warning should not be showing", () => { | ||
const { container } = render( | ||
<Provider store={store}> | ||
<ThemeProvider theme={lightTheme}> | ||
<Router> | ||
<QueryResponseTab {...defaultProps} /> | ||
</Router> | ||
</ThemeProvider> | ||
</Provider>, | ||
); | ||
|
||
// Check if the prepared statement warning is not showing | ||
expect( | ||
container.querySelector("[data-testid='t--prepared-statement-warning']"), | ||
).toBeNull(); | ||
}); | ||
|
||
it("2. Check if prepared statement warning is not showing while running the query", () => { | ||
const { container } = render( | ||
<Provider store={store}> | ||
<ThemeProvider theme={lightTheme}> | ||
<Router> | ||
<QueryResponseTab {...defaultProps} isRunning /> | ||
</Router> | ||
</ThemeProvider> | ||
</Provider>, | ||
); | ||
|
||
// Check if the prepared statement warning is showing | ||
expect( | ||
container.querySelector("[data-testid='t--prepared-statement-warning']"), | ||
).toBeNull(); | ||
}); | ||
|
||
it("3. Check if prepared statement warning is not showing when run is successful", () => { | ||
store = mockStore({ | ||
...storeData, | ||
entities: { | ||
...storeData.entities, | ||
actions: [ | ||
{ | ||
config: { | ||
id: "test-action-id", | ||
name: "Test Action", | ||
}, | ||
isLoading: false, | ||
data: { | ||
body: [{ key: "value" }], | ||
isExecutionSuccess: true, | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
const { container } = render( | ||
<Provider store={store}> | ||
<ThemeProvider theme={lightTheme}> | ||
<Router> | ||
<QueryResponseTab {...defaultProps} /> | ||
</Router> | ||
</ThemeProvider> | ||
</Provider>, | ||
); | ||
|
||
// Check if the prepared statement warning is showing | ||
expect( | ||
container.querySelector("[data-testid='t--prepared-statement-warning']"), | ||
).toBeNull(); | ||
}); | ||
|
||
it("4. Check if prepared statement warning is showing when run is failed", () => { | ||
store = mockStore({ | ||
...storeData, | ||
entities: { | ||
...storeData.entities, | ||
actions: [ | ||
{ | ||
config: { | ||
id: "test-action-id", | ||
name: "Test Action", | ||
}, | ||
isLoading: false, | ||
data: { | ||
body: "ERROR: relation 'userssss' does not exist Position: 15", | ||
isExecutionSuccess: false, | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
const { container } = render( | ||
<Provider store={store}> | ||
<ThemeProvider theme={lightTheme}> | ||
<Router> | ||
<QueryResponseTab {...defaultProps} /> | ||
</Router> | ||
</ThemeProvider> | ||
</Provider>, | ||
); | ||
|
||
// Check if the prepared statement warning is showing | ||
expect( | ||
container.querySelector("[data-testid='t--prepared-statement-warning']"), | ||
).not.toBeNull(); | ||
}); | ||
|
||
it("5. Check if prepared statement warning is not showing when prepared statement is turned off", () => { | ||
store = mockStore({ | ||
...storeData, | ||
entities: { | ||
...storeData.entities, | ||
actions: [ | ||
{ | ||
config: { | ||
id: "test-action-id", | ||
name: "Test Action", | ||
}, | ||
isLoading: false, | ||
data: { | ||
body: "ERROR: relation 'userssss' does not exist Position: 15", | ||
isExecutionSuccess: false, | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
const props = { | ||
...defaultProps, | ||
currentActionConfig: { | ||
...defaultProps.currentActionConfig, | ||
actionConfiguration: { pluginSpecifiedTemplates: [{ value: false }] }, | ||
} as Action, | ||
}; | ||
|
||
const { container } = render( | ||
<Provider store={store}> | ||
<ThemeProvider theme={lightTheme}> | ||
<Router> | ||
<QueryResponseTab {...props} /> | ||
</Router> | ||
</ThemeProvider> | ||
</Provider>, | ||
); | ||
|
||
// Check if the prepared statement warning is showing | ||
expect( | ||
container.querySelector("[data-testid='t--prepared-statement-warning']"), | ||
).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done on introducing the
PREPARED_STATEMENT_WARNING
constantYou've defined a new constant to display a warning message when prepared statements are enabled and an error occurs. This aligns perfectly with the PR objectives and enhances user awareness during error scenarios.
However, let's consider a small improvement to keep our code consistent and maintainable.
To maintain consistency with other message constants in this file, it would be better to define
MESSAGE
andLINK
as constant strings rather than arrow functions, unless dynamic computation is required. Many existing constants use direct string assignments.Here's how you might refactor the code:
This change makes the constants consistent with the rest of the file and simplifies their usage.
Committable suggestion