Fix e2e test and actually check login works
This commit is contained in:
parent
89e3d48a07
commit
971cf43c38
7 changed files with 101 additions and 21 deletions
14
.idea/codeStyles/Project.xml
Normal file
14
.idea/codeStyles/Project.xml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<code_scheme name="Project" version="173">
|
||||||
|
<TypeScriptCodeStyleSettings version="0">
|
||||||
|
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
||||||
|
<option name="BLANK_LINES_AROUND_FUNCTION" value="0" />
|
||||||
|
</TypeScriptCodeStyleSettings>
|
||||||
|
<codeStyleSettings language="TypeScript">
|
||||||
|
<option name="BLANK_LINES_AROUND_METHOD" value="0" />
|
||||||
|
<option name="BLANK_LINES_AROUND_METHOD_IN_INTERFACE" value="0" />
|
||||||
|
<option name="KEEP_SIMPLE_BLOCKS_IN_ONE_LINE" value="true" />
|
||||||
|
<option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
|
||||||
|
</codeStyleSettings>
|
||||||
|
</code_scheme>
|
||||||
|
</component>
|
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||||
|
</state>
|
||||||
|
</component>
|
24
README.md
24
README.md
|
@ -35,12 +35,34 @@ npm install
|
||||||
The app defaults to using the development server. For other options, see
|
The app defaults to using the development server. For other options, see
|
||||||
`src/environments/environments.ts`
|
`src/environments/environments.ts`
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
There are two types of test in this codebase, unit tests (using Karma) and E2E tests (using Protractor).
|
||||||
|
|
||||||
|
### Karma Unit Tests
|
||||||
|
|
||||||
|
To run these, you just need to run `npm run test` - this should work without any further configuration. These run the `*.spec.ts` files next to the normal source files, and are for basic tests for each function on their own.
|
||||||
|
|
||||||
|
These tests are a long-running process, and will automatically run on file changes. Just run the command above, and then check back to the browser window that appears to see any errors as you work!
|
||||||
|
|
||||||
|
### Protractor E2E Tests
|
||||||
|
|
||||||
|
To run these, you will need to run the following:
|
||||||
|
|
||||||
|
```
|
||||||
|
webdriver-manager update
|
||||||
|
```
|
||||||
|
|
||||||
|
This will download the correct webdriver for you (we use chromedriver), and any other dependencies it needs. After that, you can run the tests with `npm run e2e`. Note these run once, and will need to be re-run every time you want to run an e2e test. You will also need to run the
|
||||||
|
|
||||||
|
These tests are best run regularly, and should show if any issues have emerged in other parts of the application that you are not aware of, or if some part of the flow through the app has changed sufficiently.
|
||||||
|
|
||||||
## Licences
|
## Licences
|
||||||
|
|
||||||
### CoreUI
|
### CoreUI
|
||||||
|
|
||||||
The interface itself is based off of [CoreUI][core-ui] which is MIT Licenced.
|
The interface itself is based off of [CoreUI][core-ui] which is MIT Licenced.
|
||||||
For information, see [MIT Licence](./LICENCE.MIT) included in this repo.
|
For information, see `LICENCE.MIT` included in this repo.
|
||||||
|
|
||||||
[core-ui]: http://coreui.io
|
[core-ui]: http://coreui.io
|
||||||
|
|
||||||
|
|
|
@ -1,34 +1,59 @@
|
||||||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
|
|
||||||
import { TestBed, ComponentFixture, async } from '@angular/core/testing';
|
|
||||||
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
|
||||||
import { LoginPageObject } from './login.po';
|
import { LoginPageObject } from './login.po';
|
||||||
import { ApiService } from '../src/app/providers/api-service';
|
import { browser } from "protractor";
|
||||||
|
|
||||||
describe('Login Page', () => {
|
describe('Login Page', () => {
|
||||||
let page: LoginPageObject;
|
let page: LoginPageObject;
|
||||||
let api: ApiService;
|
|
||||||
let apiSpy: jasmine.SpyObj<ApiService>;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
page = new LoginPageObject();
|
page = new LoginPageObject();
|
||||||
const spy = jasmine.createSpyObj
|
page.navigateTo();
|
||||||
TestBed.configureTestingModule({ providers: [ApiService] });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
api = TestBed.inject(ApiService);
|
|
||||||
apiSpy = TestBed.inject(ApiService);
|
|
||||||
|
|
||||||
it('should have a header saying login', () => {
|
it('should have a header saying login', () => {
|
||||||
expect(page.getLoginHeaderText()).toEqual('Login');
|
expect(page.getLoginHeaderText()).toEqual('Login');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have a username box of type email', () => {
|
it('should have a username box of type email', () => {
|
||||||
expect(page.isUsernameFieldPresent()).toBeTruthy();
|
expect(page.isEmailFieldPresent()).toBeTruthy();
|
||||||
expect(page.getUsernameFieldType()).toEqual('email');
|
expect(page.getEmailFieldType()).toEqual('email');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have a password box of type password', () => {
|
it('should have a password box of type password', () => {
|
||||||
expect(page.isPasswordFieldPresent()).toBeTruthy();
|
expect(page.isPasswordFieldPresent()).toBeTruthy();
|
||||||
expect(page.getPasswordFieldType()).toBe('password');
|
expect(page.getPasswordFieldType()).toBe('password');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should have a login button of type submit', () => {
|
||||||
|
expect(page.isLoginButtonPresent()).toBeTruthy();
|
||||||
|
expect(page.getLoginButtonType()).toBe('submit');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a disabled login button when empty', () => {
|
||||||
|
expect(page.isLoginButtonEnabled()).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a disabled login button when only email', () => {
|
||||||
|
page.fillEmailFieldWith('test@example.com');
|
||||||
|
expect(page.isLoginButtonEnabled()).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a disabled login button when only password', () => {
|
||||||
|
page.fillPasswordFieldWith('abc123');
|
||||||
|
expect(page.isLoginButtonEnabled()).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have an enabled login button when both inputs filled', () => {
|
||||||
|
page.fillEmailFieldWith('test@example.com');
|
||||||
|
page.fillPasswordFieldWith('abc123');
|
||||||
|
expect(page.isLoginButtonEnabled()).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should submit the filled data when login pressed', () => {
|
||||||
|
page.fillEmailFieldWith('test@example.com');
|
||||||
|
page.fillPasswordFieldWith('abc123');
|
||||||
|
expect(page.isLoginButtonEnabled()).toBeTruthy();
|
||||||
|
page.getLoginButton().click();
|
||||||
|
browser.waitForAngular();
|
||||||
|
expect(browser.getCurrentUrl()).toContain('dashboard');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,12 +9,23 @@ export class LoginPageObject {
|
||||||
return element(by.css('app-root h1')).getText();
|
return element(by.css('app-root h1')).getText();
|
||||||
}
|
}
|
||||||
|
|
||||||
getUsernameField() { return element(by.id('username')); }
|
getEmailField() { return element(by.id('username')); }
|
||||||
getPasswordField() { return element(by.id('password')); }
|
getPasswordField() { return element(by.id('password')); }
|
||||||
|
getLoginButton() { return element(by.id('login')); }
|
||||||
|
|
||||||
isUsernameFieldPresent() { return this.getUsernameField().isPresent(); }
|
isEmailFieldPresent() { return this.getEmailField().isPresent(); }
|
||||||
isPasswordFieldPresent() { return this.getPasswordField().isPresent(); }
|
isPasswordFieldPresent() { return this.getPasswordField().isPresent(); }
|
||||||
|
isLoginButtonPresent() { return this.getLoginButton().isPresent(); }
|
||||||
|
|
||||||
getUsernameFieldType() { return this.getUsernameField().getAttribute('type'); }
|
getEmailFieldType() { return this.getEmailField().getAttribute('type'); }
|
||||||
getPasswordFieldType() { return this.getPasswordField().getAttribute('type'); }
|
getPasswordFieldType() { return this.getPasswordField().getAttribute('type'); }
|
||||||
|
getLoginButtonType() { return this.getLoginButton().getAttribute('type'); }
|
||||||
|
|
||||||
|
isLoginButtonEnabled() { return this.getLoginButton().isEnabled(); }
|
||||||
|
|
||||||
|
clearEmailField() { return this.getEmailField().clear() };
|
||||||
|
clearPasswordField() { return this.getPasswordField().clear() };
|
||||||
|
|
||||||
|
fillEmailFieldWith(text) { return this.getEmailField().sendKeys(text) };
|
||||||
|
fillPasswordFieldWith(text) { return this.getPasswordField().sendKeys(text) };
|
||||||
}
|
}
|
||||||
|
|
9
package-lock.json
generated
9
package-lock.json
generated
|
@ -4242,7 +4242,8 @@
|
||||||
},
|
},
|
||||||
"kind-of": {
|
"kind-of": {
|
||||||
"version": "6.0.2",
|
"version": "6.0.2",
|
||||||
"resolved": ""
|
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
|
||||||
|
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA=="
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -7140,7 +7141,8 @@
|
||||||
},
|
},
|
||||||
"kind-of": {
|
"kind-of": {
|
||||||
"version": "6.0.2",
|
"version": "6.0.2",
|
||||||
"resolved": ""
|
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
|
||||||
|
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA=="
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -14442,7 +14444,8 @@
|
||||||
},
|
},
|
||||||
"kind-of": {
|
"kind-of": {
|
||||||
"version": "6.0.2",
|
"version": "6.0.2",
|
||||||
"resolved": ""
|
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
|
||||||
|
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA=="
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<button type="submit" [disabled]="!signin.valid" class="btn btn-primary px-4">Login</button>
|
<button id="login" type="submit" [disabled]="!signin.valid" class="btn btn-primary px-4">Login</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-6 text-right">
|
<div class="col-6 text-right">
|
||||||
<button type="button" class="btn btn-link px-0" disabled>Forgot password?</button>
|
<button type="button" class="btn btn-link px-0" disabled>Forgot password?</button>
|
||||||
|
|
Reference in a new issue