99 lines
2.6 KiB
JavaScript
99 lines
2.6 KiB
JavaScript
import CardSummary from 'src/components/ui/CardSummary.vue';
|
|
import { createRouter, createWebHistory } from 'vue-router';
|
|
describe.skip('<CardSummary />', () => {
|
|
let router, wrapper;
|
|
|
|
beforeEach(() => {
|
|
router = createRouter({
|
|
history: createWebHistory(),
|
|
routes: [
|
|
{
|
|
path: '/test',
|
|
name: 'test',
|
|
meta: { moduleName: 'test' },
|
|
},
|
|
{
|
|
path: '/test/summary',
|
|
name: 'testSummary',
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
const mountComponent = (opt) => {
|
|
opt = {
|
|
props: {
|
|
url: 'test-url',
|
|
dataKey: 'test-key',
|
|
...opt,
|
|
},
|
|
};
|
|
cy.createWrapper(CardSummary, opt);
|
|
};
|
|
|
|
it('shows skeleton while loading', () => {
|
|
mountComponent();
|
|
cy.get('.cardSummary').find('SkeletonSummary').should('exist');
|
|
});
|
|
|
|
it('displays entity data correctly', () => {
|
|
const mockEntity = {
|
|
id: 1,
|
|
name: 'Test Entity',
|
|
};
|
|
|
|
mountComponent();
|
|
// Intercept API call
|
|
cy.intercept('GET', 'test-url*', {
|
|
body: mockEntity,
|
|
}).as('fetchData');
|
|
|
|
cy.wait('@fetchData');
|
|
cy.get('.summaryHeader').find('VnLv').should('have.prop', 'label', '1 -');
|
|
cy.get('.summaryHeader').find('VnLv').should('have.prop', 'value', 'Test Entity');
|
|
});
|
|
|
|
it('shows redirect icon when not in summary route', () => {
|
|
router.push('/test');
|
|
mountComponent({
|
|
entityId: 1,
|
|
moduleName: 'test',
|
|
});
|
|
|
|
cy.get('.header.link')
|
|
.should('exist')
|
|
.should('have.attr', 'href')
|
|
.and('include', '/test/summary');
|
|
});
|
|
|
|
it('emits onFetch event after data fetch', () => {
|
|
const mockEntity = { id: 1, name: 'Test' };
|
|
const onFetchSpy = cy.spy().as('onFetchSpy');
|
|
|
|
mountComponent({
|
|
onFetch: onFetchSpy,
|
|
});
|
|
|
|
cy.intercept('GET', 'test-url*', {
|
|
body: mockEntity,
|
|
}).as('fetchData');
|
|
|
|
cy.wait('@fetchData');
|
|
cy.get('@onFetchSpy').should('have.been.calledWith', mockEntity);
|
|
});
|
|
|
|
it('updates when props change', () => {
|
|
mountComponent();
|
|
|
|
cy.intercept('GET', 'new-url*').as('newFetch');
|
|
|
|
// Change props
|
|
cy.get('@wrapper').invoke('setProps', {
|
|
url: 'new-url',
|
|
filter: { test: true },
|
|
});
|
|
|
|
cy.wait('@newFetch');
|
|
});
|
|
});
|