Skip to content

Commit

Permalink
Merge pull request #86 from GitHarpon/tu-clone
Browse files Browse the repository at this point in the history
test(tu-clone): ajout des TU pour clone
  • Loading branch information
Nemtecl authored Feb 26, 2019
2 parents cc47952 + 689dda4 commit 31059c9
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/app/models/MockElectronService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
18 changes: 18 additions & 0 deletions src/app/models/MockGitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,22 @@ export class MockGitService {
});
}
}

async cloneHttps(url: GitUrlParse, folder: string, username: string, password: string) {
return new Promise<ServiceResult>((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')));
}
});
}
}
6 changes: 5 additions & 1 deletion src/app/providers/electron.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
113 changes: 113 additions & 0 deletions src/app/screens/home/home.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
});
});
4 changes: 2 additions & 2 deletions src/app/screens/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 31059c9

Please sign in to comment.