Skip to content

Commit bfa76ff

Browse files
Merge pull request #572 from dolthub/eric/more-cypress-tests
Add tests for diff viewer and create branch page
2 parents 75db17d + e9f95bf commit bfa76ff

File tree

7 files changed

+113
-3
lines changed

7 files changed

+113
-3
lines changed

web/renderer/components/DiffSelector/ForBranchCommitAndTag.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default function ForBranchCommitAndTag({ params }: Props) {
2929
params={params}
3030
selectedValue={toRef}
3131
onChangeValue={s => setToRef(s || "")}
32+
dataCy="to-ref-selector"
3233
/>
3334
</div>
3435
<div className={css.arrow}>
@@ -39,6 +40,7 @@ export default function ForBranchCommitAndTag({ params }: Props) {
3940
params={params}
4041
selectedValue={fromRef}
4142
onChangeValue={s => setFromRef(s || "")}
43+
dataCy="from-ref-selector"
4244
/>
4345
</div>
4446
</div>
@@ -52,7 +54,11 @@ export default function ForBranchCommitAndTag({ params }: Props) {
5254
})}
5355
className={css.viewDiffButton}
5456
>
55-
<Button disabled={fromRef === toRef} className={css.button}>
57+
<Button
58+
disabled={fromRef === toRef}
59+
className={css.button}
60+
data-cy="view-diff-button"
61+
>
5662
View Diff
5763
</Button>
5864
</Link>

web/renderer/components/FormSelectForRefs/BranchAndCommitSelector.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export default function BranchAndCommitSelector(props: Props) {
4848
placeholder="select a branch or commit..."
4949
className={css.branchAndCommitSelect}
5050
selectedOptionFirst
51+
data-cy="branch-and-commit-selector"
5152
/>
5253
);
5354
}

web/renderer/components/FormSelectForRefs/BranchCommitAndTagSelector.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type Props = {
1111
params: OptionalRefParams;
1212
selectedValue: Maybe<string>;
1313
onChangeValue: (s: Maybe<string>) => void;
14+
dataCy: string;
1415
};
1516

1617
export default function BranchCommitAndTagSelector(props: Props) {
@@ -53,6 +54,7 @@ export default function BranchCommitAndTagSelector(props: Props) {
5354
className={css.branchAndCommitSelect}
5455
selectedOptionFirst
5556
light
57+
data-cy={props.dataCy}
5658
/>
5759
);
5860
}

web/renderer/components/pageComponents/DatabasePage/ForBranches/BranchesPage/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function Inner(props: InnerProps): JSX.Element {
7979
)}
8080
<HideForNoWritesWrapper params={props.params}>
8181
<Link {...createUrl} className={css.white}>
82-
<Button>Create Branch</Button>
82+
<Button data-cy="create-branch-page-button">Create Branch</Button>
8383
</Link>
8484
</HideForNoWritesWrapper>
8585
</div>

web/renderer/components/pageComponents/DatabasePage/ForBranches/NewBranchPage/NewBranchForm/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,19 @@ export default function NewBranchForm(props: Props): JSX.Element {
6969
label="New branch name"
7070
placeholder="i.e. feature-branch"
7171
className={css.input}
72+
data-cy="new-branch-name-input"
7273
/>
7374
<ButtonsWithError
7475
onCancel={goToBranchesPage}
7576
left
7677
stackedButton={isMobile}
7778
error={err}
7879
>
79-
<Button type="submit" disabled={!newBranchName || !fromRefName}>
80+
<Button
81+
type="submit"
82+
disabled={!newBranchName || !fromRefName}
83+
data-cy="create-branch-button"
84+
>
8085
Create branch
8186
</Button>
8287
</ButtonsWithError>

workbench-cypress/cypress/e2e/branches/index.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ import {
66
newExpectationWithClickFlows,
77
} from "@utils/helpers";
88
import {
9+
beDisabled,
910
beVisible,
11+
beVisibleAndContain,
12+
shouldBeVisible,
1013
shouldFindAndContain,
14+
shouldFindButton,
15+
shouldTypeString,
1116
} from "@sharedTests/sharedFunctionsAndVariables";
1217
import { Expectation } from "@utils/types";
1318

@@ -17,6 +22,38 @@ const currentPage = `/database/${dbName}/branches`;
1722
const connectionName = "CypressTestConnection";
1823
const hasDocs = true;
1924

25+
const createBranchTest = (fromBranch: string) =>
26+
newExpectationWithClickFlows(
27+
"should go to create branch page",
28+
formatDataCy("create-branch-page-button"),
29+
beVisibleAndContain("Create Branch"),
30+
[
31+
newClickFlow(
32+
formatDataCy("create-branch-page-button"),
33+
[
34+
newExpectationWithClickFlows(
35+
"should fill out create branch form",
36+
formatDataCy("create-branch-button"),
37+
beDisabled,
38+
[
39+
newClickFlow(formatDataCy("branch-and-commit-selector"), [
40+
shouldFindAndContain(`select-option-${fromBranch}`, fromBranch),
41+
]),
42+
newClickFlow(formatDataCy(`select-option-${fromBranch}`), [
43+
shouldBeVisible(`single-value-${fromBranch}`),
44+
]),
45+
newClickFlow(formatDataCy("new-branch-name-input"), [
46+
shouldTypeString("new-branch-name-input", "test-new-branch"),
47+
shouldFindButton("create-branch-button"),
48+
]),
49+
],
50+
),
51+
],
52+
formatDataCy("cancel-button"),
53+
),
54+
],
55+
);
56+
2057
const showDeleteBranchPopUpTest = (branchToClick: string): Expectation =>
2158
newExpectationWithClickFlows(
2259
"should show delete branch popup",
@@ -34,6 +71,7 @@ const showDeleteBranchPopUpTest = (branchToClick: string): Expectation =>
3471
describe(pageName, () => {
3572
const tests = [
3673
...testDBHeader(connectionName, dbName, hasDocs),
74+
createBranchTest("main"),
3775
showDeleteBranchPopUpTest("add-view"),
3876
];
3977

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { runTests } from "@utils/index";
2+
import { testDBHeader } from "@sharedTests/dbHeaders";
3+
import { Expectation } from "@utils/types";
4+
import {
5+
formatDataCy,
6+
newClickFlow,
7+
newExpectationWithClickFlows,
8+
} from "@utils/helpers";
9+
import {
10+
beVisible,
11+
shouldFindAndContain,
12+
shouldNotExist,
13+
} from "@sharedTests/sharedFunctionsAndVariables";
14+
15+
const pageName = "Branch diff page";
16+
const dbName = "us-jails";
17+
const currentPage = `/database/${dbName}/compare`;
18+
const connectionName = "CypressTestConnection";
19+
const hasDocs = true;
20+
21+
const diffTest = (
22+
toRef: string,
23+
fromRef: string,
24+
expectedDiffStat: string,
25+
): Expectation =>
26+
newExpectationWithClickFlows(
27+
"should show diff between two refs",
28+
formatDataCy("diff-selector"),
29+
beVisible,
30+
[
31+
newClickFlow(formatDataCy("to-ref-selector"), [
32+
shouldFindAndContain(`select-option-${toRef}`, toRef),
33+
]),
34+
newClickFlow(formatDataCy(`select-option-${toRef}`), [
35+
shouldNotExist(`select-option-${toRef}`),
36+
]),
37+
newClickFlow(formatDataCy("from-ref-selector"), [
38+
shouldFindAndContain(`select-option-${fromRef}`, fromRef),
39+
]),
40+
newClickFlow(formatDataCy(`select-option-${fromRef}`), [
41+
shouldNotExist(`select-option-${fromRef}`),
42+
]),
43+
newClickFlow(formatDataCy("view-diff-button"), [
44+
shouldFindAndContain("diff-table-stats", expectedDiffStat),
45+
]),
46+
],
47+
);
48+
49+
const branchDiffTest = diffTest("main", "add-view", "1 Row Deleted");
50+
51+
describe(pageName, () => {
52+
const tests = [
53+
...testDBHeader(connectionName, dbName, hasDocs),
54+
branchDiffTest,
55+
];
56+
57+
runTests({ tests, currentPage, pageName });
58+
});

0 commit comments

Comments
 (0)