Skip to content

Instantly share code, notes, and snippets.

@wingsuitist
Last active August 22, 2017 15:17
Show Gist options
  • Save wingsuitist/51e1c4c0c2f7cb353086f07c6828d0f1 to your computer and use it in GitHub Desktop.
Save wingsuitist/51e1c4c0c2f7cb353086f07c6828d0f1 to your computer and use it in GitHub Desktop.
letslearn-ci-cd plus1 example
# run this in the terminal
npm install -g @angular/cli
ng new letslearn --prefix lsl
cd letslearn
ng e2e
ng test --watch false
ng serve -o
<h1>{{title}}</h1>
<div>
Points: <span>{{points}}</span>
</div>
<button (click)="plus1()">Plus 1</button>
<button (click)="reset()">Reset</button>
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
}).compileComponents();
}));
it('should create the app', async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
it(`should have as title 'Letslearn'`, async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('Letslearn');
}));
it('should render title in a h1 tag', async(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('Letslearn');
}));
it('should increase points by 1 if button clicked', async(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
expect(fixture.componentInstance.points).toBe(1);
fixture.debugElement.nativeElement.querySelector('button').click();
expect(fixture.componentInstance.points).toBe(2);
}));
});
import { Component } from '@angular/core';
@Component({
selector: 'lsl-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'Letslearn';
points = 1;
plus1() {
this.points++;
}
reset() {
this.points = 0;
}
}
import { LetslearnPage } from './app.po';
describe('letslearn App', () => {
let page: LetslearnPage;
beforeEach(() => {
page = new LetslearnPage();
});
it('should display Title Letslearn', () => {
page.navigateTo();
expect(page.getTitleText()).toEqual('Letslearn');
});
it('should click three times and reset with matching points', () => {
page.navigateTo();
expect(page.getPoints()).toBe('1');
page.getPlus1Button().click();
page.getPlus1Button().click();
page.getPlus1Button().click();
expect(page.getPoints()).toBe('4');
page.getResetButton().click();
expect(page.getPoints()).toBe('0');
});
});
import { browser, by, element } from 'protractor';
export class LetslearnPage {
navigateTo() {
return browser.get('/');
}
getTitleText() {
return element(by.css('h1')).getText();
}
getPoints() {
return element(by.cssContainingText('div', 'Points')).$('span').getText();
}
getPlus1Button() {
return element(by.cssContainingText('button', 'Plus 1'));
}
getResetButton() {
return element(by.cssContainingText('button', 'Reset'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment