101 lines
2.9 KiB
JavaScript
101 lines
2.9 KiB
JavaScript
// VnSelectEnum.spec.js
|
|
import VnSelectEnum from 'src/components/common/VnSelectEnum.vue';
|
|
|
|
describe.only('<VnSelectEnum />', () => {
|
|
beforeEach(() => {
|
|
cy.stub(window, 'axios').as('axiosStub');
|
|
});
|
|
|
|
it('renders without errors', () => {
|
|
cy.createWrapper(VnSelectEnum, {
|
|
props: {
|
|
table: 'test_table',
|
|
column: 'test_column',
|
|
},
|
|
});
|
|
cy.getComponent('VnSelect').should('exist');
|
|
});
|
|
|
|
it('loads enum options from API on mount', () => {
|
|
const mockEnumData = ['OPTION1', 'OPTION2'];
|
|
cy.get('@axiosStub').resolves({ data: mockEnumData });
|
|
|
|
cy.createWrapper(VnSelectEnum, {
|
|
props: {
|
|
table: 'test_table',
|
|
column: 'test_column',
|
|
},
|
|
});
|
|
|
|
cy.get('@axiosStub').should('have.been.calledWith', {
|
|
method: 'get',
|
|
url: '/api/enums/vn/test_table/test_column',
|
|
});
|
|
});
|
|
|
|
it('uses custom schema when provided', () => {
|
|
cy.createWrapper(VnSelectEnum, {
|
|
props: {
|
|
schema: 'custom',
|
|
table: 'test_table',
|
|
column: 'test_column',
|
|
},
|
|
});
|
|
|
|
cy.get('@axiosStub').should('have.been.calledWith', {
|
|
method: 'get',
|
|
url: '/api/enums/custom/test_table/test_column',
|
|
});
|
|
});
|
|
|
|
it('uses translation function when provided', () => {
|
|
const translation = (value) => `Translated ${value}`;
|
|
const mockEnumData = ['OPTION1'];
|
|
cy.get('@axiosStub').resolves({ data: mockEnumData });
|
|
|
|
cy.createWrapper(VnSelectEnum, {
|
|
props: {
|
|
table: 'test_table',
|
|
column: 'test_column',
|
|
translation,
|
|
},
|
|
});
|
|
|
|
cy.getComponent('VnSelect')
|
|
.invoke('props', 'options')
|
|
.should('deep.equal', [{ label: 'Translated OPTION1', value: 'OPTION1' }]);
|
|
});
|
|
|
|
it('uses default options when provided', () => {
|
|
const defaultOptions = [
|
|
{ label: 'Default 1', value: 'DEFAULT1' },
|
|
{ label: 'Default 2', value: 'DEFAULT2' },
|
|
];
|
|
|
|
cy.createWrapper(VnSelectEnum, {
|
|
props: {
|
|
table: 'test_table',
|
|
column: 'test_column',
|
|
defaultOptions,
|
|
},
|
|
});
|
|
|
|
cy.getComponent('VnSelect')
|
|
.invoke('props', 'options')
|
|
.should('deep.equal', defaultOptions);
|
|
});
|
|
|
|
it('handles API error gracefully', () => {
|
|
cy.get('@axiosStub').rejects(new Error('API Error'));
|
|
|
|
cy.createWrapper(VnSelectEnum, {
|
|
props: {
|
|
table: 'test_table',
|
|
column: 'test_column',
|
|
},
|
|
});
|
|
|
|
cy.getComponent('VnSelect').invoke('props', 'options').should('deep.equal', []);
|
|
});
|
|
});
|