Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
Add a test suite for LinkTextUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
karrot-farmer committed Mar 4, 2018
1 parent ab026f7 commit ad84256
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}
153 changes: 153 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@
"react-dom": "^16.2.0",
"react-scripts": "1.1.1"
},
"directories": {
"test": "test"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"unittest": "mocha --require babel-core/register || exit 0",
"eject": "react-scripts eject"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"chai": "^4.1.2",
"mocha": "^5.0.1"
}
}
4 changes: 2 additions & 2 deletions src/components/LinkedText.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import React from 'react';

const LinkedText = ({children}) => {
return (
<div>
<span>
{children}
</div>
</span>
);
};

Expand Down
16 changes: 16 additions & 0 deletions src/utils/LinkedTextUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export function splitTextIntoLinkedSlices(text) {
let linkedSlices = [];

linkedSlices.push(
new LinkedTextSlice(text, false)
);

return linkedSlices;
}

export class LinkedTextSlice {
constructor(text, isLinked) {
this.text = text;
this.isLinked = isLinked;
}
}
76 changes: 76 additions & 0 deletions test/linkedtext_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const expect = require("chai").expect;
const splitTextIntoLinkedSlices = require("../src/utils/LinkedTextUtils").splitTextIntoLinkedSlices;

describe('linikedtext', () => {
it('should splitTextIntoLinkedSlices works with a linktext that have no link', () => {
expect(
splitTextIntoLinkedSlices('abcd')
).to.deep.equal(
[
{
text: 'abcd',
isLinked: false
}
]
)
});

it('should splitTextIntoLinkedSlices works with a linktext that have a single http link', () => {
expect(
splitTextIntoLinkedSlices('a http://github.com')
).to.deep.equal(
[
{
text: 'a ',
isLinked: false
},
{
text: 'http://github.com',
isLinked: true
},
]
)
});

it('should splitTextIntoLinkedSlices works with a linktext that have a single https link', () => {
expect(
splitTextIntoLinkedSlices('a https://github.com')
).to.deep.equal(
[
{
text: 'a ',
isLinked: false
},
{
text: 'http://github.com',
isLinked: true
},
]
)
});

it('should splitTextIntoLinkedSlices works with a linktext that have two http links', () => {
expect(
splitTextIntoLinkedSlices('a http://github.com b http://google.com')
).to.deep.equal(
[
{
text: 'a ',
isLinked: false
},
{
text: 'http://github.com',
isLinked: true
},
{
text: ' b ',
isLinked: false
},
{
text: 'http://google.com',
isLinked: true
},
]
)
});
});

1 comment on commit ad84256

@kujyp
Copy link
Collaborator

@kujyp kujyp commented on ad84256 Mar 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#7

Please sign in to comment.