0
0
Fork 0

Updated cypress

This commit is contained in:
Joan Sanchez 2022-12-21 09:19:29 +01:00
parent 6744c34c93
commit 19e1749d1e
14 changed files with 90 additions and 136 deletions

11
.vscode/settings.json vendored
View File

@ -4,5 +4,14 @@
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": ["source.fixAll.eslint"],
"eslint.validate": ["javascript", "javascriptreact", "typescript", "vue"]
"eslint.validate": ["javascript", "javascriptreact", "typescript", "vue"],
"json.schemas": [
{
"fileMatch": ["cypress.json"],
"url": "https://on.cypress.io/cypress.schema.json"
}
],
"[vue]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}

View File

@ -1,9 +1,21 @@
const { defineConfig } = require("cypress");
const { defineConfig } = require('cypress');
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
e2e: {
baseUrl: 'http://localhost:8080/',
fixturesFolder: 'tests/cypress/fixtures',
screenshotsFolder: 'tests/cypress/screenshots',
supportFile: 'tests/cypress/support/index.js',
videosFolder: 'tests/cypress/videos',
video: true,
specPattern: 'tests/cypress/integration/*.spec.js',
component: {
componentFolder: 'src',
testFiles: '**/*.spec.js',
supportFile: 'tests/cypress/support/unit.js',
},
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
},
});

View File

@ -1,5 +0,0 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}

View File

@ -1,25 +0,0 @@
// ***********************************************
// 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) => { ... })

View File

@ -1,20 +0,0 @@
// ***********************************************************
// This example support/e2e.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')

14
package-lock.json generated
View File

@ -22,7 +22,7 @@
"@pinia/testing": "^0.0.14",
"@quasar/app-vite": "^1.1.3",
"autoprefixer": "^10.4.13",
"cypress": "^12.1.0",
"cypress": "^12.2.0",
"eslint": "^8.30.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-vue": "^9.8.0",
@ -1846,9 +1846,9 @@
"integrity": "sha512-Z1PhmomIfypOpoMjRQB70jfvy/wxT50qW08YXO5lMIJkrdq4yOTR+AW7FqutScmB9NkLwxo+jU+kZLbofZZq/w=="
},
"node_modules/cypress": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/cypress/-/cypress-12.1.0.tgz",
"integrity": "sha512-7fz8N84uhN1+ePNDsfQvoWEl4P3/VGKKmAg+bJQFY4onhA37Ys+6oBkGbNdwGeC7n2QqibNVPhk8x3YuQLwzfw==",
"version": "12.2.0",
"resolved": "https://registry.npmjs.org/cypress/-/cypress-12.2.0.tgz",
"integrity": "sha512-kvl95ri95KK8mAy++tEU/wUgzAOMiIciZSL97LQvnOinb532m7dGvwN0mDSIGbOd71RREtmT9o4h088RjK5pKw==",
"dev": true,
"hasInstallScript": true,
"dependencies": {
@ -7606,9 +7606,9 @@
"integrity": "sha512-Z1PhmomIfypOpoMjRQB70jfvy/wxT50qW08YXO5lMIJkrdq4yOTR+AW7FqutScmB9NkLwxo+jU+kZLbofZZq/w=="
},
"cypress": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/cypress/-/cypress-12.1.0.tgz",
"integrity": "sha512-7fz8N84uhN1+ePNDsfQvoWEl4P3/VGKKmAg+bJQFY4onhA37Ys+6oBkGbNdwGeC7n2QqibNVPhk8x3YuQLwzfw==",
"version": "12.2.0",
"resolved": "https://registry.npmjs.org/cypress/-/cypress-12.2.0.tgz",
"integrity": "sha512-kvl95ri95KK8mAy++tEU/wUgzAOMiIciZSL97LQvnOinb532m7dGvwN0mDSIGbOd71RREtmT9o4h088RjK5pKw==",
"dev": true,
"requires": {
"@cypress/request": "^2.88.10",

View File

@ -8,7 +8,8 @@
"scripts": {
"lint": "eslint --ext .js,.vue ./",
"format": "prettier --write \"**/*.{js,vue,scss,html,md,json}\" --ignore-path .gitignore",
"test:e2e": "cypress run --browser chromium"
"test:e2e": "cypress open",
"test:e2e:ci": "cypress run --browser chromium"
},
"dependencies": {
"@quasar/extras": "^1.15.8",
@ -25,7 +26,7 @@
"@pinia/testing": "^0.0.14",
"@quasar/app-vite": "^1.1.3",
"autoprefixer": "^10.4.13",
"cypress": "^12.1.0",
"cypress": "^12.2.0",
"eslint": "^8.30.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-vue": "^9.8.0",

View File

@ -27,7 +27,6 @@ $color-spacer-light: rgba(255, 255, 255, 0.12);
$color-spacer: rgba(255, 255, 255, 0.3);
$border-thin-light: 1px solid $color-spacer-light;
$separator-dark-color: rgba(0, 0, 0, 0.12);
$dark-shadow-color: #000;
$layout-shadow-dark: 0 0 10px 2px rgba(0, 0, 0, 0.2), 0 0px 10px rgba(0, 0, 0, 0.24);

View File

@ -21,9 +21,14 @@ const userLocale = computed({
if (value === 'en') value = 'en-GB';
import(`quasar/lang/${value}`).then((language) => {
Quasar.lang.set(language.default);
});
// FIXME: Dynamic imports from absolute paths are not compatible with vite:
// https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations
try {
const langList = import.meta.glob('../../node_modules/quasar/lang/*.mjs');
langList[`../../node_modules/quasar/lang/${value}.mjs`]().then((lang) => {
Quasar.lang.set(lang.default);
});
} catch (error) {}
},
});
@ -41,26 +46,28 @@ const password = ref('');
const keepLogin = ref(true);
async function onSubmit() {
const { data } = await axios.post('Accounts/login', {
user: username.value,
password: password.value,
});
try {
const { data } = await axios.post('Accounts/login', {
user: username.value,
password: password.value,
});
if (!data) return;
if (!data) return;
await session.login(data.token, keepLogin.value);
await session.login(data.token, keepLogin.value);
quasar.notify({
message: t('login.loginSuccess'),
type: 'positive',
});
quasar.notify({
message: t('login.loginSuccess'),
type: 'positive',
});
const currentRoute = router.currentRoute.value;
if (currentRoute.query && currentRoute.query.redirect) {
router.push(currentRoute.query.redirect);
} else {
router.push({ name: 'Dashboard' });
}
const currentRoute = router.currentRoute.value;
if (currentRoute.query && currentRoute.query.redirect) {
router.push(currentRoute.query.redirect);
} else {
router.push({ name: 'Dashboard' });
}
} catch (error) {}
}
</script>
@ -70,7 +77,15 @@ async function onSubmit() {
<q-page id="login">
<q-page-sticky position="top-right">
<q-toolbar>
<q-btn :label="t('globals.language')" icon="translate" color="primary" size="sm" flat rounded>
<q-btn
id="switchLanguage"
:label="t('globals.language')"
icon="translate"
color="primary"
size="sm"
flat
rounded
>
<q-menu auto-close>
<q-list dense>
<q-item @click="userLocale = 'en'" :active="userLocale == 'en'" v-ripple clickable>

View File

@ -2,6 +2,8 @@
describe('Login', () => {
beforeEach(() => {
cy.visit('/#/login');
cy.get('#switchLanguage').click();
cy.get('div.q-menu div.q-item:nth-child(1)').click();
});
it('should fail to log in using wrong user', () => {
@ -36,7 +38,7 @@ describe('Login', () => {
cy.get('#logout').click();
cy.window().its('localStorage').invoke('getItem', 'token').should('not.exist');
cy.url().should('contain', '/login');
})
});
it(`should get redirected to dashboard since employee can't create tickets`, () => {
cy.visit('/#/ticket/create', { failOnStatusCode: false });
@ -45,7 +47,7 @@ describe('Login', () => {
cy.get('input[aria-label="Password"]').type('nightmare');
cy.get('button[type="submit"]').click();
cy.url().should('contain', '/dashboard');
})
});
// ticket creation is not yet implemented, use this test once it is
// it(`should get redirected to ticket creation after login since salesPerson can do it`, () => {
@ -56,4 +58,4 @@ describe('Login', () => {
// cy.get('button[type="submit"]').click();
// cy.url().should('contain', '/#/ticket/create');
// })
});
});

View File

@ -1,8 +1,9 @@
describe('TicketBoxing', () => {
/// <reference types="cypress" />
xdescribe('TicketBoxing', () => {
beforeEach(() => {
const ticketId = 1;
cy.viewport(1280, 720)
cy.login('developer')
cy.viewport(1280, 720);
cy.login('developer');
cy.visit(`/#/ticket/${ticketId}/boxing`);
});
@ -23,16 +24,11 @@ describe('TicketBoxing', () => {
method: 'GET',
url: '/api/Boxings/*',
},
[
"2022-01-01T01-01-00.mp4",
"2022-02-02T02-02-00.mp4",
"2022-03-03T03-03-00.mp4",
]
['2022-01-01T01-01-00.mp4', '2022-02-02T02-02-00.mp4', '2022-03-03T03-03-00.mp4']
).as('getVideoList');
cy.get('.q-list > :nth-child(3)').click();
cy.get('.q-list > :nth-child(1)').should('be.visible');
cy.get('.q-list > :nth-child(2)').should('be.visible');
});
});

View File

@ -1,31 +0,0 @@
/// <reference types="cypress" />
/* eslint-env node */
// ***********************************************************
// 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)
// cypress/plugins/index.js
// const {injectDevServer} = require('@quasar/quasar-app-extension-testing-e2e-cypress/cct-dev-server');
// /**
// * @type {Cypress.PluginConfig}
// */
module.exports = async (on, config) => {
// // Enable component testing, you can safely remove this
// // if you don't plan to use Cypress for unit tests
// if (config.testingType === 'component') {
// await injectDevServer(on, config);
// }
return config;
};

View File

@ -26,7 +26,7 @@
// DO NOT REMOVE
// Imports Quasar Cypress AE predefined commands
import { registerCommands } from '@quasar/quasar-app-extension-testing-e2e-cypress';
// import { registerCommands } from '@quasar/quasar-app-extension-testing-e2e-cypress';
Cypress.Commands.add('login', (user) => {
cy.visit('/#/login');
cy.request({
@ -34,10 +34,10 @@ Cypress.Commands.add('login', (user) => {
url: '/api/accounts/login',
body: {
user: user,
password: 'nightmare'
}
}).then(response => {
password: 'nightmare',
},
}).then((response) => {
window.localStorage.setItem('token', response.body.token);
})
})
registerCommands();
});
});
// registerCommands();

View File

@ -14,3 +14,4 @@
// ***********************************************************
import './commands';