Add e2e test for app with cypress

This commit is contained in:
Marcus Eide
2020-03-27 14:07:26 +01:00
parent a17f237b75
commit 990671df9b
6 changed files with 575 additions and 56 deletions
+5
View File
@@ -0,0 +1,5 @@
{
"baseUrl": "http://localhost:3000",
"fixturesFolder": false,
"pluginsFile": false
}
+12
View File
@@ -0,0 +1,12 @@
{
"plugins": ["cypress"],
"extends": ["plugin:cypress/recommended"],
"rules": {
"jest/expect-expect": [
"error",
{
"assertFunctionNames": ["expect", "cy.contains"]
}
]
}
}
+63
View File
@@ -0,0 +1,63 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
describe('App', () => {
it('should render the welcome page', () => {
cy.visit('/');
cy.contains('Welcome to Backstage');
cy.contains('Getting Started');
cy.contains('Quick Links');
cy.contains('APIs');
});
it('should display support info when clicking the button', () => {
cy.visit('/');
cy.findByTestId('support-button').click({ force: true });
cy.contains('#backstage');
});
it('should display error message when triggering it', () => {
cy.visit('/');
cy.findByTestId('error-button').click({ force: true });
cy.contains('Error: Oh no!');
cy.findByTestId('error-button-close').click({ force: true });
});
it('should be able to login and logout', () => {
const name = 'test-name';
Cypress.on('window:before:load', win => {
win.fetch = cy.stub().resolves({
status: 200,
json: () => ({ username: 'test name', token: 'token', name }),
});
});
cy.visit('/');
cy.get('a[href="/login"]').click({ force: true });
cy.url().should('include', '/login');
cy.contains('Welcome, guest!');
cy.contains('Username')
.get('input[name=github-username-tf]')
.type(name, { force: true });
cy.contains('Token')
.get('input[name=github-auth-tf]')
.type('password', { force: true });
cy.findByTestId('github-auth-button').click({ force: true });
cy.contains(`Welcome, ${name}!`);
cy.contains('Logout').click({ force: true });
cy.contains('Welcome, guest!');
});
});
+16
View File
@@ -0,0 +1,16 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import '@testing-library/cypress/add-commands';
+12 -2
View File
@@ -28,7 +28,11 @@
"start": "backstage-cli app:serve",
"build": "backstage-cli app:build",
"test": "backstage-cli test",
"lint": "backstage-cli lint"
"test:e2e": "start-server-and-test start http://localhost:3000 cy:dev",
"test:e2e:ci": "start-server-and-test start http://localhost:3000 cy:run",
"lint": "backstage-cli lint",
"cy:dev": "cypress open",
"cy:run": "cypress run"
},
"browserslist": {
"production": [
@@ -42,5 +46,11 @@
"last 1 safari version"
]
},
"license": "Apache-2.0"
"license": "Apache-2.0",
"devDependencies": {
"@testing-library/cypress": "^6.0.0",
"@types/jquery": "^3.3.34",
"cypress": "^4.2.0",
"start-server-and-test": "^1.10.11"
}
}