Skip to content

Commit

Permalink
Merge pull request #946 from shreyanshdwivedi/feedLinker
Browse files Browse the repository at this point in the history
Adds tests for feed-linker and feed-footer component
  • Loading branch information
simsausaurabh authored Jan 15, 2019
2 parents 0974a8e + 26a552b commit 50d06b0
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 2 deletions.
51 changes: 50 additions & 1 deletion src/app/feed/feed-footer/feed-footer.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,58 @@
/* tslint:disable:no-unused-variable */
import { FeedFooterComponent } from './feed-footer.component';
import { TestBed, async } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';

describe('Component: FeedFooter', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
declarations: [
FeedFooterComponent
]
});
});

it('should create an instance', () => {
const component = new FeedFooterComponent();
const fixture = TestBed.createComponent(FeedFooterComponent);
const component = fixture.debugElement.componentInstance;
expect(component).toBeTruthy();
});

it('should sort apiResponseTags on ngOninit()', async(() => {
const fixture = TestBed.createComponent(FeedFooterComponent);
const component = fixture.debugElement.componentInstance;

component.apiResponseTags = [
{
tag : 'tag1',
count : 10
},
{
tag : 'tag2',
count : 5
},
{
tag : 'tag3',
count : 5
},
{
tag : 'tag0',
count : 10
},
{
tag : 'tag1',
count : 10
},
];
component.ngOnInit();
expect(component.sortedApiResponseTags[0].tag).toBe('tag2');
expect(component.sortedApiResponseTags[1].tag).toBe('tag3');
expect(component.sortedApiResponseTags[2].tag).toBe('tag0');
expect(component.sortedApiResponseTags[3].tag).toBe('tag1');
expect(component.sortedApiResponseTags[4].tag).toBe('tag1');
}));
});
48 changes: 47 additions & 1 deletion src/app/feed/feed-linker/feed-linker.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,55 @@
/* tslint:disable:no-unused-variable */
import { FeedLinkerComponent } from './feed-linker.component';
import { TestBed, async } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';

describe('Component: FeedLinker', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
declarations: [
FeedLinkerComponent
]
});
});

it('should create an instance', () => {
const component = new FeedLinkerComponent();
const fixture = TestBed.createComponent(FeedLinkerComponent);
const component = fixture.debugElement.componentInstance;
expect(component).toBeTruthy();
});

it('should call generateAllShards() when useAll is true', async(() => {
const fixture = TestBed.createComponent(FeedLinkerComponent);
const component = fixture.debugElement.componentInstance;

component.useAll = true;
component.text = 'loklak @fossasia #loklak http://loklak.org/';
component.ngOnInit();
expect(component.shardArray.length).toBe(4);
}));

it('should call generateShards() when useAll is false', async(() => {
const fixture = TestBed.createComponent(FeedLinkerComponent);
const component = fixture.debugElement.componentInstance;

component.useAll = false;
component.hashtags = [
'FOSSASIA',
'loklak'
];
component.mentions = [
'loklak'
];
component.links = [
'http://loklak.org/',
'https://github.com/fossasia/loklak_search'
];
component.text = 'loklak @fossasia #loklak http://loklak.org/';
component.ngOnInit();
expect(component.shardArray.length).toBe(4);
}));
});

0 comments on commit 50d06b0

Please sign in to comment.