-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
363 additions
and
251 deletions.
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
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
7 changes: 7 additions & 0 deletions
7
web/components/DiffTable/DataDiff/ViewSqlLink/index.module.css
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,7 @@ | ||
.sqlIcon { | ||
@apply text-lg font-normal; | ||
} | ||
|
||
.sqlLink { | ||
@apply font-thin text-primary hover:text-primary; | ||
} |
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
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,75 @@ | ||
import { ColumnForDataTableFragment, CommitDiffType } from "@gen/graphql-types"; | ||
import { fakeCommitId } from "@hooks/useCommitListForBranch/mocks"; | ||
import { RequiredRefsParams, TableParams } from "@lib/params"; | ||
import { sprintf } from "@lib/sprintf"; | ||
import { Props } from "./useGetDoltCommitDiffQuery"; | ||
|
||
type Params = RequiredRefsParams & { tableName: string; refName: string }; | ||
|
||
const tableParams: TableParams = { | ||
databaseName: "dbname", | ||
refName: "master", | ||
tableName: "test-table", | ||
}; | ||
|
||
export const params: Params = { | ||
...tableParams, | ||
fromRefName: fakeCommitId(), | ||
toRefName: fakeCommitId(), | ||
}; | ||
|
||
export const tableCols: ColumnForDataTableFragment[] = [ | ||
{ | ||
__typename: "Column", | ||
name: "id", | ||
isPrimaryKey: true, | ||
type: "INT", | ||
}, | ||
{ | ||
__typename: "Column", | ||
name: "name", | ||
isPrimaryKey: false, | ||
type: "VARCHAR(16383)", | ||
}, | ||
]; | ||
|
||
export const noDiffTagsOrRemovedColsProps: Props = { | ||
params, | ||
columns: tableCols, | ||
hiddenColIndexes: [], | ||
}; | ||
|
||
export const noDiffTagsOrRemovedColsExpected = sprintf( | ||
"SELECT `diff_type`, `from_id`, `to_id`, `from_name`, `to_name`, `from_commit`, `from_commit_date`, `to_commit`, `to_commit_date` FROM `dolt_commit_diff_$` WHERE `from_commit` = '$' AND `to_commit` = '$'", | ||
params.tableName, | ||
params.fromRefName, | ||
params.toRefName, | ||
); | ||
|
||
export const noDiffTagsAndRemovedColsProps: Props = { | ||
params, | ||
columns: tableCols, | ||
hiddenColIndexes: [1], | ||
}; | ||
|
||
export const noDiffTagsAndRemovedColsExpected = sprintf( | ||
"SELECT `diff_type`, `from_id`, `to_id`, `from_commit`, `from_commit_date`, `to_commit`, `to_commit_date` FROM `dolt_commit_diff_$` WHERE `from_commit` = '$' AND `to_commit` = '$'", | ||
params.tableName, | ||
params.fromRefName, | ||
params.toRefName, | ||
); | ||
|
||
export const noDiffTagsAndRemovedColsForPullProps: Props = { | ||
params, | ||
columns: tableCols, | ||
hiddenColIndexes: [1], | ||
type: CommitDiffType.ThreeDot, | ||
}; | ||
|
||
export const noDiffTagsAndRemovedColsForPullExpected = sprintf( | ||
"SELECT `diff_type`, `from_id`, `to_id`, `from_commit`, `from_commit_date`, `to_commit`, `to_commit_date` FROM `dolt_commit_diff_$` WHERE `from_commit` = DOLT_MERGE_BASE('$', '$') AND `to_commit` = HASHOF('$')", | ||
params.tableName, | ||
params.toRefName, | ||
params.fromRefName, | ||
params.fromRefName, | ||
); |
56 changes: 56 additions & 0 deletions
56
web/components/DiffTable/DataDiff/ViewSqlLink/useGetDoltCommitDiffQuery.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,56 @@ | ||
import { MockedProvider } from "@apollo/client/testing"; | ||
import { databaseDetailsMock } from "@components/util/NotDoltWrapper/mocks"; | ||
import { renderHook } from "@testing-library/react"; | ||
import { ReactNode } from "react"; | ||
import { | ||
noDiffTagsAndRemovedColsExpected, | ||
noDiffTagsAndRemovedColsForPullExpected, | ||
noDiffTagsAndRemovedColsForPullProps, | ||
noDiffTagsAndRemovedColsProps, | ||
noDiffTagsOrRemovedColsExpected, | ||
noDiffTagsOrRemovedColsProps, | ||
} from "./testData"; | ||
import { Props, useGetDoltCommitDiffQuery } from "./useGetDoltCommitDiffQuery"; | ||
|
||
function renderUseGetDoltCommitDiffQuery( | ||
props: Props, | ||
isPostgres = false, | ||
): () => string { | ||
const wrapper = ({ children }: { children: ReactNode }) => ( | ||
<MockedProvider mocks={[databaseDetailsMock(true, true, isPostgres)]}> | ||
{children} | ||
</MockedProvider> | ||
); | ||
|
||
const { result } = renderHook(() => useGetDoltCommitDiffQuery(props), { | ||
wrapper, | ||
}); | ||
return result.current; | ||
} | ||
|
||
const tests: Array<{ desc: string; props: Props; expected: string }> = [ | ||
{ | ||
desc: "no diff tags or removed columns", | ||
props: noDiffTagsOrRemovedColsProps, | ||
expected: noDiffTagsOrRemovedColsExpected, | ||
}, | ||
{ | ||
desc: "no diff tags and removed columns", | ||
props: noDiffTagsAndRemovedColsProps, | ||
expected: noDiffTagsAndRemovedColsExpected, | ||
}, | ||
{ | ||
desc: "no diff tags and removed columns for pull", | ||
props: noDiffTagsAndRemovedColsForPullProps, | ||
expected: noDiffTagsAndRemovedColsForPullExpected, | ||
}, | ||
]; | ||
|
||
describe("test getDoltCommitDiffQuery for diff tables", () => { | ||
tests.forEach(({ desc, props, expected }) => { | ||
it(`[mysql] generates dolt_commit_diff query for ${desc}`, () => { | ||
const generateQuery = renderUseGetDoltCommitDiffQuery(props); | ||
expect(generateQuery()).toBe(expected); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.