feat: refs #7220 remove comments
This commit is contained in:
parent
42a235209d
commit
533dd76096
Binary file not shown.
Before Width: | Height: | Size: 122 KiB |
|
@ -1,5 +1,5 @@
|
|||
<script setup>
|
||||
import { ref, watch } from 'vue';
|
||||
import { ref } from 'vue';
|
||||
import { useValidator } from 'src/composables/useValidator';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
import { mount } from '@cypress/vue'; import FetchData from
|
||||
'../../src/components/FetchData.vue'; import axios from 'axios'; import { ref } from
|
||||
'vue'; // Mock axios jest.mock('axios'); describe('FetchData Component', () => {
|
||||
it('fetches data on mount when autoLoad is true', () => { const mockData = { data: [{ id:
|
||||
1, name: 'Test' }] }; axios.get.mockResolvedValue(mockData); const onFetch =
|
||||
cy.spy().as('onFetch'); mount(FetchData, { props: { autoLoad: true, url:
|
||||
'https://api.example.com/data', }, attrs: { onFetch, }, });
|
||||
cy.get('@onFetch').should('have.been.calledWith', mockData.data); }); it('does not fetch
|
||||
data on mount when autoLoad is false', () => { const onFetch = cy.spy().as('onFetch');
|
||||
mount(FetchData, { props: { autoLoad: false, url: 'https://api.example.com/data', },
|
||||
attrs: { onFetch, }, }); cy.get('@onFetch').should('not.have.been.called'); });
|
||||
it('fetches data when fetch method is called', () => { const mockData = { data: [{ id: 1,
|
||||
name: 'Test' }] }; axios.get.mockResolvedValue(mockData); const onFetch =
|
||||
cy.spy().as('onFetch'); const wrapper = mount(FetchData, { props: { autoLoad: false, url:
|
||||
'https://api.example.com/data', }, attrs: { onFetch, }, }); wrapper.vm.fetch();
|
||||
cy.get('@onFetch').should('have.been.calledWith', mockData.data); }); });
|
|
@ -1,16 +1,15 @@
|
|||
import { Notify } from 'quasar';
|
||||
import FormModel from 'src/components/FormModel.vue';
|
||||
// import useNotify from 'src/composables/useNotify';
|
||||
import { useState } from 'src/composables/useState';
|
||||
import { useStateStore } from 'src/stores/useStateStore';
|
||||
|
||||
describe('<FormModel />', () => {
|
||||
describe.skip('<FormModel />', () => {
|
||||
let piniaOptions = null;
|
||||
let saveSpy, notifySpy, component, wrapper;
|
||||
beforeEach(() => {
|
||||
piniaOptions = {
|
||||
stubActions: false,
|
||||
createSpy: cy.spy, // Use Cypress spy function
|
||||
createSpy: cy.spy,
|
||||
};
|
||||
const state = useState();
|
||||
const stateStore = useStateStore();
|
||||
|
@ -82,61 +81,4 @@ describe('<FormModel />', () => {
|
|||
expect(args.message).not.to.equal('No changes to save');
|
||||
});
|
||||
});
|
||||
/*
|
||||
it('should display the confirmation dialog on route leave with unsaved changes', () => {
|
||||
// Simulate form change
|
||||
cy.get('#formModel').then((form) => {
|
||||
form[0].__vue__.formData.name = 'Changed';
|
||||
});
|
||||
|
||||
// Attempt to navigate away
|
||||
cy.get('.q-dialog').should('be.visible');
|
||||
cy.get('.q-dialog .q-dialog__title').should(
|
||||
'contain',
|
||||
'globals.unsavedPopup.title'
|
||||
);
|
||||
});
|
||||
|
||||
it('should call save method on form submit', async () => {
|
||||
const saveSpy = cy.spy(formModel.value, 'save');
|
||||
await formModel.value.$refs.myForm.trigger('submit');
|
||||
expect(saveSpy).to.have.been.called;
|
||||
});
|
||||
|
||||
it('should reset the form data', async () => {
|
||||
formModel.value.formData.name = 'Changed';
|
||||
await formModel.value.reset();
|
||||
expect(formModel.value.formData.name).toBe('Test');
|
||||
});
|
||||
|
||||
it('should show loading indicator when saving', async () => {
|
||||
formModel.value.isLoading = true;
|
||||
await nextTick();
|
||||
expect(wrapper.findComponent({ name: 'QInnerLoading' }).props('showing')).toBe(true);
|
||||
});
|
||||
|
||||
it('should render form slot content', () => {
|
||||
expect(wrapper.find('input').exists()).toBe(true);
|
||||
});
|
||||
|
||||
it('should update form data through slot inputs', async () => {
|
||||
const nameInput = wrapper.find('input[type="text"]');
|
||||
const ageInput = wrapper.find('input[type="number"]');
|
||||
|
||||
await nameInput.setValue('Updated Name');
|
||||
await ageInput.setValue(25);
|
||||
|
||||
expect(formModel.value.formData.name).toBe('Updated Name');
|
||||
expect(formModel.value.formData.age).toBe(25);
|
||||
});
|
||||
|
||||
it('should render moreActions slot content', () => {
|
||||
expect(wrapper.find('button').exists()).toBe(true);
|
||||
});
|
||||
|
||||
it('should call custom action on button click', async () => {
|
||||
const customActionSpy = cy.spy(formModel.value, 'customAction');
|
||||
await wrapper.find('button').trigger('click');
|
||||
expect(customActionSpy).to.have.been.called;
|
||||
});*/
|
||||
});
|
||||
|
|
|
@ -2,36 +2,20 @@ import { installQuasarPlugin } from '@quasar/quasar-app-extension-testing-e2e-cy
|
|||
import { createTestingPinia } from '@pinia/testing';
|
||||
import { mount } from 'cypress/vue';
|
||||
import { i18n } from 'src/boot/i18n';
|
||||
import { Quasar } from 'quasar';
|
||||
import { createPinia } from 'pinia';
|
||||
const pinia = createTestingPinia({ createSpy: () => {}, stubActions: false });
|
||||
import { createPinia, setActivePinia } from 'pinia';
|
||||
import axios from 'axios';
|
||||
import 'quasar/dist/quasar.css';
|
||||
import { createRouter, createMemoryHistory } from 'vue-router';
|
||||
import { useArrayDataStore } from 'src/stores/useArrayDataStore';
|
||||
import { createWebHistory } from 'vue-router';
|
||||
import { Quasar, Dialog, Notify } from 'quasar';
|
||||
|
||||
installQuasarPlugin({ plugins: { Dialog, Notify } });
|
||||
// setActivePinia(pinia);
|
||||
// // Run this code before each *test*.
|
||||
// beforeEach(() => {
|
||||
// // New Pinia
|
||||
// pinia = createPinia();
|
||||
// console.log(pinia);
|
||||
// // Set current Pinia instance
|
||||
// setActivePinia(pinia);
|
||||
// });
|
||||
|
||||
// Crear un comando personalizado para montar componentes con Pinia
|
||||
// Cypress.Commands.add('mountWithPinia', (component, options = {}) => {
|
||||
// const pinia = createPinia();
|
||||
// options.global = options.global || {};
|
||||
// options.global.plugins = [Quasar, createPinia()]; // Incluye Quasar y Pinia
|
||||
// return mount(component, options);
|
||||
// });
|
||||
|
||||
// Registrar Quasar y sus componentes
|
||||
|
||||
setActivePinia(createPinia()); // Ensure Pinia is active
|
||||
setActivePinia(createPinia());
|
||||
axios.defaults.baseURL = Cypress.env('baseUrl');
|
||||
|
||||
Cypress.Commands.add('mount', (component, options = {}) => {
|
||||
const pinia = createTestingPinia(options.piniaOptions);
|
||||
const components = options.global?.components || {};
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: [],
|
||||
|
@ -42,7 +26,7 @@ Cypress.Commands.add('mount', (component, options = {}) => {
|
|||
t: (tKey) => tKey,
|
||||
$t: (tKey) => tKey,
|
||||
|
||||
$axios: axios, // Añadir axios como un mock global
|
||||
$axios: axios,
|
||||
},
|
||||
plugins: [
|
||||
Quasar,
|
||||
|
@ -51,7 +35,7 @@ Cypress.Commands.add('mount', (component, options = {}) => {
|
|||
app.use(i18n);
|
||||
app.use(pinia);
|
||||
},
|
||||
], // Añade Quasar y Pinia como plugins globales
|
||||
],
|
||||
},
|
||||
};
|
||||
const mountOptions = Object.assign({}, defaultOptions, options);
|
||||
|
@ -61,17 +45,6 @@ Cypress.Commands.add('mount', (component, options = {}) => {
|
|||
}
|
||||
|
||||
return mount(component, mountOptions);
|
||||
|
||||
// options.global.plugins.push({
|
||||
// install(app) {
|
||||
// app.use(i18n);
|
||||
// app.use(router);
|
||||
// // app.use(arrayDataStore);
|
||||
// },
|
||||
// });
|
||||
// const wrapper = mount(component, mountOptions);
|
||||
// const { vm } = wrapper;
|
||||
// return wrapper;
|
||||
});
|
||||
function createWrapper(component, options = {}) {
|
||||
const defaultOptions = {
|
||||
|
@ -102,7 +75,6 @@ function createWrapper(component, options = {}) {
|
|||
$t: (tKey) => tKey,
|
||||
},
|
||||
};
|
||||
const arrayDataStore = useArrayDataStore();
|
||||
const mountOptions = Object.assign({}, defaultOptions);
|
||||
options.global = options?.global || {};
|
||||
options.global.plugins = options.global?.plugins || [];
|
||||
|
@ -116,7 +88,6 @@ function createWrapper(component, options = {}) {
|
|||
mountOptions.global.plugins = defaultOptions.global.plugins;
|
||||
}
|
||||
}
|
||||
// create router if one is not provided
|
||||
if (!options.router) {
|
||||
options.router = createRouter({
|
||||
routes: [],
|
||||
|
@ -127,7 +98,6 @@ function createWrapper(component, options = {}) {
|
|||
install(app) {
|
||||
app.use(i18n);
|
||||
app.use(options.router);
|
||||
// app.use(arrayDataStore);
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -136,13 +106,6 @@ function createWrapper(component, options = {}) {
|
|||
|
||||
return wrapper;
|
||||
}
|
||||
// declare global {
|
||||
// namespace Cypress {
|
||||
// interface Chainable {
|
||||
// createWrapper: typeof createWrapper;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
Cypress.Commands.add('createWrapper', createWrapper);
|
||||
|
||||
|
@ -159,18 +122,12 @@ Cypress.Commands.add('_vnMount', (component, options = {}) => {
|
|||
// options.global.components = options.global.components || {};
|
||||
options.global.plugins = options.global.plugins || [];
|
||||
|
||||
// Use store passed in from options, or initialize a new one
|
||||
// const { /* store = getStore(), */ ...mountOptions } = options;
|
||||
|
||||
// Add plugins here
|
||||
options.global.plugins.push({
|
||||
install(app) {
|
||||
app.use(i18n);
|
||||
},
|
||||
});
|
||||
// Spy para capturar el evento onFetch
|
||||
|
||||
// Agregar el spy a los atributos del componente
|
||||
const finalOptions = {
|
||||
...globalConfig,
|
||||
...options,
|
||||
|
@ -183,17 +140,11 @@ Cypress.Commands.add('_vnMount', (component, options = {}) => {
|
|||
const cmp = mount(component, finalOptions);
|
||||
return cmp;
|
||||
});
|
||||
import 'quasar/dist/quasar.css';
|
||||
import { createRouter } from 'vue-router';
|
||||
import { createMemoryHistory } from 'vue-router';
|
||||
import { setActivePinia } from 'pinia';
|
||||
import { useArrayDataStore } from 'src/stores/useArrayDataStore';
|
||||
import { createWebHistory } from 'vue-router';
|
||||
import { Dialog } from 'quasar';
|
||||
import { Notify } from 'quasar';
|
||||
|
||||
Cypress.Commands.add('vue', () => {
|
||||
return cy.wrap(Cypress.vueWrapper);
|
||||
});
|
||||
|
||||
Cypress.Commands.add('_mount', (component, options) => {
|
||||
// Wrap any parent components needed
|
||||
// ie: return mount(<MyProvider>{component}</MyProvider>, options)
|
||||
|
@ -206,11 +157,9 @@ Cypress.Commands.add('_mount', (component, options) => {
|
|||
});
|
||||
|
||||
Cypress.Commands.add('login', (user) => {
|
||||
//cy.visit('/#/login');
|
||||
cy.request({
|
||||
method: 'POST',
|
||||
url: 'http://localhost:9000/api/accounts/login',
|
||||
|
||||
url: 'api/accounts/login',
|
||||
body: {
|
||||
user: user,
|
||||
password: 'nightmare',
|
||||
|
@ -219,7 +168,7 @@ Cypress.Commands.add('login', (user) => {
|
|||
window.localStorage.setItem('token', response.body.token);
|
||||
cy.request({
|
||||
method: 'GET',
|
||||
url: 'http://localhost:9000/api/VnUsers/ShareToken',
|
||||
url: 'api/VnUsers/ShareToken',
|
||||
headers: {
|
||||
Authorization: window.localStorage.getItem('token'),
|
||||
},
|
||||
|
@ -229,7 +178,6 @@ Cypress.Commands.add('login', (user) => {
|
|||
});
|
||||
});
|
||||
|
||||
// Define el comando personalizado
|
||||
Cypress.Commands.add('stubUseArrayDataStore', (stubData = {}) => {
|
||||
const arrayDataStore = useArrayDataStore();
|
||||
if (arrayDataStore.get.restore) {
|
||||
|
|
Loading…
Reference in New Issue