Advertisement
krutzz

Untitled

Sep 10th, 2017
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { ComponentFixture, TestBed, async } from '@angular/core/testing';
  2.  
  3. import { By } from '@angular/platform-browser';
  4. import { MockPostDirective } from '../../tests/tests-mocks/mock-post.directive';
  5. import { MostpoluarComponent } from './mostpoluar.component';
  6. import { NewPostPipe } from '../pipes/transform-to-post/new-post.pipe';
  7. import { Post } from './../../shared/models/post';
  8. import { PostServiceMockService } from '../../tests/providers/posts-service-mock/post-service-mock.service';
  9. import { PostsService } from '../providers/posts-service/Posts.service';
  10.  
  11. const post = new Post({
  12.   '$key': '-KsXmtFl4altqKAOtexA',
  13.   'category': 'Cars',
  14.   'date': 'Sun Aug 27 2017 11:25:17 GMT+0300 (FLE Daylight Time)',
  15.   'description': 'No description',
  16.   // tslint:disable-next-line:max-line-length
  17.   'images': ['https://firebasestorage.googleapis.com/v0/b/nglx-98be4.appspot.com/o/posts%2FSun%20Aug%2027%202017%2011%3A25%3A17%20GMT%2B0300%20(FLE%20Daylight%20Time)_lambo1.jpg?alt=media&token=11f3fc4c-7a48-4e56-a016-7b511b2eb646'],
  18.   'price': '100000',
  19.   'province': 'Sofia',
  20.   'title': 'Lamborghini',
  21.   'user': [{
  22.     'email': 'krutz@gmail.com',
  23.     'providerId': 'password',
  24.     'uid': 'krutz@gmail.com'
  25.   }],
  26.   'views': 5
  27. });
  28.  
  29. describe('MostpoluarComponent', () => {
  30.   let component: MostpoluarComponent;
  31.   let fixture: ComponentFixture<MostpoluarComponent>;
  32.  
  33.   beforeEach(async(() => {
  34.     TestBed.configureTestingModule({
  35.       declarations: [
  36.         MostpoluarComponent,
  37.         NewPostPipe,
  38.         MockPostDirective
  39.       ],
  40.       providers: [
  41.         { provide: PostsService, useClass: PostServiceMockService }
  42.       ]
  43.     })
  44.       .compileComponents();
  45.   }));
  46.  
  47.   beforeEach(() => {
  48.     fixture = TestBed.createComponent(MostpoluarComponent);
  49.     fixture.autoDetectChanges();
  50.     component = fixture.componentInstance;
  51.   });
  52.  
  53.   it('should be created', () => {
  54.     expect(component).toBeTruthy();
  55.   });
  56.  
  57.   it('should contain post component', () => {
  58.     // Arrange.
  59.     const mockPostEl = fixture.debugElement.query(By.directive(MockPostDirective));
  60.  
  61.     // Assert.
  62.     expect(mockPostEl).toBeTruthy();
  63.   });
  64.  
  65.   it('should pass down post element', () => {
  66.     // Arrange.
  67.     const mockPostEl = fixture.debugElement.query(By.directive(MockPostDirective));
  68.     const mockTaskCmp = mockPostEl.injector.get(MockPostDirective) as MockPostDirective;
  69.  
  70.     // Assert.
  71.     expect(mockTaskCmp.post).toBeTruthy();
  72.     expect(mockTaskCmp.post).toEqual(post);
  73.   });
  74.  
  75. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement