Skip to content

Commit d9881a5

Browse files
authored
Merge pull request #443 from dolthub/liuliu/cypress-add-connection-form
Liuliu/Cypress: add connection form test
2 parents 1df60c1 + c677779 commit d9881a5

File tree

16 files changed

+273
-36
lines changed

16 files changed

+273
-36
lines changed

.github/workflows/tests_cypress.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ jobs:
3636
working-directory: ./workbench-cypress
3737
run: |
3838
yarn
39-
39+
4040
- name: Run tests
4141
working-directory: ./workbench-cypress
42+
env:
43+
CYPRESS_WORKBENCH_CONNECTION_URL: ${{ secrets.WORKBENCH_CONNECTION_URL}}
4244
run: |
4345
# Start servers and store PIDs
4446
echo "Starting servers..."
@@ -49,6 +51,7 @@ jobs:
4951
# Run Cypress
5052
cd ../workbench-cypress
5153
yarn cy-chrome
54+
5255

5356
- name: Save screenshots of failed tests
5457
uses: actions/upload-artifact@v4

web/renderer/components/pageComponents/ConnectionsPage/ExistingConnections/Item.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ export default function Item({
5151

5252
return (
5353
<>
54-
<li key={conn.name} className={css.connectionContainer}>
54+
<li
55+
key={conn.name}
56+
className={css.connectionContainer}
57+
data-cy={`connection-${conn.name}`}
58+
>
5559
<div
5660
className={cx(css.line, css[borderClassName], {
5761
[css.shorterLine]: shorterLine,
@@ -70,6 +74,7 @@ export default function Item({
7074
<Button.Link
7175
onClick={() => onDeleteClicked(conn.name)}
7276
className={css.delete}
77+
data-cy={`delete-${conn.name}-button`}
7378
>
7479
<IoMdClose />
7580
</Button.Link>

web/renderer/components/pageComponents/ConnectionsPage/ExistingConnections/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,15 @@ export default function ExistingConnections(props: Props) {
6767
<div className={css.leftLine} />
6868
</div>
6969
</div>
70-
<Button className={css.newConnection} onClick={onClick}>
70+
<Button
71+
className={css.newConnection}
72+
onClick={onClick}
73+
data-cy="add-connection-button"
74+
>
7175
Add Connection
7276
</Button>
7377
<div className={css.rightLine} />
74-
<ul>
78+
<ul data-cy="connections-list">
7579
{props.connections.map((conn, i) => (
7680
<Item
7781
conn={conn}
@@ -104,6 +108,7 @@ export default function ExistingConnections(props: Props) {
104108
? "This action will permanently delete the local Dolt server and all associated data stored within it. This cannot be undone."
105109
: undefined
106110
}
111+
buttonDataCy="delete-connection-confirm-button"
107112
/>
108113
</div>
109114
);

web/renderer/components/pageComponents/ConnectionsPage/NewConnection/About.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
FormSelect,
77
useTabsContext,
88
} from "@dolthub/react-components";
9-
import { useState } from "react";
9+
import { SyntheticEvent, useState } from "react";
1010
import { DatabaseType } from "@gen/graphql-types";
1111
import CloneForm from "@components/CloneDatabaseForm/CloneForm";
1212
import { useConfigContext } from "./context/config";
@@ -22,12 +22,13 @@ export default function About() {
2222
const [startDoltServer, setStartDoltServer] = useState(false);
2323
const [cloneDolt, setCloneDolt] = useState(false);
2424

25-
const onNext = () => {
25+
const onNext = (e: SyntheticEvent) => {
26+
e.preventDefault();
2627
setActiveTabIndex(activeTabIndex + 1);
2728
};
2829

2930
return (
30-
<form onSubmit={onNext} className={css.form}>
31+
<form onSubmit={onNext} className={css.form} data-cy="connection-tab-form">
3132
{forElectron && (
3233
<>
3334
<Checkbox
@@ -111,6 +112,7 @@ export default function About() {
111112
labelClassName={css.label}
112113
placeholder="my-database (required)"
113114
light
115+
data-cy="connection-name-input"
114116
/>
115117
<FormSelect
116118
outerClassName={css.typeSelect}
@@ -136,9 +138,15 @@ export default function About() {
136138
]}
137139
hideSelectedOptions
138140
light
141+
data-cy="connection-type-selector"
139142
/>
140143
<ButtonsWithError error={error}>
141-
<Button type="submit" disabled={!state.name} className={css.button}>
144+
<Button
145+
type="submit"
146+
disabled={!state.name}
147+
className={css.button}
148+
data-cy="next-about"
149+
>
142150
Next
143151
</Button>
144152
</ButtonsWithError>

web/renderer/components/pageComponents/ConnectionsPage/NewConnection/Advanced.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function Advanced() {
1414
const { canSubmit, message } = getCanSubmit(state);
1515

1616
return (
17-
<form onSubmit={onSubmit} className={css.form}>
17+
<form onSubmit={onSubmit} className={css.form} data-cy="advanced-tab-form">
1818
<Checkbox
1919
checked={state.useSSL}
2020
onChange={() => setState({ useSSL: !state.useSSL })}
@@ -39,6 +39,7 @@ export default function Advanced() {
3939
data-tooltip-id="submit-message"
4040
data-tooltip-content={message}
4141
data-tooltip-hidden={canSubmit}
42+
data-cy="launch-workbench-button"
4243
>
4344
Launch Workbench
4445
</Button>

web/renderer/components/pageComponents/ConnectionsPage/NewConnection/Connection.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function Connection() {
1414
};
1515

1616
return (
17-
<form onSubmit={onNext} className={css.form}>
17+
<form onSubmit={onNext} className={css.form} data-cy="connection-tab-form">
1818
<FormInput
1919
value={state.connectionUrl}
2020
onChangeString={c => setState({ connectionUrl: c })}
@@ -25,6 +25,7 @@ export default function Connection() {
2525
horizontal
2626
light
2727
labelClassName={css.label}
28+
data-cy="connection-url-input"
2829
/>
2930
<div className={css.or}>OR</div>
3031
<FormInput
@@ -35,6 +36,7 @@ export default function Connection() {
3536
horizontal
3637
light
3738
labelClassName={css.label}
39+
data-cy="connection-host-input"
3840
/>
3941
<FormInput
4042
label="Port"
@@ -44,6 +46,7 @@ export default function Connection() {
4446
horizontal
4547
light
4648
labelClassName={css.label}
49+
data-cy="connection-port-input"
4750
/>
4851
<FormInput
4952
label="User"
@@ -53,6 +56,7 @@ export default function Connection() {
5356
horizontal
5457
light
5558
labelClassName={css.label}
59+
data-cy="connection-user-input"
5660
/>
5761
<FormInput
5862
label="Password"
@@ -63,6 +67,7 @@ export default function Connection() {
6367
horizontal
6468
light
6569
labelClassName={css.label}
70+
data-cy="connection-password-input"
6671
/>
6772
<FormInput
6873
label="Database"
@@ -72,11 +77,13 @@ export default function Connection() {
7277
horizontal
7378
light
7479
labelClassName={css.label}
80+
data-cy="connection-database-input"
7581
/>
7682
<Button
7783
type="submit"
7884
disabled={!state.connectionUrl && (!state.host || !state.port)}
7985
className={css.button}
86+
data-cy="next-connection"
8087
>
8188
Next
8289
</Button>

web/renderer/components/pageComponents/ConnectionsPage/NewConnection/ConnectionTabs.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ export default function ConnectionTabs() {
2424
<TabList className={css.tabList}>
2525
{state.isLocalDolt
2626
? [
27-
<CustomTab key="About" index={0}>
27+
<CustomTab key="About" index={0} data-cy="connection-tabs-about">
2828
About
2929
</CustomTab>,
3030
]
3131
: ["About", "Connection", "Advanced"].map((tab, i) => (
32-
<CustomTab key={tab} index={i}>
32+
<CustomTab
33+
key={tab}
34+
index={i}
35+
data-cy={`connection-tabs-${tab.toLowerCase()}`}
36+
>
3337
{tab}
3438
</CustomTab>
3539
))}
@@ -60,7 +64,11 @@ function CustomTabPanel(props: PanelProps) {
6064
);
6165
}
6266

63-
function CustomTab(props: { index: number; children: string }) {
67+
function CustomTab(props: {
68+
index: number;
69+
children: string;
70+
["data-cy"]?: string;
71+
}) {
6472
const { activeTabIndex } = useTabsContext();
6573
const isActive = props.index === activeTabIndex;
6674
const { state } = useConfigContext();
@@ -76,7 +84,7 @@ function CustomTab(props: { index: number; children: string }) {
7684
disabled={getDisabled(props.children, state)}
7785
>
7886
{isCompleted && <FiCheck className={css.check} />}
79-
<span>{props.children}</span>
87+
<span data-cy={props["data-cy"]}>{props.children}</span>
8088
</Tab>
8189
);
8290
}

web/renderer/components/pageComponents/ConnectionsPage/NewConnection/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type InnerProps = {
1616

1717
function Inner({ showWelcomeMsg }: InnerProps) {
1818
return (
19-
<div className={css.databaseForm}>
19+
<div className={css.databaseForm} data-cy="add-connection-form">
2020
{showWelcomeMsg && <WelcomeMessage />}
2121
<div className={css.whiteContainer}>
2222
<div className={css.top}>

web/renderer/components/pageComponents/DatabasesPage/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ export default function DatabasesPage() {
3434
Choose an existing database or create a new database to get started.
3535
</p>
3636
{res.data?.databases.length ? (
37-
<ul className={css.dbList}>
37+
<ul className={css.dbList} data-cy="databases-list">
3838
{res.data.databases.map(db => (
39-
<li key={db}>
39+
<li key={db} data-cy={`database-${db}-button`}>
4040
<Link {...database({ databaseName: db })}>
4141
<div className={css.database}>
4242
<FaDatabase />
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {
2+
shouldFindAndContain,
3+
shouldFindButton,
4+
} from "@sharedTests/sharedFunctionsAndVariables";
5+
import { newExpectation, newShouldArgs } from "@utils/helpers";
6+
import { runTests } from "@utils/index";
7+
8+
const pageName = "Homepage";
9+
const currentPage = "/";
10+
11+
describe(pageName, () => {
12+
const tests = [
13+
shouldFindAndContain("connections-title", "Connections"),
14+
shouldFindAndContain(
15+
"welcome-message",
16+
"Connect the workbench to any MySQL or PostgreSQL compatible database. ",
17+
),
18+
shouldFindButton("add-connection-button"),
19+
newExpectation(
20+
"should find connections list with at least 1 connection",
21+
"[data-cy=connections-list] > li",
22+
newShouldArgs("be.visible.and.have.length.of.at.least", 1),
23+
),
24+
shouldFindAndContain(
25+
"connection-CypressTestConnection",
26+
"CypressTestConnection",
27+
),
28+
];
29+
runTests({ tests, currentPage, pageName });
30+
});

0 commit comments

Comments
 (0)