You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "justinpark (via GitHub)" <gi...@apache.org> on 2023/09/12 17:41:47 UTC
[GitHub] [superset] justinpark opened a new pull request, #25274: chore(sqllab): Migrate tests to typescript
justinpark opened a new pull request, #25274:
URL: https://github.com/apache/superset/pull/25274
### SUMMARY
Migrates legacy jsx tests to typescript including replacing enzyme by testing-library.
### TESTING INSTRUCTIONS
npm run type and test
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] justinpark commented on a diff in pull request #25274: chore(sqllab): Migrate tests to typescript
Posted by "justinpark (via GitHub)" <gi...@apache.org>.
justinpark commented on code in PR #25274:
URL: https://github.com/apache/superset/pull/25274#discussion_r1325133374
##########
superset-frontend/src/SqlLab/components/HighlightedSql/HighlightedSql.test.tsx:
##########
@@ -0,0 +1,48 @@
+/**
Review Comment:
Thanks @captain-hoity-toity for the detail improvement. It was basically migrating existing test block to typescript so I was not able to focus on the test quality.
I'll update your improvement suggestion too!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] michael-s-molina commented on a diff in pull request #25274: chore(sqllab): Migrate tests to typescript
Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #25274:
URL: https://github.com/apache/superset/pull/25274#discussion_r1323468056
##########
superset-frontend/src/SqlLab/components/HighlightedSql/HighlightedSql.test.tsx:
##########
@@ -17,12 +17,9 @@
* under the License.
*/
import React from 'react';
-import SyntaxHighlighter from 'react-syntax-highlighter';
-import { mount, shallow } from 'enzyme';
import HighlightedSql from 'src/SqlLab/components/HighlightedSql';
-import ModalTrigger from 'src/components/ModalTrigger';
-import { supersetTheme, ThemeProvider } from '@superset-ui/core';
+import { fireEvent, render } from 'spec/helpers/testing-library';
Review Comment:
Thank you @justinpark for the improvements! We generally avoid `describe` and `it` in RTL tests. Could you also update those?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] captain-hoity-toity commented on a diff in pull request #25274: chore(sqllab): Migrate tests to typescript
Posted by "captain-hoity-toity (via GitHub)" <gi...@apache.org>.
captain-hoity-toity commented on code in PR #25274:
URL: https://github.com/apache/superset/pull/25274#discussion_r1324736702
##########
superset-frontend/src/SqlLab/components/HighlightedSql/HighlightedSql.test.tsx:
##########
@@ -0,0 +1,48 @@
+/**
Review Comment:
The code is generally well-written and follows good practices. However, there are a few minor improvements that could be made:
1. **Test Descriptions:** Make your test descriptions more descriptive to better understand what each test is doing. For example, instead of 'renders with props', you could say 'renders HighlightedSql component with sql prop'.
2. **Consistent Quotation Marks:** In the sql constant declaration, you are using double quotes for the SQL string. It would be better to stick to single quotes for consistency.
3. **Test Variable Names:** In your last test, the variable name 'syntaxHighlighter' is a bit misleading as it's actually a collection of 'code' elements, not 'SyntaxHighlighter' components. Consider renaming it to something like 'codeElements'.
Here's how the improved code could look:
```jsx
const sql = 'SELECT * FROM test WHERE something=\'fkldasjfklajdslfkjadlskfjkldasjfkladsjfkdjsa\'';
test('renders HighlightedSql component with sql prop', () => {
expect(React.isValidElement(<HighlightedSql sql={sql} />)).toBe(true);
});
test('renders a ModalTrigger component', () => {
const { getByTestId } = render(<HighlightedSql sql={sql} />);
expect(getByTestId('span-modal-trigger')).toBeInTheDocument();
});
test('renders a ModalTrigger component with shrink prop and maxWidth prop set to 20', () => {
const { getByTestId } = render(
<HighlightedSql sql={sql} shrink maxWidth={20} />,
);
expect(getByTestId('span-modal-trigger')).toBeInTheDocument();
});
test('renders two code elements in modal when rawSql prop is provided', () => {
const { getByRole, queryByRole, getByTestId } = render(
<HighlightedSql sql={sql} rawSql="SELECT * FORM foo" shrink maxWidth={5} />,
);
expect(queryByRole('dialog')).not.toBeInTheDocument();
fireEvent.click(getByTestId('span-modal-trigger'));
expect(queryByRole('dialog')).toBeInTheDocument();
const codeElements = getByRole('dialog').getElementsByTagName('code');
expect(codeElements.length).toEqual(2);
});
``
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] michael-s-molina commented on a diff in pull request #25274: chore(sqllab): Migrate tests to typescript
Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #25274:
URL: https://github.com/apache/superset/pull/25274#discussion_r1323469680
##########
superset-frontend/src/SqlLab/components/HighlightedSql/HighlightedSql.test.tsx:
##########
@@ -17,12 +17,9 @@
* under the License.
*/
import React from 'react';
-import SyntaxHighlighter from 'react-syntax-highlighter';
-import { mount, shallow } from 'enzyme';
import HighlightedSql from 'src/SqlLab/components/HighlightedSql';
-import ModalTrigger from 'src/components/ModalTrigger';
-import { supersetTheme, ThemeProvider } from '@superset-ui/core';
+import { fireEvent, render } from 'spec/helpers/testing-library';
Review Comment:
You can check our [Testing Guidelines and Best Practices](https://github.com/apache/superset/wiki/Testing-Guidelines-and-Best-Practices) to improve even more the tests 😉
##########
superset-frontend/src/SqlLab/components/HighlightedSql/HighlightedSql.test.tsx:
##########
@@ -17,12 +17,9 @@
* under the License.
*/
import React from 'react';
-import SyntaxHighlighter from 'react-syntax-highlighter';
-import { mount, shallow } from 'enzyme';
import HighlightedSql from 'src/SqlLab/components/HighlightedSql';
-import ModalTrigger from 'src/components/ModalTrigger';
-import { supersetTheme, ThemeProvider } from '@superset-ui/core';
+import { fireEvent, render } from 'spec/helpers/testing-library';
Review Comment:
You can check our [Testing Guidelines and Best Practices](https://github.com/apache/superset/wiki/Testing-Guidelines-and-Best-Practices) to improve even more the tests 😉
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] justinpark merged pull request #25274: chore(sqllab): Migrate tests to typescript
Posted by "justinpark (via GitHub)" <gi...@apache.org>.
justinpark merged PR #25274:
URL: https://github.com/apache/superset/pull/25274
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [superset] michael-s-molina commented on a diff in pull request #25274: chore(sqllab): Migrate tests to typescript
Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #25274:
URL: https://github.com/apache/superset/pull/25274#discussion_r1323468056
##########
superset-frontend/src/SqlLab/components/HighlightedSql/HighlightedSql.test.tsx:
##########
@@ -17,12 +17,9 @@
* under the License.
*/
import React from 'react';
-import SyntaxHighlighter from 'react-syntax-highlighter';
-import { mount, shallow } from 'enzyme';
import HighlightedSql from 'src/SqlLab/components/HighlightedSql';
-import ModalTrigger from 'src/components/ModalTrigger';
-import { supersetTheme, ThemeProvider } from '@superset-ui/core';
+import { fireEvent, render } from 'spec/helpers/testing-library';
Review Comment:
Thank you @justinpark for the improvements! We generally avoid `describe` and `it` in RTL tests. Could you remove them?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org