client: initial integration tests

This commit is contained in:
Jesse Chan
2020-10-18 21:50:49 +08:00
parent ae536b4b75
commit f0daebbf41
15 changed files with 1396 additions and 189 deletions

View File

@@ -4,3 +4,4 @@
**/*.d.ts
/docs
coverage/
cypress/

View File

@@ -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

View File

@@ -24,5 +24,5 @@ jobs:
with:
node-version: ${{ matrix.node }}
- run: npm ci
- run: npm ci --no-optional
- run: npm run ${{ matrix.check }}

View File

@@ -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: |

View File

@@ -1,4 +1,4 @@
name: Test
name: Test backend
on:
push:
@@ -7,7 +7,7 @@ on:
pull_request:
jobs:
test:
test-backend:
runs-on: ubuntu-20.04
strategy:
@@ -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

35
.github/workflows/test-frontend.yml vendored Normal file
View File

@@ -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
.gitignore vendored
View File

@@ -62,3 +62,7 @@ out/
# Coverage reports
coverage/
# Test results
cypress/videos
cypress/screenshots

3
cypress.json Normal file
View File

@@ -0,0 +1,3 @@
{
"projectId": "akrovg"
}

View File

@@ -0,0 +1,83 @@
context('Register', () => {
beforeEach(() => {
cy.visit('http://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: 'http://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
cypress/plugins/index.js Normal file
View File

@@ -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
};

View File

@@ -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
cypress/support/index.js Normal file
View File

@@ -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
cypress/tsconfig.json Normal file
View File

@@ -0,0 +1,9 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress"]
},
"include": ["**/*.ts"],
"resolveJsonModule": true
}

1365
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -33,7 +33,8 @@
"start:production": "UPDATED_SCRIPT=start npm run deprecated-warning && npm start",
"start:watch": "UPDATED_SCRIPT=start:development:client npm run deprecated-warning && npm run start:development:client",
"test": "jest --forceExit",
"test:watch": "jest --watchAll --forceExit"
"test:watch": "jest --watchAll --forceExit",
"test:client": "FLOOD_OPTION_port=4200 start-server-and-test start 4200 'cypress run'"
},
"dependencies": {
"argon2-browser": "^1.15.2",
@@ -186,6 +187,10 @@
"yargs": "^16.0.3",
"zod": "^1.11.9"
},
"optionalDependencies": {
"cypress": "^5.4.0",
"start-server-and-test": "^1.11.5"
},
"eslintConfig": {
"extends": "react-app"
},