-
Notifications
You must be signed in to change notification settings - Fork 111
Add tests and refactor #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
MichaelCurrin
wants to merge
6
commits into
master
Choose a base branch
from
add-tests-and-refactor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cc9bd5b
chore: Create package
MichaelCurrin 1ae17df
test: Create repo and license tests
MichaelCurrin 2470c34
feat: And license.js and repo.js
MichaelCurrin 919666a
test: Move files
MichaelCurrin ccb5200
chore: Move to components
MichaelCurrin ce738b0
test: Create and update tests
MichaelCurrin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
node_modules/ |
This file contains hidden or 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,21 @@ | ||
{ | ||
"name": "badge-generator", | ||
"description": "Online tool to help you quickly generate tailor-made badges/shields for your repo docs and learn to work with badges", | ||
"main": "main.js", | ||
"scripts": { | ||
"test": "jest" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/MichaelCurrin/badge-generator.git" | ||
}, | ||
"author": "Michael Currin", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/MichaelCurrin/badge-generator/issues" | ||
}, | ||
"homepage": "https://github.com/MichaelCurrin/badge-generator#readme", | ||
"devDependencies": { | ||
"jest": "^26.0.1" | ||
} | ||
} |
Empty file.
This file contains hidden or 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,34 @@ | ||
const { License } = require('../components/license.js') | ||
|
||
test('MIT license badge title displays correctly', () => { | ||
var license = new License('MIT') | ||
|
||
expect(license.title()).toBe('License: MIT') | ||
}) | ||
|
||
test('MIT license badge image is correct', () => { | ||
var license = new License('MIT') | ||
|
||
expect(license.img()).toBe('https://img.shields.io/badge/License-MIT-blue') | ||
}) | ||
|
||
test('MIT license badge relative target is correct', () => { | ||
var license = new License('MIT') | ||
|
||
expect(license.REL_TARGET).toBe('#license') | ||
}) | ||
|
||
test('MIT license full badge with relative target displays correctly', () => { | ||
var license = new License('MIT') | ||
|
||
var badge = '[](#license)'; | ||
expect(license.markdown()).toBe(badge) | ||
}) | ||
|
||
test('MIT license full badge with FQDN target displays correctly', () => { | ||
var target = 'https://github.com/my-user/my-repo-name/blob/master/LICENSE'; | ||
var license = new License('MIT', target) | ||
|
||
var badge = '[](https://github.com/my-user/my-repo-name/blob/master/LICENSE)'; | ||
expect(license.markdown()).toBe(badge) | ||
}) |
This file contains hidden or 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,6 @@ | ||
test('Made with Bash badge is correct', () => { | ||
var badge = new MadeWith('Bash') | ||
|
||
// Use mix of shield and markdown links internally. And preset target. | ||
var result = '[](https://www.gnu.org/software/bash/)' | ||
}) |
This file contains hidden or 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,36 @@ | ||
const { MarkdownLink } = require('../components/markdownLink.js') | ||
|
||
test('An ID markdown link formats correctly', () => { | ||
var tag = MarkdownLink('My link', '#target') | ||
expect(tag.md()).toBe('[My link](#target)') | ||
}) | ||
|
||
test('An absolute markdown link formats correctly', () => { | ||
var tag = MarkdownLink('Absolute link', '/foo/bar.md') | ||
expect(tag.md()).toBe('[Absolute link](/foo/bar.md)') | ||
}) | ||
|
||
test('A markdown URL link formats correctly', () => { | ||
var tag = MarkdownLink('Example link', 'https://example.com') | ||
expect(tag.md()).toBe('[Example link](https://example.com)') | ||
}) | ||
|
||
test('A markdown image tag formats correctly', () => { | ||
var tag = MarkdownLink('Example image', 'https://example.com/image.png') | ||
expect(tag.image()).toBe('') | ||
}) | ||
|
||
test('A markdown image tag with target URL formats correctly', () => { | ||
var tag = MarkdownLink('Example image', 'https://example.com/image.png', 'https://foo.bar.com') | ||
expect(tag.image()).toBe('[](https://foo.bar.com)') | ||
}) | ||
|
||
test('An ID markdown link with alt text formats correctly', () => { | ||
var tag = MarkdownLink('My link', '#target') | ||
expect(tag.md("My alt test for hover")).toBe('[My link](#target "My alt test for hover")') | ||
}) | ||
|
||
test('A markdown image tag with alt text and target URL formats correctly', () => { | ||
var tag = MarkdownLink('Example image', 'https://example.com/image.png', 'https://foo.bar.com') | ||
expect(tag.image("My alt test for hover")).toBe('[](https://foo.bar.com)') | ||
}) |
This file contains hidden or 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,78 @@ | ||
const { parseRepoUrl, Repo } = require('../components/repo.js') | ||
|
||
test("A repo URL can be split correctly", () => { | ||
var url = 'https://github.com/my-username/my-repo-name' | ||
|
||
expect(parseRepoUrl(url)).toBe({ | ||
username: 'my-username', | ||
repoName: 'my-repo-name' | ||
}) | ||
}) | ||
|
||
test("Create a repo instance", () => { | ||
var repo = new Repo('my-username', 'my-repo-name') | ||
|
||
expect(repo.username).toBe('my-username') | ||
expect(repo.repoName).toBe('my-repo-name') | ||
}) | ||
|
||
test("Create a repo instance by key-value pairs", () => { | ||
var repo = new Repo({ username: 'my-username', repoName: 'my-repo-name' }) | ||
|
||
expect(repo.username).toBe('my-username') | ||
expect(repo.repoName).toBe('my-repo-name') | ||
}) | ||
|
||
test('Get Github URL for a repo', () => { | ||
var repo = new Repo('my-user', 'my-repo-name') | ||
|
||
expect(repo.githubUrl()).toBe('https://github.com/my-user/my-repo-name') | ||
}) | ||
|
||
test('Get repo-based Github Pages URL for a repo', () => { | ||
var repo = new Repo('my-user', 'my-repo-name') | ||
|
||
expect(repo.githubPagesUrl()).toBe('https://my-user.github.io/my-repo-name') | ||
}) | ||
|
||
test('Get user-based Github Pages URL for a repo', () => { | ||
var repo = new Repo('my-user') | ||
|
||
expect(repo.githubPagesUrl()).toBe('https://my-user.github.io/') | ||
}) | ||
|
||
test('Get correct full license URL for a repo', () => { | ||
var repo = new Repo('my-user', 'my-repo-name') | ||
|
||
expect(repo.licenseUrl()).toBe('https://github.com/my-user/my-repo-name/blob/master/LICENSE') | ||
}) | ||
|
||
test('Get generate template URL for a repo', () => { | ||
var repo = new Repo('my-user', 'my-repo-name') | ||
|
||
expect(repo.template()).toBe('https://github.com/my-user/my-repo-name/template') | ||
}) | ||
|
||
test('Get tags URL for a repo', () => { | ||
var repo = new Repo('my-user', 'my-repo-name') | ||
|
||
expect(repo.tags()).toBe('https://github.com/my-user/my-repo-name/tags') | ||
}) | ||
|
||
test('Get releases URL for a repo', () => { | ||
var repo = new Repo('my-user', 'my-repo-name') | ||
|
||
expect(repo.releases()).toBe('https://github.com/my-user/my-repo-name/releases') | ||
}) | ||
|
||
test('Get forks URL for a repo', () => { | ||
var repo = new Repo('my-user', 'my-repo-name') | ||
|
||
expect(repo.forks()).toBe('https://github.com/my-user/my-repo-name/network/members') | ||
}) | ||
|
||
test('Get stars URL for a repo', () => { | ||
var repo = new Repo('my-user', 'my-repo-name') | ||
|
||
expect(repo.stars()).toBe('https://github.com/my-user/my-repo-name/stargazers') | ||
}) |
This file contains hidden or 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,32 @@ | ||
class License { | ||
DOMAIN = 'https://img.shields.io' | ||
REL_TARGET = '#license' | ||
DEFAULT_COLOR = 'blue' | ||
|
||
constructor(type, target = null, color = null) { | ||
this.type = type | ||
|
||
this.target = target || this.REL_TARGET | ||
this.color = color || this.DEFAULT_COLOR | ||
} | ||
|
||
title() { | ||
return `License: ${this.type}` | ||
} | ||
|
||
img() { | ||
return `${this.DOMAIN}/badge/License-${this.type}-${this.color}` | ||
} | ||
|
||
fileUrl() { | ||
return `` | ||
} | ||
|
||
markdown() { | ||
return `[})](${this.target})` | ||
} | ||
} | ||
|
||
module.exports = { | ||
License, | ||
} |
This file contains hidden or 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,19 @@ | ||
class Repo { | ||
constructor(username, repoName) { | ||
this.username = username | ||
this.repoName = repoName | ||
} | ||
|
||
url() { | ||
return `https://github.com/${this.username}/${this.repoName}` | ||
} | ||
|
||
licenseUrl() { | ||
return `${this.url()}/blob/master/LICENSE` | ||
} | ||
} | ||
|
||
|
||
module.exports = { | ||
Repo | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I made License its own object.
This is actually not that important to me - I had the app working fine as is for license.