2017-03-07 18:42:14 +01:00
|
|
|
import { expect } from 'chai';
|
|
|
|
|
|
|
|
import HeadlineFinder from '../src/javascript/models/HeadlineFinder';
|
2017-03-27 07:34:58 +02:00
|
|
|
import LineItem from '../src/javascript/models/LineItem.jsx';
|
2017-03-07 18:42:14 +01:00
|
|
|
|
|
|
|
describe('HeadlineFinder', () => {
|
|
|
|
|
|
|
|
it('Not Found - Case 1', () => {
|
|
|
|
const headlineFinder = new HeadlineFinder({
|
|
|
|
headline: 'My Little Headline'
|
|
|
|
});
|
2017-03-27 07:34:58 +02:00
|
|
|
const item1 = new LineItem({
|
2017-03-07 18:42:14 +01:00
|
|
|
text: 'My '
|
|
|
|
});
|
2017-03-27 07:34:58 +02:00
|
|
|
const item2 = new LineItem({
|
2017-03-07 18:42:14 +01:00
|
|
|
text: 'Little'
|
|
|
|
});
|
2017-03-27 07:34:58 +02:00
|
|
|
const item3 = new LineItem({
|
2017-03-07 18:42:14 +01:00
|
|
|
text: ' Headline2'
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(headlineFinder.consume(item1)).to.equal(null);
|
2017-03-27 07:34:58 +02:00
|
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(1).to.contain(item1);
|
2017-03-07 18:42:14 +01:00
|
|
|
expect(headlineFinder.consume(item2)).to.equal(null);
|
2017-03-27 07:34:58 +02:00
|
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(2).to.contain(item1).to.contain(item2);
|
2017-03-07 18:42:14 +01:00
|
|
|
expect(headlineFinder.consume(item3)).to.equal(null);
|
2017-03-27 07:34:58 +02:00
|
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(0);
|
2017-03-07 18:42:14 +01:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Found - Simple', () => {
|
|
|
|
const headlineFinder = new HeadlineFinder({
|
|
|
|
headline: 'My Little Headline'
|
|
|
|
});
|
2017-03-27 07:34:58 +02:00
|
|
|
const item1 = new LineItem({
|
2017-03-07 18:42:14 +01:00
|
|
|
text: 'My '
|
|
|
|
});
|
2017-03-27 07:34:58 +02:00
|
|
|
const item2 = new LineItem({
|
2017-03-07 18:42:14 +01:00
|
|
|
text: 'Little'
|
|
|
|
});
|
2017-03-27 07:34:58 +02:00
|
|
|
const item3 = new LineItem({
|
2017-03-07 18:42:14 +01:00
|
|
|
text: ' Headline'
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(headlineFinder.consume(item1)).to.equal(null);
|
2017-03-27 07:34:58 +02:00
|
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(1).to.contain(item1);
|
2017-03-07 18:42:14 +01:00
|
|
|
expect(headlineFinder.consume(item2)).to.equal(null);
|
2017-03-27 07:34:58 +02:00
|
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(2).to.contain(item1).to.contain(item2);
|
2017-03-07 18:42:14 +01:00
|
|
|
expect(headlineFinder.consume(item3)).to.have.lengthOf(3).to.contain(item1).to.contain(item2).to.contain(item3);
|
2017-03-27 07:34:58 +02:00
|
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(3).to.contain(item1).to.contain(item2).to.contain(item3);
|
2017-03-07 18:42:14 +01:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Found - Waste in beginning', () => {
|
|
|
|
const headlineFinder = new HeadlineFinder({
|
|
|
|
headline: 'My Little Headline'
|
|
|
|
});
|
2017-03-27 07:34:58 +02:00
|
|
|
const item0 = new LineItem({
|
2017-03-07 18:42:14 +01:00
|
|
|
text: 'Waste '
|
|
|
|
});
|
2017-03-27 07:34:58 +02:00
|
|
|
const item1 = new LineItem({
|
2017-03-07 18:42:14 +01:00
|
|
|
text: 'My '
|
|
|
|
});
|
2017-03-27 07:34:58 +02:00
|
|
|
const item2 = new LineItem({
|
2017-03-07 18:42:14 +01:00
|
|
|
text: 'Little'
|
|
|
|
});
|
2017-03-27 07:34:58 +02:00
|
|
|
const item3 = new LineItem({
|
2017-03-07 18:42:14 +01:00
|
|
|
text: ' Headline'
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(headlineFinder.consume(item0)).to.equal(null);
|
2017-03-27 07:34:58 +02:00
|
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(0);
|
2017-03-07 18:42:14 +01:00
|
|
|
expect(headlineFinder.consume(item1)).to.equal(null);
|
2017-03-27 07:34:58 +02:00
|
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(1).to.contain(item1);
|
2017-03-07 18:42:14 +01:00
|
|
|
expect(headlineFinder.consume(item2)).to.equal(null);
|
2017-03-27 07:34:58 +02:00
|
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(2).to.contain(item1).to.contain(item2);
|
2017-03-07 18:42:14 +01:00
|
|
|
expect(headlineFinder.consume(item3)).to.have.lengthOf(3).to.contain(item1).to.contain(item2).to.contain(item3);
|
2017-03-27 07:34:58 +02:00
|
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(3).to.contain(item1).to.contain(item2).to.contain(item3);
|
2017-03-07 18:42:14 +01:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Found - Duplicate in beginning', () => {
|
|
|
|
const headlineFinder = new HeadlineFinder({
|
|
|
|
headline: 'My Little Headline'
|
|
|
|
});
|
2017-03-27 07:34:58 +02:00
|
|
|
const item0 = new LineItem({
|
2017-03-07 18:42:14 +01:00
|
|
|
text: 'My '
|
|
|
|
});
|
2017-03-27 07:34:58 +02:00
|
|
|
const item1 = new LineItem({
|
2017-03-07 18:42:14 +01:00
|
|
|
text: 'My '
|
|
|
|
});
|
2017-03-27 07:34:58 +02:00
|
|
|
const item2 = new LineItem({
|
2017-03-07 18:42:14 +01:00
|
|
|
text: 'Little'
|
|
|
|
});
|
2017-03-27 07:34:58 +02:00
|
|
|
const item3 = new LineItem({
|
2017-03-07 18:42:14 +01:00
|
|
|
text: ' Headline'
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(headlineFinder.consume(item0)).to.equal(null);
|
2017-03-27 07:34:58 +02:00
|
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(1).to.contain(item0);
|
2017-03-07 18:42:14 +01:00
|
|
|
expect(headlineFinder.consume(item1)).to.equal(null);
|
2017-03-27 07:34:58 +02:00
|
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(1).to.contain(item1);
|
2017-03-07 18:42:14 +01:00
|
|
|
expect(headlineFinder.consume(item2)).to.equal(null);
|
2017-03-27 07:34:58 +02:00
|
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(2).to.contain(item1).to.contain(item2);
|
2017-03-07 18:42:14 +01:00
|
|
|
expect(headlineFinder.consume(item3)).to.have.lengthOf(3).to.contain(item1).to.contain(item2).to.contain(item3);
|
2017-03-27 07:34:58 +02:00
|
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(3).to.contain(item1).to.contain(item2).to.contain(item3);
|
2017-03-07 18:42:14 +01:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Found - Mixed up case and Whitespace', () => {
|
|
|
|
const headlineFinder = new HeadlineFinder({
|
|
|
|
headline: 'MYLitt le HEADline'
|
|
|
|
});
|
2017-03-27 07:34:58 +02:00
|
|
|
const item1 = new LineItem({
|
2017-03-07 18:42:14 +01:00
|
|
|
text: 'My '
|
|
|
|
});
|
2017-03-27 07:34:58 +02:00
|
|
|
const item2 = new LineItem({
|
2017-03-07 18:42:14 +01:00
|
|
|
text: 'Little'
|
|
|
|
});
|
2017-03-27 07:34:58 +02:00
|
|
|
const item3 = new LineItem({
|
2017-03-07 18:42:14 +01:00
|
|
|
text: ' Headline'
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(headlineFinder.consume(item1)).to.equal(null);
|
2017-03-27 07:34:58 +02:00
|
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(1).to.contain(item1);
|
2017-03-07 18:42:14 +01:00
|
|
|
expect(headlineFinder.consume(item2)).to.equal(null);
|
2017-03-27 07:34:58 +02:00
|
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(2).to.contain(item1).to.contain(item2);
|
2017-03-07 18:42:14 +01:00
|
|
|
expect(headlineFinder.consume(item3)).to.have.lengthOf(3).to.contain(item1).to.contain(item2).to.contain(item3);
|
2017-03-27 07:34:58 +02:00
|
|
|
expect(headlineFinder.stackedLineItems).to.have.lengthOf(3).to.contain(item1).to.contain(item2).to.contain(item3);
|
2017-03-07 18:42:14 +01:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|