Skip to content

Commit c6396ce

Browse files
committed
add tests for admin app, and update tests for main app
1 parent 5ed1667 commit c6396ce

File tree

15 files changed

+327
-179
lines changed

15 files changed

+327
-179
lines changed

clients/.DS_Store

-6 KB
Binary file not shown.

clients/Admin/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,8 @@ amplifytools.xcconfig
6565
# ignore yarn.lock and package-lock.json files for now
6666
yarn.lock
6767
package-lock.json
68+
69+
#cypress
70+
cypress/videos/*
71+
cypress/screenshots/*
72+
cypress.env.json

clients/Admin/cypress.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from 'cypress';
2+
3+
export default defineConfig({
4+
defaultCommandTimeout: 10000,
5+
requestTimeout: 10000,
6+
e2e: {
7+
supportFile: false,
8+
},
9+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"host": "UPDATE_ME",
3+
"adminUsername": "UPDATE_ME",
4+
"adminUserPassword": "UPDATE_ME",
5+
"newTenantName": "UPDATE_ME",
6+
"newTenantEmail": "UPDATE_ME",
7+
"newTenantTier": "UPDATE_ME"
8+
}

clients/Admin/cypress/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Application End-to-End Testing
2+
3+
## Instructions
4+
5+
To run End-to-End (e2e) tests against the Sample Application, take the following steps:
6+
7+
1. Make a copy of the example env file (`cypress.env.json.example`):
8+
9+
```bash
10+
cp cypress.env.json.example cypress.env.json
11+
```
12+
13+
2. Edit the new file and replace the sample values with real values.
14+
15+
3. Navigate to the root of the Application project (`aws-saas-factory-ref-solution-serverless-saas/clients/Application/`) and run the following:
16+
17+
```bash
18+
npx cypress run
19+
```
20+
21+
This will run the tests located in the `cypress/e2e` folder.
22+
23+
The documentation [here](https://docs.cypress.io/guides/guides/command-line#cypress-run) has more information on what can be passed in as arguments when running the Cypress tests.
24+
25+
For example, running the following will show the Cypress UI and what is happening as each of the tests are run:
26+
27+
```bash
28+
npx cypress run --headed
29+
```
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
describe('admin user tests', () => {
2+
beforeEach(() => {
3+
cy.visit(Cypress.env('host'));
4+
5+
cy.get('form input[name="username"]').type(Cypress.env('adminUsername'));
6+
cy.get('form input[name="password"]').type(
7+
Cypress.env('adminUserPassword')
8+
);
9+
10+
cy.intercept({
11+
url: 'https://cognito-idp.*.amazonaws.com',
12+
}).as('signIn');
13+
14+
cy.get('form button[type="submit"]').click();
15+
cy.wait('@signIn');
16+
17+
cy.wait(1500);
18+
cy.get('body').then((body) => {
19+
if (body.find('form input[name="confirm_password"]').length > 0) {
20+
cy.get('form input[name="password"]').type(
21+
Cypress.env('adminUserPassword')
22+
);
23+
cy.get('form input[name="confirm_password"]').type(
24+
Cypress.env('adminUserPassword')
25+
);
26+
27+
cy.get('form button[type="submit"]').click();
28+
cy.wait('@signIn');
29+
}
30+
if (body.find('input[name="unverifiedAttr"]').length > 0) {
31+
cy.get('button').contains('Skip').click();
32+
}
33+
});
34+
});
35+
36+
it('can create new tenants', () => {
37+
const myTenant = {
38+
name: Cypress.env('newTenantName'),
39+
email: Cypress.env('newTenantEmail'),
40+
tier: Cypress.env('newTenantTier'),
41+
};
42+
cy.location().should((loc) => {
43+
expect(loc.href).to.contain('/dashboard');
44+
expect(loc.href).to.not.contain('/unauthorized');
45+
});
46+
47+
cy.get('a').contains('Tenants').click();
48+
cy.location().should((loc) => {
49+
expect(loc.href).to.contain('/tenants/list');
50+
});
51+
52+
cy.get("button[color='primary'").contains('Add Tenant').click();
53+
cy.location().should((loc) => {
54+
expect(loc.href).to.contain('/tenants/create');
55+
});
56+
57+
cy.get('form').within(() => {
58+
cy.get('input[formcontrolname="tenantName"]').type(myTenant.name);
59+
cy.get('input[formcontrolname="tenantEmail"]').type(myTenant.email);
60+
cy.get('select[formcontrolname="tenantTier"]').select(myTenant.tier);
61+
});
62+
63+
cy.intercept({
64+
method: 'POST',
65+
url: '**/registration',
66+
}).as('postRegistration');
67+
68+
cy.intercept({
69+
method: 'GET',
70+
url: '**/tenants',
71+
}).as('getTenants');
72+
73+
cy.get('button').contains('Submit').click();
74+
cy.wait('@postRegistration');
75+
76+
cy.location().should((loc) => {
77+
expect(loc.href).to.contain('/tenants/list');
78+
});
79+
80+
cy.wait('@getTenants');
81+
82+
cy.get('table td').contains(myTenant.name).should('be.visible');
83+
cy.get('table td').contains(myTenant.email).should('be.visible');
84+
cy.get('table td').contains(myTenant.tier).should('be.visible');
85+
});
86+
});

clients/Admin/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@angular/cli": "~14.0.5",
3737
"@angular/compiler-cli": "~14.0.0",
3838
"@types/jasmine": "~4.0.0",
39+
"cypress": "^12.4.1",
3940
"jasmine-core": "~4.1.0",
4041
"karma": "~6.3.0",
4142
"karma-chrome-launcher": "~3.1.0",

clients/Application/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Dashboard
1+
# Application
22

33
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 14.0.5.
44

clients/Application/angular.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"newProjectRoot": "projects",
99
"projects": {
10-
"dashboard": {
10+
"application": {
1111
"projectType": "application",
1212
"schematics": {
1313
"@schematics/angular:component": {
@@ -47,8 +47,8 @@
4747
},
4848
{
4949
"type": "anyComponentStyle",
50-
"maximumWarning": "2kb",
51-
"maximumError": "4kb"
50+
"maximumWarning": "6kb",
51+
"maximumError": "6kb"
5252
}
5353
],
5454
"fileReplacements": [
@@ -74,18 +74,18 @@
7474
"builder": "@angular-devkit/build-angular:dev-server",
7575
"configurations": {
7676
"production": {
77-
"browserTarget": "dashboard:build:production"
77+
"browserTarget": "application:build:production"
7878
},
7979
"development": {
80-
"browserTarget": "dashboard:build:development"
80+
"browserTarget": "application:build:development"
8181
}
8282
},
8383
"defaultConfiguration": "development"
8484
},
8585
"extract-i18n": {
8686
"builder": "@angular-devkit/build-angular:extract-i18n",
8787
"options": {
88-
"browserTarget": "dashboard:build"
88+
"browserTarget": "application:build"
8989
}
9090
},
9191
"test": {

clients/Application/cypress.config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { defineConfig } from 'cypress';
22

33
export default defineConfig({
4+
defaultCommandTimeout: 10000,
5+
requestTimeout: 10000,
46
e2e: {
57
supportFile: false,
6-
setupNodeEvents(on, config) {
7-
// implement node event listeners here
8-
},
98
},
109
});
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
2-
"host": "http://localhost:4200",
2+
"host": "UPDATE_ME!",
33
"tenantName": "UPDATE_ME!",
44
"tenantUsername": "UPDATE_ME!",
55
"tenantUserPassword": "UPDATE_ME!",
6-
"email": "[email protected]"
6+
"newUserName": "UPDATE_ME!",
7+
"newUserEmail": "UPDATE_ME!",
8+
"newUserRole": "UPDATE_ME!"
79
}

clients/Application/cypress/README.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,7 @@ To run End-to-End (e2e) tests against the Sample Application, take the following
1010
cp cypress.env.json.example cypress.env.json
1111
```
1212

13-
2. Edit the new file and replace the sample values with real values. The following should help when deciding what to use in place of the sample values provided:
14-
15-
- `host`: The URL where the Sample Application is running. If testing locally, this is usually `"http://localhost:4200"`.
16-
17-
- `tenantName`: The name of the tenant used to identify the appropriate Cognito User Pool to use for Authentication.
18-
19-
- `tenantUsername`: The username to use when logging in.
20-
21-
- `tenantUserPassword`: The password to use when logging in.
22-
23-
- `email`: The email address to use for testing. (This should be a valid email address.)
13+
2. Edit the new file and replace the sample values with real values.
2414

2515
3. Navigate to the root of the Application project (`aws-saas-factory-ref-solution-serverless-saas/clients/Application/`) and run the following:
2616

clients/Application/cypress/e2e/1-getting-started/basic-access.cy.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("check that the app redirects to /unauthorized when tenant is not set",
2626
});
2727
});
2828

29-
describe("check that the app redirects to a page with a sign-in form when tenant is set and user is not logged in", () => {
29+
describe("check that the app redirects to a sign-in page when tenant name is set and user is not logged in", () => {
3030
beforeEach(() => {
3131
cy.visit(Cypress.env("host"));
3232

@@ -47,7 +47,6 @@ describe("check that the app redirects to a page with a sign-in form when tenant
4747
it("redirects when visiting orders page", () => {
4848
cy.visit(Cypress.env("host") + "/orders");
4949
cy.location().should((loc) => {
50-
expect(loc.href).to.not.contain("/unauthorized");
5150
expect(loc.href).to.not.contain("/orders");
5251
});
5352

@@ -60,7 +59,6 @@ describe("check that the app redirects to a page with a sign-in form when tenant
6059
it("redirects when visiting products page", () => {
6160
cy.visit(Cypress.env("host") + "/products");
6261
cy.location().should((loc) => {
63-
expect(loc.href).to.not.contain("/unauthorized");
6462
expect(loc.href).to.not.contain("/products");
6563
});
6664

@@ -73,7 +71,6 @@ describe("check that the app redirects to a page with a sign-in form when tenant
7371
it("redirects when visiting a random page", () => {
7472
cy.visit(Cypress.env("host") + "/random");
7573
cy.location().should((loc) => {
76-
expect(loc.href).to.not.contain("/unauthorized");
7774
expect(loc.href).to.not.contain("/random");
7875
});
7976

0 commit comments

Comments
 (0)