mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-10-27 05:27:16 +03:00
feat: more fixtures and mocks
This commit is contained in:
parent
2a7a84e655
commit
0f9e5043a2
@ -1,82 +1,157 @@
|
||||
import type { Project } from '$lib/backend/projects'
|
||||
import type { BaseBranch, RemoteCommit, Author } from '$lib/vbranches/types'
|
||||
import type { User } from '$lib/stores/user'
|
||||
import type { BaseBranch, RemoteCommit, Author, RemoteBranchData } from '$lib/vbranches/types'
|
||||
|
||||
export type Constructor<T = any> = new (...args: any[]) => T;
|
||||
export type Class<T = any> = InstanceType<Constructor<T>>;
|
||||
|
||||
export const project: Class<Project> = {
|
||||
id: "abc123",
|
||||
title: 'My Project',
|
||||
description: "A project description",
|
||||
path: "/Users/user/project",
|
||||
api: {
|
||||
name: 'github',
|
||||
description: 'description',
|
||||
repository_id: 'abc123',
|
||||
git_url: 'https://github.com/user/project',
|
||||
created_at: '2021-07-01T00:00:00Z',
|
||||
updated_at: '2021-07-01T00:01:00Z',
|
||||
sync: false
|
||||
},
|
||||
preferred_key: {
|
||||
local: { private_key_path: '/Users/.ssh/id_rsa' },
|
||||
},
|
||||
export const project = {
|
||||
api: null,
|
||||
description: null,
|
||||
gitbutler_code_push_state: null,
|
||||
gitbutler_data_last_fetch: null,
|
||||
id: "ac44a3bb-8bbb-4af9-b8c9-7950dd9ec295",
|
||||
ok_with_force_push: true,
|
||||
omit_certificate_check: true,
|
||||
use_diff_context: true,
|
||||
vscodePath: '/Users/user/project'
|
||||
omit_certificate_check: null,
|
||||
path: "/opt/ndomino/home2021",
|
||||
preferred_key: "systemExecutable",
|
||||
project_data_last_fetch: Object,
|
||||
fetched: {
|
||||
timestamp: {
|
||||
nanos_since_epoch: 410569736,
|
||||
secs_since_epoch: 1714924416
|
||||
}
|
||||
},
|
||||
title: "home2021"
|
||||
}
|
||||
|
||||
export const author: Class<Author> = {
|
||||
// export const author: Class<Author> = {
|
||||
export const author = {
|
||||
name: 'John Snow',
|
||||
email: 'user@company.com',
|
||||
gravatarUrl: new URL('https://gravatar.com/abc123'),
|
||||
isBot: false
|
||||
gravatarUrl: 'https://gravatar.com/abc123',
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
export const remoteCommit: Class<RemoteCommit> = {
|
||||
id: 'abc123',
|
||||
export const remoteCommit0 = {
|
||||
id: 'fe30876278739f7182effd27e9d9debde648b4de',
|
||||
author,
|
||||
description: 'A commit message',
|
||||
createdAt: new Date(),
|
||||
isLocal: false,
|
||||
description: 'fix: updated files',
|
||||
createdAt: 1714902366,
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
export const baseBranch: Class<BaseBranch> = {
|
||||
branchName: 'main',
|
||||
export const remoteCommit1 = {
|
||||
id: 'fe30876278739f7182effd27e9d9debde648b4dd',
|
||||
author,
|
||||
description: 'fix: updated files',
|
||||
createdAt: 1714902366,
|
||||
}
|
||||
|
||||
export const remoteBranch0 = {
|
||||
sha: '90c225edcc74b31718a9cd8963c1bc89c17d8863',
|
||||
name: '',
|
||||
upstream: '',
|
||||
lastCommitTimestampMs: 1714902366140,
|
||||
lastCommitAuthor: 'John Snow'
|
||||
}
|
||||
|
||||
export const baseBranch = {
|
||||
branchName: 'origin/gitbutler/integration',
|
||||
remoteName: 'origin',
|
||||
remoteUrl: 'ssh://github.com/user/project.git',
|
||||
baseSha: '90c225edcc74b31718a9cd8963c1bc89c17d8864',
|
||||
currentSha: '90c225edcc74b31718a9cd8963c1bc89c17d8864',
|
||||
behind: 0,
|
||||
upstreamCommits: [],
|
||||
recentCommits: [remoteCommit],
|
||||
recentCommits: [remoteCommit0],
|
||||
lastFetchedMs: 1714843209991,
|
||||
lastFetched: new Date(),
|
||||
repoBaseUrl: 'https://github.com/user/project',
|
||||
shortName: 'main',
|
||||
branchUrl: () => 'https://github.com/user/project',
|
||||
commitUrl: () => 'https://github.com/user/project',
|
||||
isGitlab: false,
|
||||
isBitBucket: false
|
||||
}
|
||||
|
||||
export const user: Class<User> = {
|
||||
id: 123,
|
||||
name: "John Snow",
|
||||
given_name: "John",
|
||||
family_name: "Snow",
|
||||
email: "user@comapny.com",
|
||||
picture: "",
|
||||
locale: "en_EN",
|
||||
created_at: "2021-07-01T00:00:00Z",
|
||||
updated_at: "2021-07-01T00:01:00Z",
|
||||
access_token: "abc123",
|
||||
role: "ADMIN",
|
||||
supporter: true,
|
||||
// export const user: Class<User> = {
|
||||
export const user = {
|
||||
access_token: "c5da8ec0-2a2e-4f1c-a796-686c5606e566",
|
||||
created_at: "2024-05-04T13:27:30Z",
|
||||
email: "yo@ndo.dev",
|
||||
family_name: undefined,
|
||||
github_access_token: undefined,
|
||||
github_username: undefined
|
||||
github_username: undefined,
|
||||
given_name: undefined,
|
||||
id: 31,
|
||||
locale: "en_US",
|
||||
name: "Nico",
|
||||
picture: "https://source.boringavatar.com/marble/120",
|
||||
role: undefined,
|
||||
updated_at: "2024-05-05T15:38:02Z",
|
||||
}
|
||||
|
||||
// export const remoteBranchData: Class<RemoteBranchData> = {
|
||||
export const remoteBranchData = {
|
||||
sha: '90c225edcc74b31718a9cd8963c1bc89c17d8864',
|
||||
name: 'test',
|
||||
upstream: 'abc123',
|
||||
authors: [author],
|
||||
displayName: 'test',
|
||||
lastCommitTs: new Date(),
|
||||
firstCommitAt: new Date(),
|
||||
ahead: 0,
|
||||
behind: 0,
|
||||
commits: [remoteCommit0],
|
||||
isMergeable: true,
|
||||
}
|
||||
|
||||
export const fileHunk = {
|
||||
binary: false,
|
||||
changeType: "modified",
|
||||
diff: `
|
||||
@@ -63,7 +63,7 @@
|
||||
"simple-git-hooks": "^2.11.1",
|
||||
"tailwindcss": "^3.4.3",
|
||||
"typescript": "^5.4.5",
|
||||
- "typescript-eslint": "^7.7.0"
|
||||
+ "typescript-eslint": "^7.8.0"
|
||||
},
|
||||
"commitlint": {
|
||||
"extends": [
|
||||
`,
|
||||
end: 70,
|
||||
filePath: "package.json",
|
||||
hash: "dc79c984a36b2f8a29007633bde4daf3",
|
||||
id: "63-70",
|
||||
locked: false,
|
||||
lockedTo: null,
|
||||
modifiedAt: 1714829527993,
|
||||
oldStart: 63,
|
||||
start: 63
|
||||
}
|
||||
|
||||
export const file0 = {
|
||||
binary: false,
|
||||
conflicted: false,
|
||||
hunks: [fileHunk],
|
||||
id: "package.json",
|
||||
large: false,
|
||||
modifiedAt: 1714829589111,
|
||||
path: "package.json",
|
||||
}
|
||||
|
||||
export const virtualBranch = {
|
||||
active: true,
|
||||
baseCurrent: true,
|
||||
commits: [],
|
||||
conflicted: false,
|
||||
files: [file0],
|
||||
head: "90c225edcc74b31718a9cd8963c1bc89c17d8864",
|
||||
id: "29cdc7a7-3462-4c14-a037-0a6cdad68da3",
|
||||
name: "Virtual branch",
|
||||
notes: "",
|
||||
order: 0,
|
||||
ownership: "package.json:63-70-dc79c984a36b2f8a29007633bde4daf3-1714829528116,23-58-fbf18cec4afef8aafbbc2dddef3e3391-1714829528116,79-85-c4d0a57fca736c384cde2a68009ffcb3-1714829503193",
|
||||
requiresForce: false,
|
||||
updatedAt: 1714829503190,
|
||||
upstream: null,
|
||||
upstreamName: null,
|
||||
}
|
||||
|
||||
export const virtualBranches = {
|
||||
branches: [virtualBranch],
|
||||
skippedFiles: []
|
||||
}
|
||||
|
@ -1,14 +1,11 @@
|
||||
import { baseBranch, project, remoteBranch0, remoteBranchData, user, virtualBranches } from "./fixtures"
|
||||
import { mockIPC } from "@tauri-apps/api/mocks";
|
||||
import { mockWindows } from '@tauri-apps/api/mocks';
|
||||
import { baseBranch, project, user } from "./fixtures"
|
||||
|
||||
export const mockTauri = () => {
|
||||
|
||||
// TODO: Set localSTorage like 'lastProject'
|
||||
export function mockTauri() {
|
||||
mockIPC((cmd, args) => {
|
||||
console.log("MOCKIPC.CMD", cmd, args)
|
||||
// console.log(JSON.stringify(args, null, 2))
|
||||
// console.groupEnd()
|
||||
|
||||
// Open Project Dialog
|
||||
if (cmd === "tauri" && args.__tauriModule === "Dialog" && args.message?.cmd === "openDialog") {
|
||||
return "/Users/user/project"
|
||||
@ -16,23 +13,21 @@ export const mockTauri = () => {
|
||||
|
||||
// List Projects
|
||||
if (cmd === "list_projects") {
|
||||
|
||||
console.log('mock.projects', [project])
|
||||
return [project]
|
||||
}
|
||||
|
||||
// List Project
|
||||
if (cmd === "get_project" && args.id === "abc123") {
|
||||
if (cmd === "get_project" && args.id === "ac44a3bb-8bbb-4af9-b8c9-7950dd9ec295") {
|
||||
return project
|
||||
}
|
||||
|
||||
// Get HEAD
|
||||
if (cmd === "git_head") {
|
||||
return "refs/heads/abc123"
|
||||
return "refs/heads/gitbutler/integration"
|
||||
}
|
||||
|
||||
if (cmd === "menu_item_set_enabled") {
|
||||
return true
|
||||
return null
|
||||
}
|
||||
|
||||
if (cmd === "fetch_from_target") {
|
||||
@ -44,6 +39,22 @@ export const mockTauri = () => {
|
||||
return baseBranch
|
||||
}
|
||||
|
||||
if (cmd === "list_virtual_branches") {
|
||||
return virtualBranches
|
||||
}
|
||||
|
||||
if (cmd === "list_remote_branches") {
|
||||
return []
|
||||
}
|
||||
|
||||
if (cmd === "get_remote_branch_data") {
|
||||
return remoteBranchData
|
||||
}
|
||||
|
||||
if (cmd === "get_remote_branchs") {
|
||||
return ["refs/heads/abc123"]
|
||||
}
|
||||
|
||||
if (cmd === "get_user") {
|
||||
return user
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user