Skip to content

Commit

Permalink
client: initial integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jesec committed Oct 18, 2020
1 parent ae536b4 commit f0daebb
Show file tree
Hide file tree
Showing 15 changed files with 1,417 additions and 210 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
**/*.d.ts
/docs
coverage/
cypress/
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ jobs:
with:
node-version: ${{ matrix.node }}

- run: npm ci
- run: npm ci --no-optional
- run: npm run build
- run: npm run start -- --help
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ jobs:
with:
node-version: ${{ matrix.node }}

- run: npm ci
- run: npm ci --no-optional
- run: npm run ${{ matrix.check }}
2 changes: 1 addition & 1 deletion .github/workflows/publish-rolling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
node-version: ${{ matrix.node }}
registry-url: 'https://registry.npmjs.org'

- run: npm ci
- run: npm ci --no-optional

- name: Tag rolling release
run: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test
name: Test backend

on:
push:
Expand All @@ -7,7 +7,7 @@ on:
pull_request:

jobs:
test:
test-backend:
runs-on: ubuntu-20.04

strategy:
Expand All @@ -25,7 +25,7 @@ jobs:

- run: sudo apt-get install -y rtorrent

- run: npm ci
- run: npm ci --no-optional
- run: npm run build
- run: npm run start -- --help
- run: npm test
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/test-frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test frontend

on:
push:
branches-ignore:
- 'integration/**'
pull_request:

jobs:
test-frontend:
runs-on: ubuntu-16.04

steps:
- uses: actions/checkout@v2

- name: Use Node.js 14
uses: actions/setup-node@v1
with:
node-version: 14

- run: sudo apt-get install -y rtorrent

- run: sudo npm i -g wait-on
- run: npm ci
- run: npm run build

- run: npm run start -- -p 4200 &
- run: wait-on tcp:4200

- uses: cypress-io/github-action@v2
with:
record: true
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ out/

# Coverage reports
coverage/

# Test results
cypress/videos
cypress/screenshots
3 changes: 3 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"projectId": "akrovg"
}
83 changes: 83 additions & 0 deletions cypress/integration/register.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
context('Register', () => {
beforeEach(() => {
cy.visit('https://127.0.0.1:4200/register');
cy.url().should('include', 'register');
});

it('Client selection menu', () => {
cy.get('.select').click();
cy.get('.context-menu').should('be.visible');
cy.get('.select__item').contains('rTorrent').click();
cy.get('.context-menu').should('not.be.visible');
cy.get('.input[name="client"]').should('have.value', 'rTorrent');
});

it('Connection type selection', () => {
cy.get('.toggle-input__label').contains('TCP').click();
cy.get('.toggle-input__element[value="tcp"]').should('be.checked');
cy.get('.toggle-input__element[value="socket"]').should('not.be.checked');
cy.get('.input--text[name="host"]').should('be.visible');
cy.get('.input--text[name="port"]').should('be.visible');
cy.get('.input--text[name="socket"]').should('not.be.visible');

cy.get('.toggle-input__label').contains('Socket').click();
cy.get('.toggle-input__element[value="tcp"]').should('not.be.checked');
cy.get('.toggle-input__element[value="socket"]').should('be.checked');
cy.get('.input--text[name="host"]').should('not.be.visible');
cy.get('.input--text[name="port"]').should('not.be.visible');
cy.get('.input--text[name="socket"]').should('be.visible');
});

it('Register without username', () => {
cy.get('.input[name="password"]').type('test');
cy.get('.select').click();
cy.get('.select__item').contains('rTorrent').click();
cy.get('.toggle-input__label').contains('Socket').click();
cy.get('.input--text[name="socket"]').type('/data/rtorrent.sock');
cy.get('.button[type="submit"]').click();
cy.get('.application__view--auth-form').should('be.visible');
cy.get('.application__content').should('not.be.visible');
cy.get('.application__loading-overlay').should('not.be.visible');
});

it('Register without password', () => {
cy.get('.input[name="username"]').type('test');
cy.get('.select').click();
cy.get('.select__item').contains('rTorrent').click();
cy.get('.toggle-input__label').contains('TCP').click();
cy.get('.input--text[name="host"]').type('127.0.0.1');
cy.get('.input--text[name="port"]').type('5000');
cy.get('.button[type="submit"]').click();
cy.get('.application__view--auth-form').should('be.visible');
cy.get('.application__content').should('not.be.visible');
cy.get('.application__loading-overlay').should('not.be.visible');
});

it('Register without connection settings', () => {
cy.get('.input[name="username"]').type('test');
cy.get('.input[name="password"]').type('test');
cy.get('.button[type="submit"]').click();
cy.get('.application__view--auth-form').should('be.visible');
cy.get('.application__content').should('not.be.visible');
cy.get('.application__loading-overlay').should('not.be.visible');
});

it('Register with socket connection settings', () => {
cy.get('.input[name="username"]').type('test');
cy.get('.input[name="password"]').type('test');
cy.get('.select').click();
cy.get('.select__item').contains('rTorrent').click();
cy.get('.toggle-input__label').contains('Socket').click();
cy.get('.input--text[name="socket"]').type('/data/rtorrent.sock');

cy.server();
cy.route({method: 'POST', url: 'https://127.0.0.1:4200/api/auth/register', response: {}, status: 403}).as(
'register-request',
);

cy.get('.button[type="submit"]').click();

cy.get('.application__view--auth-form').should('not.be.visible');
cy.get('.application__content').should('be.visible');
});
});
21 changes: 21 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
};
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands';

// Alternatively you can use CommonJS syntax:
// require('./commands')
9 changes: 9 additions & 0 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress"]
},
"include": ["**/*.ts"],
"resolveJsonModule": true
}
Loading

0 comments on commit f0daebb

Please sign in to comment.