Cypress Test – Check number of an api calls

describe('Check API calls', () => {
  before(() => {
    cy.visit('/home'); 
    cy.intercept({method: 'GET', url: 'api-url'}, cy.spy().as('myAlias'));
  });

  it('should only call api-url 2 times', () => {
    cy.get('@myAlias').its('callCount').should('equal', 2)    
  });
}); 

Unit Testing Karma notes

it('should create the app', async(() => { 
    let fixture = TestBed.createComponent(AppComponent); 
    let app = fixture.debugElement.componentInstance; 
    expect(app).toBeTruthy();
}));

it('should have a title `app works!`', async(() => { 
    let fixture = TestBed.createComponent(AppComponent); 
    let app = fixture.debugElement.componentInstance; 
    expect(app.title).toEqual('app works!');
}));

it('should render title in a h1 tag', async(() => { 
    let fixture = TestBed.createComponent(AppComponent); 
    fixture.detectChanges();
    let compiled = fixture.debugElement.nativeElement; 
    expect(compiled.querySelector('h1').textContent).toContain('app works!');
}));

it('should use the user name from the service', () => { 
    let fixture = TestBed.createComponent(UserComponent); 
    let app = fixture.debugElement.componentInstance; 
    let userService = fixture.debugElement.injector.get(UserService); 
    fixture.detectChanges(); 
    expect(userService.user.name).toEqual(app.user.name);
});

it('should display the user name if user is logged in', () => { 
    let fixture = TestBed.createComponent(UserComponent); 
    let app = fixture.debugElement.componentInstance; 
    app.isLoggedIn = true
    fixture.detectChanges(); 
    let compiled = fixture.debugElement.nativeElement; 
    expect(compiled.querySelector('p').textContent).toContain(app.user.name);
});

it('should not display the user name if user is not logged in', () => { 
    let fixture = TestBed.createComponent(UserComponent); 
    let app = fixture.debugElement.componentInstance; 
    fixture.detectChanges(); 
    let compiled = fixture.debugElement.nativeElement; 
    expect(compiled.querySelector('p').textContent).not.toContain(app.user.name);
});




// Expecting undefined
it('should not fetch data successfully if not called asynchronously', async(() => { 
    let fixture = TestBed.createComponent(UserComponent);
    let app = fixture.debugElement.componentInstance; 
    let dataService = fixture.debugElement.injector.get(DataService); 
    let spy = spyOn(dataService, 'getDetails') //getDetails is a function in dataService
        .and.returnValue(Promise.resolve('Data'));
    fixture.detectChanges(); 
    expect(app.data).toBe(undefined);
}));


// Expecting proper data v1
it('should fetch data successfully if called asynchronously', async(() => { 
    let fixture = TestBed.createComponent(UserComponent);
    let app = fixture.debugElement.componentInstance; 
    let dataService = fixture.debugElement.injector.get(DataService); 
    let spy = spyOn(dataService, 'getDetails') //getDetails is a function in dataService
        .and.returnValue(Promise.resolve('Data'));
    fixture.detectChanges(); 
    fixture.whenStable().then(() => { 
        expect(app.data).toBe('Data');
    });
}));

// Expecting proper data v2
it('should fetch data successfully if called asynchronously', fakeAsync(() => { 
    let fixture = TestBed.createComponent(UserComponent);
    let app = fixture.debugElement.componentInstance; 
    let dataService = fixture.debugElement.injector.get(DataService); 
    let spy = spyOn(dataService, 'getDetails') //getDetails is a function in dataService
        .and.returnValue(Promise.resolve('Data'));
    fixture.detectChanges(); 
    tick();
    expect(app.data).toBe('Data');
}));





it('should test isolated function (not rely on angular)', () => {
    let reversePipe = new ReversePipe(); 
    expect(reversePipe.transform('hello').toEqual('olleh'));
})

Introduction to GIS for devs

What is GIS?

Basemap and Geocoding

Operation Layer and GIS Services

Visualize Data

Spatial Analysis

Suitability Analysis

GIS Analysis Performance & Network Analysis & Spatial Analysis Solution

GIS and Community

 

Ref: A good course from Pluralsight
https://app.pluralsight.com/library/courses/gis-introduction-developers

Protractor – elementexplorer.js

elementexplorer.js is a bonus tool from protractor that helps you debug your selectors on page objects live! It’ll make your life on writing protractor tests a lot easier! This post assumes that you have worked with protractor before and have it installed on your machine.

Start selenium

Before starting elementexplorer.js, you need to first start selenium:

> webdriver-manager update
> webdriver-manager start

# or you can start webdriver with a specific port; default is 4444
> webdriver-manager start --seleniumPort XXXX

In the browser opened by selenium, navigate to your angular web app.

Assuming that you have the following binding in your application:

$scope.yourName = "Wahaha" 
<input ng-model="yourName" />

 

Use elementexplorer

Open a new terminal. Then locate it in node_modules folder and run the following command

> ./node_modules/protractor/bin/elementexplorer.js

Using list() in elementexplorer:

> list(by.model('yourName'))
['']

> list(by.model('notExisted'))
[]

> list(by.binding('yourName'))
['Wahaha']  //Note: this value can be changed on page

 

Reference:

How To Master The Perfect Voice

The referenced video of this post is an interview done by Stefan James with Roger Love.

Just to take note and apply it to my next speaking sessions, here are the three main points that may immediately applicable for me:

1. Three range of tone of speaking to make the talk more interesting: (should be lower and slower for me)

2. Pause and breathe in with nose instead of mouth between sentences or commas.

3. Don’t limit my voice to the microphone; Project my voice to vibrate the bodies of the far audience.