diff --git a/src/app/models/MockElectronService.ts b/src/app/models/MockElectronService.ts index a889d58..0f1eeee 100644 --- a/src/app/models/MockElectronService.ts +++ b/src/app/models/MockElectronService.ts @@ -10,7 +10,11 @@ export class MockElectronService { return CHEMIN; } - pathJoin(...paths: string[]) { + pathJoin(...paths: string[]): string { return paths.join('').toString(); } + + fsExistsSync(pathToCheck: string): boolean { + return pathToCheck === 'path'; + } } diff --git a/src/app/models/MockGitService.ts b/src/app/models/MockGitService.ts index 2bb1975..efac7ce 100644 --- a/src/app/models/MockGitService.ts +++ b/src/app/models/MockGitService.ts @@ -56,4 +56,22 @@ export class MockGitService { }); } } + + async cloneHttps(url: GitUrlParse, folder: string, username: string, password: string) { + return new Promise((resolve, reject) => { + if (url && folder === 'path') { + if (username === 'username' && password === 'password') { + const REPOPATH = '/path'; + resolve(new ServiceResult(true, this.translate.instant('SUCCESS'), + this.translate.instant('CLONE.DONE'), REPOPATH)); + } else { + reject(new ServiceResult(false, this.translate.instant('ERROR'), + this.translate.instant('CLONE.ERROR'))); + } + } else { + reject(new ServiceResult(false, this.translate.instant('ERROR'), + this.translate.instant('CLONE.ERROR'))); + } + }); + } } diff --git a/src/app/providers/electron.service.ts b/src/app/providers/electron.service.ts index 7cd036c..91f38a7 100644 --- a/src/app/providers/electron.service.ts +++ b/src/app/providers/electron.service.ts @@ -55,7 +55,11 @@ export class ElectronService { return null; } - pathJoin(...paths: string[]) { + pathJoin(...paths: string[]): string { return this.path.join(...paths).toString(); } + + fsExistsSync(pathToCheck: fs.PathLike): boolean { + return this.fs.existsSync(pathToCheck); + } } diff --git a/src/app/screens/home/home.component.spec.ts b/src/app/screens/home/home.component.spec.ts index dcd1a20..b438fa7 100644 --- a/src/app/screens/home/home.component.spec.ts +++ b/src/app/screens/home/home.component.spec.ts @@ -353,4 +353,117 @@ describe('HomeComponent', () => { expect(component.path).toBeUndefined(); expect(component.repoName).toBeUndefined(); }); + + it('tests the cloneBrowse function', () => { + component.cloneBrowse(); + expect(component.cloneFolder).toBe('/new'); + }); + + it('tests the cloneSubmit function with https', () => { + const CloneFolder = 'path'; + const CloneUrl = 'https://github.com/GitHarpon/git-harpon'; + component.cloneFolder = CloneFolder; + component.cloneUrl = CloneUrl; + component.cloneSubmit(); + expect(component.projectModalVisible).toBeFalsy(); + expect(component.credInfoBarVisible).toBeTruthy(); + }); + + it('tests the cloneSubmit function with ssh', () => { + const CloneFolder = 'path'; + const CloneUrl = 'git@github.com:GitHarpon/git-harpon.git'; + component.cloneFolder = CloneFolder; + component.cloneUrl = CloneUrl; + component.cloneSubmit(); + }); + + it('tests the cloneSubmit function with invalid url', () => { + const CloneFolder = 'path'; + const CloneUrl = 'NotAnUrl'; + component.cloneFolder = CloneFolder; + component.cloneUrl = CloneUrl; + component.cloneSubmit(); + }); + + it('tests the cloneSubmit function with invalid folder', () => { + const CloneFolder = 'invalid'; + const CloneUrl = 'https://github.com/GitHarpon/git-harpon'; + component.cloneFolder = CloneFolder; + component.cloneUrl = CloneUrl; + component.cloneSubmit(); + }); + + it('tests the cloneHttps function with valid arguments', (done) => { + const CloneUrl = 'https://github.com/GitHarpon/git-harpon'; + const CloneFolder = 'path'; + const Username = 'username'; + const Password = 'password'; + component.cloneUrl = CloneUrl; + component.cloneFolder = CloneFolder; + component.username = Username; + component.password = Password; + component.openClonedInfoBarVisible = false; + component.cloneHttps().then(() => { + expect(component.homeLoading).toBeFalsy(); + expect(component.openClonedInfoBarVisible).toBeTruthy(); + done(); + }); + }); + + it('tests the cloneHttps function with invalid url or folder', (done) => { + const CloneUrl = 'invalidurl'; + const CloneFolder = 'invalidfolder'; + const Username = 'username'; + const Password = 'password'; + component.cloneUrl = CloneUrl; + component.cloneFolder = CloneFolder; + component.username = Username; + component.password = Password; + component.cloneHttps().then(() => { + expect(component.homeLoading).toBeFalsy(); + done(); + }); + }); + + it('tests the cloneHttps function with invalid username or password', (done) => { + const CloneUrl = 'https://github.com/GitHarpon/git-harpon'; + const CloneFolder = 'path'; + const Username = 'badusername'; + const Password = 'badpassword'; + component.cloneUrl = CloneUrl; + component.cloneFolder = CloneFolder; + component.username = Username; + component.password = Password; + component.cloneHttps().then(() => { + expect(component.homeLoading).toBeFalsy(); + done(); + }); + }); + + it('tests the closeCredInfoBar function', () => { + component.closeCredInfoBar(); + expect(component.credInfoBarVisible).toBeFalsy(); + }); + + it('tests the openClonedRepo function', () => { + const NewRepo = '/new'; + component.newClonedRepoPath = NewRepo; + component.openClonedRepo(); + expect(component.path).toBe(NewRepo); + expect(component.openClonedInfoBarVisible).toBeFalsy(); + }); + + it('tests the closeClonedInfoBar function', () => { + component.closeClonedInfoBar(); + expect(component.openClonedInfoBarVisible).toBeFalsy(); + }); + + it('tests the resetCloneInputs function', () => { + component.resetCloneInputs(); + expect(component.username).toBe(''); + expect(component.password).toBe(''); + expect(component.cloneUrl).toBe(''); + expect(component.cloneFolder).toBe(''); + expect(component.newClonedRepoPath).toBe(''); + }); }); diff --git a/src/app/screens/home/home.component.ts b/src/app/screens/home/home.component.ts index 0b6d86c..16847b1 100644 --- a/src/app/screens/home/home.component.ts +++ b/src/app/screens/home/home.component.ts @@ -141,7 +141,7 @@ export class HomeComponent implements OnDestroy { } cloneSubmit() { - if (this.electronService.fs.existsSync(this.cloneFolder.toString())) { + if (this.electronService.fsExistsSync(this.cloneFolder.toString())) { var Url = GitUrlParse(this.cloneUrl); if (Url.protocol === 'https') { this.projectModalVisible = false; @@ -161,7 +161,7 @@ export class HomeComponent implements OnDestroy { cloneHttps() { this.credInfoBarVisible = false; this.homeLoading = true; - this.gitService.cloneHttps(GitUrlParse(this.cloneUrl), this.cloneFolder, this.username, this.password) + return this.gitService.cloneHttps(GitUrlParse(this.cloneUrl), this.cloneFolder, this.username, this.password) .then((data) => { this.homeLoading = false; this.openClonedInfoBarVisible = true;