How to use pushDecorator method in ng-mocks

Best JavaScript code snippet using ng-mocks

push-importer.js

Source:push-importer.js Github

copy

Full Screen

1import _ from 'lodash';2import Moment from 'moment';3import * as Localization from 'localization';4import * as ExternalDataUtils from 'objects/utils/external-data-utils';5import * as PushReconstructor from 'gitlab-adapter/push-reconstructor';6import * as PushDecorator from 'gitlab-adapter/push-decorator';7// accessors8import Story from 'accessors/story';9/**10 * Import an activity log entry about a push11 *12 * @param {Database} db13 * @param {System} system14 * @param {Server} server15 * @param {Repo} repo16 * @param {Project} project17 * @param {User} author18 * @param {Object} glEvent19 *20 * @return {Promise<Story>}21 */22async function importEvent(db, system, server, repo, project, author, glEvent) {23 let schema = project.name;24 let branch, headID, tailID, type, count;25 if (glEvent.push_data) {26 // version 1027 branch = glEvent.push_data.ref;28 type = glEvent.push_data.ref_type;29 headID = glEvent.push_data.commit_to;30 tailID = glEvent.push_data.commit_from;31 count = glEvent.push_data.commit_count;32 } else if (glEvent.data) {33 // version 934 let refParts = _.split(glEvent.data.ref, '/');35 branch = _.last(refParts);36 type = /^tags$/.test(refParts[1]) ? 'tag' : 'branch';37 headID = glEvent.data.after;38 tailID = glEvent.data.before;39 if (/^0+$/.test(tailID)) {40 // all zeros41 tailID = null;42 }43 count = glEvent.data.total_commits_count;44 }45 // retrieve all commits in the push46 let push = await PushReconstructor.reconstructPush(db, server, repo, type, branch, headID, tailID, count);47 // look for component descriptions48 let languageCode = Localization.getDefaultLanguageCode(system);49 let components = await PushDecorator.retrieveDescriptions(server, repo, push, languageCode);50 let storyNew = copyPushProperties(null, system, server, repo, author, push, components, glEvent);51 return Story.insertOne(db, schema, storyNew);52}53/**54 * Copy properties of push55 *56 * @param {Story|null} story57 * @param {System} system58 * @param {Server} server59 * @param {Repo} repo60 * @param {User} author61 * @param {Object} push62 * @param {Array<Object>} components63 * @param {Object} glEvent64 *65 * @return {Story}66 */67function copyPushProperties(story, system, server, repo, author, push, components, glEvent) {68 let storyType;69 let isBranching = false;70 if (!push.tailID) {71 if (glEvent.push_data) {72 // GL 10+73 if (glEvent.push_data.action === 'created') {74 isBranching = true;75 }76 } else if (glEvent.data) {77 // GL 978 if (glEvent.data.project.default_branch !== push.branch) {79 isBranching = true;80 }81 }82 }83 if (isBranching) {84 storyType = push.type;85 } else if (!_.isEmpty(push.fromBranches)) {86 storyType = 'merge';87 } else {88 storyType = 'push';89 }90 let defLangCode = _.get(system, [ 'settings', 'input_languages', 0 ]);91 let storyAfter = _.cloneDeep(story) || {};92 ExternalDataUtils.inheritLink(storyAfter, server, repo, {93 commit: { ids: push.commitIDs }94 });95 ExternalDataUtils.importProperty(storyAfter, server, 'type', {96 value: storyType,97 overwrite: 'always',98 });99 ExternalDataUtils.importProperty(storyAfter, server, 'language_codes', {100 value: [ defLangCode ],101 overwrite: 'always',102 });103 ExternalDataUtils.importProperty(storyAfter, server, 'user_ids', {104 value: [ author.id ],105 overwrite: 'always',106 });107 ExternalDataUtils.importProperty(storyAfter, server, 'role_ids', {108 value: author.role_ids,109 overwrite: 'always',110 });111 ExternalDataUtils.importProperty(storyAfter, server, 'details.commit_before', {112 value: push.tailID || undefined,113 overwrite: 'always',114 });115 ExternalDataUtils.importProperty(storyAfter, server, 'details.commit_after', {116 value: push.headID,117 overwrite: 'always',118 });119 ExternalDataUtils.importProperty(storyAfter, server, 'details.lines', {120 value: _.pickBy(push.lines), // don't include 0's121 overwrite: 'always',122 });123 ExternalDataUtils.importProperty(storyAfter, server, 'details.files', {124 value: _.pickBy(_.mapValues(push.files, 'length')),125 overwrite: 'always',126 });127 ExternalDataUtils.importProperty(storyAfter, server, 'details.components', {128 value: components,129 overwrite: 'always',130 });131 ExternalDataUtils.importProperty(storyAfter, server, 'details.branch', {132 value: push.branch,133 overwrite: 'always',134 });135 ExternalDataUtils.importProperty(storyAfter, server, 'details.from_branches', {136 value: !_.isEmpty(push.fromBranches) ? push.fromBranches : undefined,137 overwrite: 'always',138 });139 ExternalDataUtils.importProperty(storyAfter, server, 'public', {140 value: true,141 overwrite: 'always',142 });143 ExternalDataUtils.importProperty(storyAfter, server, 'published', {144 value: true,145 overwrite: 'always',146 });147 ExternalDataUtils.importProperty(storyAfter, server, 'ptime', {148 value: Moment(glEvent.created_at).toISOString(),149 overwrite: 'always',150 });151 if (_.isEqual(storyAfter, story)) {152 return story;153 }154 storyAfter.itime = new String('NOW()');155 return storyAfter;156}157export {158 importEvent,...

Full Screen

Full Screen

index.ts

Source:index.ts Github

copy

Full Screen

1import { INotification, INotificationProps, NotificationType } from "./types";2import { EmailNotification } from "./email";3import { SmsNotification } from "./sms";4import { PushNotification } from "./push";5import { PushNotificationDecorator } from "./pushDecorator";6import { SmsNotificationDecorator } from "./smsDecotaror";7/**8 * Factory9 */10export class NotificationFactory {11 createEmailNotificationService(): INotification {12 const EmailDependency = null;13 return new EmailNotification(EmailDependency);14 }15 createSMSNotificationService(): INotification {16 const SMSdependency = null;17 return new SmsNotification(SMSdependency);18 }19 createPushotificationService(): INotification {20 const PushDependency = null;21 return new PushNotification(PushDependency);22 }23 createCombinedNotificationService(types: NotificationType[]): INotification {24 let theDefault = this.createEmailNotificationService();25 if (types.includes(NotificationType.push)) {26 theDefault = new PushNotificationDecorator(theDefault);27 }28 if (types.includes(NotificationType.sms)) {29 theDefault = new SmsNotificationDecorator(theDefault);30 }31 return theDefault;32 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';2import { AppComponent } from './app.component';3describe('AppComponent', () => {4 beforeEach(() => MockBuilder(AppComponent).mock(ChildComponent));5 it('should create the app', () => {6 const fixture = MockRender(AppComponent);7 const app = fixture.point.componentInstance;8 expect(app).toBeTruthy();9 });10 it('should have as title "app"', () => {11 const fixture = MockRender(AppComponent);12 const app = fixture.point.componentInstance;13 expect(app.title).toEqual('app');14 });15 it('should render title in a h1 tag', () => {16 const fixture = MockRender(AppComponent);17 expect(fixture.nativeElement.querySelector('h1').textContent).toContain(18 );19 });20 it('should render child component', () => {21 const fixture = MockRender(AppComponent);22 const child = fixture.debugElement.query(By.directive(ChildComponent));23 expect(child).toBeTruthy();24 });25 it('should render child component with input', () => {26 const fixture = MockRender(AppComponent);27 const child = fixture.debugElement.query(By.directive(ChildComponent));28 expect(child.componentInstance.input).toEqual('mock');29 });30 it('should render child component with output', () => {31 const fixture = MockRender(AppComponent);32 const child = fixture.debugElement.query(By.directive(ChildComponent));33 const spy = spyOn(child.componentInstance.output, 'emit');34 child.triggerEventHandler('output', 'test');35 expect(spy).toHaveBeenCalledWith('test');36 });37 it('should render child component with output', () => {38 const fixture = MockRender(AppComponent);39 const child = fixture.debugElement.query(By.directive(ChildComponent));40 const spy = spyOn(child.componentInstance.output, 'emit');41 child.triggerEventHandler('output', 'test');42 expect(spy).toHaveBeenCalledWith('test');43 });44 it('should render child component with custom decorator', () => {45 ngMocks.pushDecorator(46 (component: ChildComponent) => {47 component.output.emit('decorator');48 },49 );50 const fixture = MockRender(AppComponent);51 const child = fixture.debugElement.query(By.directive(ChildComponent));52 expect(child.componentInstance.output).toEqual('decorator');53 });54});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { pushDecorator } from 'ng-mocks';2import { MockBuilder } from 'ng-mocks';3import { MockRender } from 'ng-mocks';4import { Component } from '@angular/core';5import { HttpClient } from '@angular/common/http';6import { Observable } from 'rxjs';7import { TestBed } from '@angular/core/testing';8import { HttpClientTestingModule } from '@angular/common/http/testing';9class MockedHttpService { get() { return new Observable(); } }10pushDecorator(HttpClient, MockedHttpService);11@Component({12})13export class TestComponent {14 constructor(private http: HttpClient) {}15}16describe('TestComponent', () => {17 beforeEach(() => MockBuilder(TestComponent));18 it('should use mocked service', () => {19 const fixture = MockRender(TestComponent);20 expect(TestBed.get(HttpClient)).toBeInstanceOf(MockedHttpService);21 });22});23import { MockBuilder } from 'ng-mocks';24import { MockRender } from 'ng-mocks';25import { Component } from '@angular/core';26import { HttpClient } from '@angular/common/http';27import { Observable } from 'rxjs';28import { TestBed } from '@angular/core/testing';29import { HttpClientTestingModule } from '@angular/common/http/testing';30class MockedHttpService { get() { return new Observable(); } }31@Component({32})33export class TestComponent {34 constructor(private http: HttpClient) {}35}36describe('TestComponent', () => {37 beforeEach(() => MockBuilder(TestComponent).mock(HttpClient, MockedHttpService));38 it('should use mocked service', () => {39 const fixture = MockRender(TestComponent);40 expect(TestBed.get(HttpClient)).toBeInstanceOf(MockedHttpService);41 });42});43import { MockBuilder } from 'ng-mocks';44import { MockRender } from 'ng-mocks';45import { Component } from '@angular/core';46import { HttpClient } from '@angular/common/http';47import { Observable } from 'rxjs';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { pushDecorator } from 'ng-mocks';2import { MockBuilder, MockRender } from 'ng-mocks';3pushDecorator(MyComponent, {4});5describe('MyComponent', () => {6 beforeEach(() => MockBuilder(MyComponent));7 it('should render', () => {8 const fixture = MockRender(MyComponent);9 expect(fixture.nativeElement.innerHTML).toContain('Hello World!');10 });11});12The pushDecorator() method is used to add a decorator to a component. The decorator can be used to change the selector of the component. The MockBuilder() method is used to

Full Screen

Using AI Code Generation

copy

Full Screen

1import { pushDecorator } from 'ng-mocks';2pushDecorator({3 useValue: { ... }4});5import { TestBed } from '@angular/core/testing';6import { MyService } from './test';7describe('MyService', () => {8 it('should be created', () => {9 const service: MyService = TestBed.get(MyService);10 expect(service).toBeTruthy();11 });12});

Full Screen

Using AI Code Generation

copy

Full Screen

1const ngMocks = require('ng-mocks');2ngMocks.pushDecorator('foo', () => {3 return {4 };5});6const ngMocks = require('ng-mocks');7ngMocks.mockComponent('foo');8const ngMocks = require('ng-mocks');9ngMocks.mockDirective('foo');10const ngMocks = require('ng-mocks');11ngMocks.mockPipe('foo');12const ngMocks = require('ng-mocks');13ngMocks.mockProvider('foo');14const ngMocks = require('ng-mocks');15ngMocks.mockRender('foo');16const ngMocks = require('ng-mocks');17ngMocks.mockService('foo');18const ngMocks = require('ng-mocks');19ngMocks.mockNgModule('foo');20const ngMocks = require('ng-mocks');21ngMocks.mockModule('foo');22const ngMocks = require('ng-mocks');23ngMocks.mockInstance('foo');24const ngMocks = require('ng-mocks');25ngMocks.mockImport('foo');26const ngMocks = require('ng-mocks');27ngMocks.mockExport('foo');28const ngMocks = require('ng-mocks');29ngMocks.mockDeclarations('foo');30const ngMocks = require('ng-mocks');31ngMocks.mockImports('foo');32const ngMocks = require('ng-mocks');33ngMocks.mockProviders('foo');34const ngMocks = require('ng-mocks');35ngMocks.mockRoutes('foo');36const ngMocks = require('ng-mocks');

Full Screen

Using AI Code Generation

copy

Full Screen

1pushDecorator(ReactiveFormsModule, 'imports', [ReactiveFormsModule]);2TestBed.configureTestingModule({3 imports: [ReactiveFormsModule]4 }).compileComponents();5 fixture = TestBed.createComponent(AppComponent);6});7describe('AppComponent', () => {8 let component: AppComponent;9 let fixture: ComponentFixture<AppComponent>;10 beforeEach(async(() => {11 TestBed.configureTestingModule({12 imports: [ReactiveFormsModule]13 }).compileComponents();14 fixture = TestBed.createComponent(AppComponent);15 }));16 it('should create the app', () => {17 const app = fixture.debugElement.componentInstance;18 expect(app).toBeTruthy();19 });20});21import { ComponentFixture, TestBed, async } from '@angular/core/testing';22import { ReactiveFormsModule } from '@angular/forms';23import { AppComponent } from './app.component';24describe('AppComponent', () => {25 let component: AppComponent;26 let fixture: ComponentFixture<AppComponent>;27 beforeEach(async(() => {28 TestBed.configureTestingModule({29 imports: [ReactiveFormsModule]30 }).compileComponents();31 fixture = TestBed.createComponent(AppComponent);32 }));33 it('should create the app', () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1pushDecorator(NG_MOCKS_GLOBAL_OPTIONS, {2 mock: {3 providers: {4 },5 },6});7TestBed.configureTestingModule({8 { provide: MyService, useClass: MockedMyService },9});10pushDecorator(NG_MOCKS_GLOBAL_OPTIONS, {11 mock: {12 providers: {13 },14 },15});16TestBed.configureTestingModule({17 { provide: MyService, useClass: MockedMyService },18});19pushDecorator(NG_MOCKS_GLOBAL_OPTIONS, {20 mock: {21 providers: {22 },23 },24});25TestBed.configureTestingModule({26 { provide: MyService, useClass: MockedMyService },27});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', () => {2 let $httpBackend;3 let $http;4 let $rootScope;5 beforeEach(() => {6 angular.mock.module('app', ($provide) => {7 $provide.decorator('$http', ($delegate) => {8 $delegate.get = () => {9 return Promise.resolve({ data: 'mock' });10 };11 return $delegate;12 });13 });14 angular.mock.inject((_$httpBackend_, _$http_, _$rootScope_) => {15 $httpBackend = _$httpBackend_;16 $http = _$http_;17 $rootScope = _$rootScope_;18 });19 });20 it('should use mock response', async () => {21 expect(response.data).toEqual('mock');22 });23});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ng-mocks automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful