Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 3a4cfa9b

Přidáno uživatelem Jakub Hlaváč před téměř 4 roky(ů)

Re #8858 - Testování aplikace

+ login actions tests
+ navbar actions tests

Zobrazit rozdíly:

e2e/protractor.conf.js
8 8
 * @type { import("protractor").Config }
9 9
 */
10 10
exports.config = {
11
  allScriptsTimeout: 11000,
11
  allScriptsTimeout: 51000,
12 12
  specs: [
13 13
    './src/**/*.e2e-spec.ts'
14 14
  ],
15 15
  capabilities: {
16
    browserName: 'chrome'
16
    browserName: 'chrome',
17
    chromeOptions: {
18
      args: ['--window-size=1920,870']
19
    }
17 20
  },
21
  restartBrowserBetweenTests: false,
18 22
  directConnect: true,
19 23
  SELENIUM_PROMISE_MANAGER: false,
20 24
  baseUrl: 'http://localhost:4200/',
21 25
  framework: 'jasmine',
22 26
  jasmineNodeOpts: {
23 27
    showColors: true,
24
    defaultTimeoutInterval: 30000,
28
    defaultTimeoutInterval: 50000,
25 29
    print: function() {}
26 30
  },
27 31
  onPrepare() {
......
34 38
      }
35 39
    }));
36 40
  }
37
};
41
};
e2e/src/app.e2e-spec.ts
1
import { browser, logging } from 'protractor';
2
import { AppPage } from './app.po';
3

  
4
describe('workspace-project App', () => {
5
  let page: AppPage;
6

  
7
  beforeEach(() => {
8
    page = new AppPage();
9
  });
10

  
11
  it('should display welcome message', async () => {
12
    await page.navigateTo();
13
    expect(await page.getTitleText()).toEqual('SensLog app is running!');
14
  });
15

  
16
  afterEach(async () => {
17
    // Assert that there are no errors emitted from the browser
18
    const logs = await browser.manage().logs().get(logging.Type.BROWSER);
19
    expect(logs).not.toContain(jasmine.objectContaining({
20
      level: logging.Level.SEVERE,
21
    } as logging.Entry));
22
  });
23
});
e2e/src/app.po.ts
1
import { browser, by, element } from 'protractor';
2

  
3
export class AppPage {
4
  async navigateTo(): Promise<unknown> {
5
    return browser.get(browser.baseUrl);
6
  }
7

  
8
  async getTitleText(): Promise<string> {
9
    return element(by.css('app-root .content span')).getText();
10
  }
11
}
e2e/src/dashboard/dashboard.e2e-spec.ts
1
import {DashboardPo} from './dashboard.po';
2
import {LoginPo} from '../login/login.po';
3
import {browser} from 'protractor';
4

  
5

  
6
describe('Login Module', () => {
7
  let dashboardPo: DashboardPo;
8
  let loginPo: LoginPo
9

  
10
  beforeEach(() => {
11
    dashboardPo = new DashboardPo();
12
    loginPo = new LoginPo();
13
  });
14

  
15
  it('Add user!', async () => {
16
    await loginPo.navigateTo();
17
    await loginPo.processForm();
18
    await dashboardPo.showUserInsert();
19
    expect(await dashboardPo.popupShown()).toEqual(true);
20
    await dashboardPo.sendUserForm();
21
    expect(await dashboardPo.success()).toEqual(true);
22
  });
23

  
24
  it('Add unit!', async () => {
25
    await loginPo.navigateTo();
26
    await loginPo.processForm();
27
    await dashboardPo.showUnitInsert();
28
    expect(await dashboardPo.popupShown()).toEqual(true);
29
    await dashboardPo.sendUnitForm();
30
    expect(await dashboardPo.success()).toEqual(true);
31
  });
32

  
33
});
e2e/src/dashboard/dashboard.po.ts
1
import { browser, by, element } from 'protractor';
2
import * as moment from 'moment-timezone';
3

  
4
export class DashboardPo {
5
  async navigateTo(): Promise<unknown> {
6
    return browser.get(browser.baseUrl);
7
  }
8

  
9
  async showUserInsert(): Promise<unknown> {
10
    return element(by.id('addUser')).click();
11
  }
12

  
13
  async popupShown(): Promise<boolean> {
14
    return element(by.className('p-dialog-resizable')).isPresent();
15
  }
16

  
17
  async sendUserForm(): Promise<unknown> {
18
    const today = moment().format('YYYYMMDDHHMMSS').toString();
19
    element(by.id('username')).sendKeys(today);
20
    element(by.id('password')).sendKeys('testuser');
21
    element(by.id('userRealName')).sendKeys('testuser');
22
    element(by.cssContainingText('option', 'testing units')).click();
23
    element(by.cssContainingText('option', 'General user')).click();
24
    return element(by.buttonText('Save')).click();
25
  }
26

  
27
  async success(): Promise<boolean> {
28
    return element(by.cssContainingText('.p-toast-summary', 'Success')).isPresent();
29
  }
30

  
31
  async showUnitInsert(): Promise<unknown> {
32
    return element(by.id('addUnit')).click();
33
  }
34

  
35
  async sendUnitForm() {
36
    const today = moment().format('YYYYMMDDHHMMSS').toString();
37
    element(by.id('unitId')).sendKeys(today);
38
    element(by.id('unitDescription')).sendKeys(today);
39
    element(by.id('unitId')).sendKeys(today);
40
    element(by.id('lat')).sendKeys(10);
41
    element(by.id('lon')).sendKeys('10');
42
    element(by.buttonText('Add sensor')).click();
43
    await browser.sleep(2000);
44
    element(by.id('sensorId')).sendKeys(today);
45
    element(by.id('sensorName')).sendKeys(today)
46
    element(by.cssContainingText('option', 'test')).click();
47
    element(by.cssContainingText('option', 'Strikes (  )')).click();
48
    return element(by.buttonText('Save')).click();
49
  }
50
}
e2e/src/login/login.e2e-spec.ts
1
import {LoginPo} from './login.po';
2

  
3

  
4
describe('Login Module', () => {
5
  let loginPo: LoginPo;
6

  
7
  beforeEach(() => {
8
    loginPo = new LoginPo();
9
  });
10

  
11
  it('Check if login form displayed!', async () => {
12
    await loginPo.navigateTo();
13
    expect(await loginPo.getTitleText()).toEqual('Sign in');
14
  });
15

  
16
  it('Process login form!', async () => {
17
    await loginPo.navigateTo();
18
    await loginPo.processForm();
19
    expect(await loginPo.dashboardPresent()).toEqual(true);
20
    expect(await loginPo.loggedUser()).toEqual(' TESTINS');
21
  });
22
});
e2e/src/login/login.po.ts
1
import { browser, by, element } from 'protractor';
2

  
3
export class LoginPo {
4
  async navigateTo(): Promise<unknown> {
5
    return browser.get(browser.baseUrl);
6
  }
7

  
8
  async getTitleText(): Promise<string> {
9
    return element(by.className('login-heading')).getText();
10
  }
11

  
12
  async processForm(): Promise<unknown> {
13
    element(by.id('username')).sendKeys('testins');
14
    element(by.id('password')).sendKeys('insert');
15
    return element(by.id('loginButton')).click();
16
  }
17

  
18
  async dashboardPresent(): Promise<unknown> {
19
    return element(by.className('dashboard')).isPresent();
20
  }
21

  
22
  async loggedUser(): Promise<string> {
23
    return element(by.id('loggedUser')).getText();
24
  }
25
}
src/app/dashboard/components/dashboard.component.html
31 31
<app-position-insert-popup *ngIf="showInsertPositionPopup" [unitId]="editedUnit.unitId" [(isVisible)]="showInsertPositionPopup"></app-position-insert-popup>
32 32

  
33 33

  
34
<p-confirmDialog [style]="{width: '50vw'}" key="positionDialog" [position]="position" [baseZIndex]="10000" rejectButtonStyleClass="p-button-outlined"></p-confirmDialog>
34
<p-confirmDialog [style]="{width: '50vw'}" key="positionDialog" [position]="position" [baseZIndex]="10000" rejectButtonStyleClass="p-button-outlined" [closable]="false"></p-confirmDialog>
src/app/login/components/login.component.html
26 26
              <input type="password" formControlName="password" class="form-control" id="password" placeholder="Password"/>
27 27
            </div>
28 28
            <div class="form-group text-center mt-4">
29
              <p-button type="submit" label="Login"><i class="fas fa-sign-in-alt"></i></p-button>
29
              <p-button id="loginButton" type="submit" label="Login"><i class="fas fa-sign-in-alt"></i></p-button>
30 30
            </div>
31 31
          </form>
32 32
        </div>
src/app/shared/nav-bar/components/nav-bar.component.html
11 11
              <a class="nav-link" [routerLink]="['/dashboard']"><h2>Dashboard</h2></a>
12 12
            </li>
13 13
            <li *ngIf="loggedUser?.userInfo?.rightsId == 0" class="nav-item">
14
              <a class="nav-link" (click)="addUser()"><h2><i class="fas fa-user-plus"></i>&nbsp;Add user</h2></a>
14
              <a class="nav-link" id="addUser" (click)="addUser()"><h2><i class="fas fa-user-plus"></i>&nbsp;Add user</h2></a>
15 15
            </li>
16 16
            <li *ngIf="loggedUser?.userInfo?.rightsId == 0 || loggedUser?.userInfo?.rightsId == 1" class="nav-item">
17
              <a class="nav-link" (click)="insertUnitPopup()"><h2><i class="fas fa-folder-plus"></i>&nbsp;Add unit</h2></a>
17
              <a class="nav-link" id="addUnit" (click)="insertUnitPopup()"><h2><i class="fas fa-folder-plus"></i>&nbsp;Add unit</h2></a>
18 18
            </li>
19 19
          </ul>
20 20
          <a class="navbar-brand" href="/">
......
23 23
          </a>
24 24
          <ul class="navbar-nav right">
25 25
            <li class="nav-item">
26
              <h2 class="nav-link"><i class="fas fa-user"></i>&nbsp;<strong>{{loggedUser?.userInfo?.userName.toUpperCase()}}</strong></h2>
26
              <h2 class="nav-link" id="loggedUser"><i class="fas fa-user"></i>&nbsp;<strong>{{loggedUser?.userInfo?.userName.toUpperCase()}}</strong></h2>
27 27
            </li>
28 28
            <li class="nav-item">
29 29
              <a class='nav-link' [routerLink]="['/login']" (click)="logOut()"><h2><i class="fas fa-sign-out-alt"></i>&nbsp;Logout</h2></a>
src/app/shared/nav-bar/components/user-insert-popup/user-insert-popup.component.ts
78 78
        map((response: HttpResponse<any>) => {
79 79
          if (response.status === 200) {
80 80
            this.close();
81
            this.toastService.showSuccess();
81 82
          } else {
82 83
            this.toastService.showError(null);
83 84
          }

Také k dispozici: Unified diff