Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: MyMICDS/MyMICDS-v2-Angular
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: MyMICDS/MyMICDS-v2-Angular
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e2e-first-pass
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 8 commits
  • 19 files changed
  • 2 contributors

Commits on May 2, 2020

  1. base protractor setup

    nickbclifford committed May 2, 2020
    Copy the full SHA
    5f71d1e View commit details

Commits on May 3, 2020

  1. Copy the full SHA
    928facf View commit details

Commits on May 4, 2020

  1. Copy the full SHA
    1e25ccb View commit details
  2. now it's working

    nickbclifford committed May 4, 2020
    Copy the full SHA
    2ac4b70 View commit details

Commits on May 5, 2020

  1. login tests

    nickbclifford committed May 5, 2020
    Copy the full SHA
    f1730c2 View commit details

Commits on May 28, 2020

  1. scaffolding for settings and planner tests

    sam committed May 28, 2020
    Copy the full SHA
    343852c View commit details

Commits on May 29, 2020

  1. planner first pass

    nick is a lord; btw DONT BE LIKE ME. run CI=true npm start; don't mess it up
    sam committed May 29, 2020
    Copy the full SHA
    d9bc7ae View commit details

Commits on May 30, 2020

  1. this working i swear

    sam committed May 30, 2020
    Copy the full SHA
    f904196 View commit details
14 changes: 0 additions & 14 deletions e2e/app.e2e-spec.ts

This file was deleted.

11 changes: 0 additions & 11 deletions e2e/app.po.ts

This file was deleted.

20 changes: 20 additions & 0 deletions e2e/home.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { HomePage } from './page-objects/home.po';
import { by, element } from 'protractor';

describe('Home', () => {
let page: HomePage;

beforeAll(() => {
page = new HomePage();
});

beforeEach(async () => {
await page.navigateTo();
});

it('loads default modules', async () => {
for (const module of ['progress', 'schedule', 'weather']) {
expect(await element(by.tagName(`mymicds-${module}`)).isPresent());
}
});
});
51 changes: 51 additions & 0 deletions e2e/login.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { LoginPage } from './page-objects/login.po';
import { browser, ExpectedConditions as until } from 'protractor';
import { testUser } from './utils/user';
import { alert } from './utils/alerts';
import { AlertType } from '../src/app/common/alert';

describe('Login', () => {
let page: LoginPage;

beforeAll(() => {
page = new LoginPage();
});

beforeEach(async () => {
await page.navigateTo();
});

afterEach(async () => {
await browser.executeScript('window.localStorage.clear();');
});

it('requires both fields', async () => {
await page.username.sendKeys('nonempty');
expect(await page.loginButton.getAttribute('disabled')).toBeTruthy();
await page.username.clear();
await page.password.sendKeys('nonempty');
// Protractor is weird with boolean fields? idk
expect(await page.loginButton.getAttribute('disabled')).toBeNull();
});

it('rejects unknown users', async () => {
await page.login('bad username', 'oops');
const alertEl = alert(AlertType.Warning);
await browser.wait(until.presenceOf(alertEl));
expect(await alertEl.$('.alert-content').getText()).toContain('Account is not confirmed!');
});

it('rejects incorrect credentials', async () => {
await page.login(testUser, 'not the right password');
const alertEl = alert(AlertType.Warning);
await browser.wait(until.presenceOf(alertEl));
expect(await alertEl.$('.alert-content').getText()).toContain('Invalid username / password!');
});

it('logs the user in', async () => {
await page.loginTestAccount();
await browser.wait(until.urlContains('/home'));
const token = await browser.executeScript('return window.localStorage.getItem(\'jwt\')');
expect(token).toBeTruthy();
});
});
7 changes: 7 additions & 0 deletions e2e/page-objects/home.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { browser } from 'protractor';

export class HomePage {
async navigateTo() {
await browser.get('/');
}
}
37 changes: 37 additions & 0 deletions e2e/page-objects/login.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { browser, by, element } from 'protractor';
import { testPassword, testUser } from '../utils/user';

export class LoginPage {
async navigateTo() {
await browser.get('/login');
}

get username() {
return element(by.css('input[name="username"]'));
}

get password() {
return element(by.css('input[name="password"]'));
}

get rememberMe() {
return element(by.css('input[name="remember"]'));
}

get loginButton() {
return element(by.tagName('mymicds-login')).element(by.buttonText('Login'));
}

async login(username: string, password: string, remember = false) {
await this.username.sendKeys(username);
await this.password.sendKeys(password);
if (remember) {
await this.rememberMe.click();
}
await this.loginButton.click();
}

async loginTestAccount(remember = false) {
await this.login(testUser, testPassword, remember);
}
}
64 changes: 64 additions & 0 deletions e2e/page-objects/planner.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { browser, element, by } from 'protractor';

export class PlannerPage {
async navigateTo() {
await browser.get('/planner')
}

get showNewEventModal() {
return element.all(by.buttonText("Create Event")).first();
}

get eventTitle() {
return element(by.css('input[name="title"]'));
}

get eventDescription() {
return element(by.css('textarea[name="desc"]'));
}

//school class, NOT programming class
get eventClass() {
return element.all(by.css('select[name="classId"] > option'));
}

get eventDate() {
return element(by.css('input[name="dates"]'));
}

get submitNewEvent() {
return element.all(by.buttonText("Create Event")).last();
}

getCalenderEvent(eventTitle: string) {
// getting event div by finding parent div with title child
return element(by.css('.event-title')).element(by.cssContainingText('div',eventTitle))
//.element(by.xpath('..'));
}

async createCustomEvent(title: string, desc: string) {

// set the date selector
var today = new Date();
var day = today.getDate();
var month = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
var dd : string | number, mm : string | number;

dd = day < 10 ? '0' + day : day
mm = month < 10 ? '0' + month : month

var dateString = mm+'/'+dd+'/'+yyyy;
await this.eventDate.sendKeys(dateString + " - " + dateString)

// for class id select first option
await this.eventClass.first().click();

// set the title and toString
await this.eventTitle.sendKeys(title);
await this.eventDescription.sendKeys(desc)

//submit
await this.submitNewEvent.click()
}
}
39 changes: 39 additions & 0 deletions e2e/page-objects/register.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { browser, by, element } from 'protractor';

export class RegisterPage {
async navigateTo() {
await browser.get('/register');
}

get username() {
return element(by.css('input[formcontrolname="user"]'));
}

get password() {
return element(by.css('input[formcontrolname="password"]'));
}

get confirmPassword() {
return element(by.css('input[formcontrolname="confirmPassword"]'));
}

get firstName() {
return element(by.css('input[formcontrolname="firstName"]'));
}

get lastName() {
return element(by.css('input[formcontrolname="lastName"]'));
}

get teacher() {
return element(by.css('input[formcontrolname="teacher"]'));
}

get gradYears() {
return element.all(by.css('select[formcontrolname="gradYear"] > option'));
}

get registerButton() {
return element(by.css('form > button'));
}
}
7 changes: 7 additions & 0 deletions e2e/page-objects/settings.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { browser, by, element } from 'protractor';
// TODO finish
export class RegisterPage {
async navigateTo() {
await browser.get('/settings');
}
}
53 changes: 53 additions & 0 deletions e2e/planner.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { LoginPage } from './page-objects/login.po';
import { PlannerPage } from './page-objects/planner.po'
import { browser, ExpectedConditions as until } from 'protractor';
import { alert } from './utils/alerts';
import { AlertType } from '../src/app/common/alert';

describe('planner', () => {
let plannerPage : PlannerPage;

beforeAll(async () => {
plannerPage = new PlannerPage();
});

beforeEach(async () => {
await plannerPage.navigateTo();
});

describe('while logged in', () => {
let loginPage : LoginPage;
let eventTitle : string;
let eventDesc : string;

beforeAll(async () => {
loginPage = new LoginPage;
await loginPage.navigateTo();
await loginPage.loginTestAccount();
await plannerPage.navigateTo();
eventTitle = "Special Title";
eventDesc = "This is a cool description.";
});

afterAll(async () => {
await browser.executeScript('window.localStorage.clear();');
});


it('creates a valid custom event', async () => {
await plannerPage.showNewEventModal.click();
await plannerPage.createCustomEvent(eventTitle, eventDesc);
const alertEl = alert(AlertType.Success);
await browser.wait(until.presenceOf(alertEl));
expect(await alertEl.$('.alert-content').getText()).toContain('Added event to planner!');
});

// for some reason I cannot ever select the event title on the calender, no idea why
// it('deletes a custom event', async () => {
// await plannerPage.getCalenderEvent(eventTitle).click();
// await browser.sleep(3500);
// });

})

})
35 changes: 35 additions & 0 deletions e2e/protractor.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/docs/referenceConf.js

const { SpecReporter } = require('jasmine-spec-reporter');

exports.config = {
allScriptsTimeout: 11000,
specs: [
'**/*.e2e-spec.ts'
],
capabilities: {
browserName: 'chrome'
},
SELENIUM_PROMISE_MANAGER: false,
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print() { }
},
useAllAngular2AppRoots: true,
beforeLaunch() {
require('ts-node').register({
project: 'e2e/tsconfig.json'
});
},
async onPrepare() {
jasmine.getEnv().addReporter(new SpecReporter());
// TODO: This feels super hacky, but it's the only way I can get it to work
// noinspection ES6ModulesDependencies
await browser.waitForAngularEnabled(false);
}
};
43 changes: 43 additions & 0 deletions e2e/register.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { RegisterPage } from './page-objects/register.po';
import * as faker from 'faker';
import { browser, by, element, ExpectedConditions as until } from 'protractor';

describe('Register', () => {
let page: RegisterPage;

beforeAll(() => {
page = new RegisterPage();
});

beforeEach(async () => {
await page.navigateTo();
});

it('allows registration as a student', async () => {
await page.username.sendKeys(faker.internet.userName());
const password = faker.internet.password();
await page.password.sendKeys(password);
await page.confirmPassword.sendKeys(password);
await page.firstName.sendKeys(faker.name.firstName());
await page.lastName.sendKeys(faker.name.lastName());
await page.gradYears.first().click();
expect(await page.registerButton.getAttribute('disabled')).toBeFalsy();
await page.registerButton.click();
// it'll timeout if there's an error and it shows any of the other register dialogs instead
await browser.wait(until.presenceOf(element(by.id('register-success'))), 5000);
});

it('allows registration as a teacher', async () => {
await page.username.sendKeys(faker.internet.userName());
const password = faker.internet.password();
await page.password.sendKeys(password);
await page.confirmPassword.sendKeys(password);
await page.firstName.sendKeys(faker.name.firstName());
await page.lastName.sendKeys(faker.name.lastName());
await page.teacher.click();
expect(await page.registerButton.getAttribute('disabled')).toBeFalsy();
await page.registerButton.click();
// ditto
await browser.wait(until.presenceOf(element(by.id('register-success'))), 5000);
});
});
6 changes: 6 additions & 0 deletions e2e/utils/alerts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { AlertType } from '../../src/app/common/alert';
import { by, element } from 'protractor';

export function alert(type: AlertType) {
return element(by.css(`div.alert.alert-${type}`));
}
Loading