mirror of
https://github.com/openobserve/openobserve.git
synced 2026-11-05 16:10:43 +00:00
+5![github-actions[bot]](https://secure.gravatar.com/avatar/cb7b7994e594270ea25948a7bf186123?d=identicon&s=40)








ae22a74e62
#11720 Design at: https://github.com/openobserve/designs/blob/main/dashboards/ux-improvement-dialog/design.md --------- --------- Co-authored-by: ktx-vaidehi <134508096+ktx-vaidehi@users.noreply.github.com> Co-authored-by: Abhay Padamani <141122205+ktx-abhay@users.noreply.github.com> Co-authored-by: Sai Nikhil <nikhil@openobserve.ai> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: ktx-akshay <akshay.patil@kiara.tech> Co-authored-by: Bhargav <BJP232004@GMAIL.COM> Co-authored-by: ktx-mihir <mihir.patel@kiara.tech> Co-authored-by: ktx-riya <riya.kukadiya@kiara.tech> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Omkar Kesarkhane <127078473+omkarK06@users.noreply.github.com> Co-authored-by: omkark06 <omkar@zinclabs.io> Co-authored-by: ktx-vaidehi <vaidehi.akhani@kiara.tech> Co-authored-by: ktx-abhay <abhay.padamani@kiara.tech> Co-authored-by: Shrinath Rao <shnath@openobserve.ai>
274 lines
6.0 KiB
TypeScript
274 lines
6.0 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { mount } from '@vue/test-utils';
|
|
import { createI18n } from 'vue-i18n';
|
|
import DetailTable from './DetailTable.vue';
|
|
|
|
|
|
describe('DetailTable.vue', () => {
|
|
const mockRowData = {
|
|
name: 'John Doe',
|
|
email: 'john@example.com',
|
|
age: 30,
|
|
city: 'New York',
|
|
};
|
|
|
|
let i18n: any;
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
i18n = createI18n({
|
|
legacy: false,
|
|
locale: 'en',
|
|
messages: {
|
|
en: {
|
|
search: {
|
|
rowDetail: 'Row Details',
|
|
sourceName: 'Name',
|
|
sourceValue: 'Value',
|
|
},
|
|
common: {
|
|
table: 'Table',
|
|
json: 'JSON',
|
|
},
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
it('should render with default props', () => {
|
|
const wrapper = mount(DetailTable, {
|
|
global: {
|
|
plugins: [i18n, ],
|
|
stubs: {
|
|
QCard: true,
|
|
QCardSection: true,
|
|
QBtn: true,
|
|
QSeparator: true,
|
|
QTabs: true,
|
|
QTab: true,
|
|
QTabPanels: true,
|
|
QTabPanel: true,
|
|
QList: true,
|
|
QItem: true,
|
|
QItemSection: true,
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(wrapper.exists()).toBe(true);
|
|
});
|
|
|
|
it('should display row detail title', () => {
|
|
const wrapper = mount(DetailTable, {
|
|
global: {
|
|
plugins: [i18n, ],
|
|
stubs: {
|
|
QCard: false,
|
|
QCardSection: false,
|
|
QBtn: true,
|
|
QSeparator: true,
|
|
QTabs: true,
|
|
QTab: true,
|
|
QTabPanels: true,
|
|
QTabPanel: true,
|
|
QList: true,
|
|
QItem: true,
|
|
QItemSection: true,
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(wrapper.text()).toContain('Row Details');
|
|
});
|
|
|
|
it('should initialize with table tab', () => {
|
|
const wrapper = mount(DetailTable, {
|
|
global: {
|
|
plugins: [i18n, ],
|
|
stubs: {
|
|
QCard: true,
|
|
QCardSection: true,
|
|
QBtn: true,
|
|
QSeparator: true,
|
|
QTabs: true,
|
|
QTab: true,
|
|
QTabPanels: true,
|
|
QTabPanel: true,
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(wrapper.vm.tab).toBe('table');
|
|
});
|
|
|
|
it('should display "No data available" when rowData is empty', () => {
|
|
const wrapper = mount(DetailTable, {
|
|
props: {
|
|
modelValue: {},
|
|
},
|
|
global: {
|
|
plugins: [i18n, ],
|
|
stubs: {
|
|
QCard: false,
|
|
QCardSection: false,
|
|
QBtn: true,
|
|
QSeparator: true,
|
|
QTabs: false,
|
|
QTab: false,
|
|
QTabPanels: false,
|
|
QTabPanel: false,
|
|
QList: true,
|
|
QItem: true,
|
|
QItemSection: true,
|
|
},
|
|
},
|
|
});
|
|
|
|
// Since the component checks rowData.length which is undefined for objects,
|
|
// it will always show the data view. We verify that row data is empty instead.
|
|
expect(wrapper.vm.rowData).toEqual({});
|
|
});
|
|
|
|
it('should display row data when provided', () => {
|
|
const wrapper = mount(DetailTable, {
|
|
props: {
|
|
modelValue: mockRowData,
|
|
},
|
|
global: {
|
|
plugins: [i18n, ],
|
|
stubs: {
|
|
QCard: false,
|
|
QCardSection: false,
|
|
QBtn: true,
|
|
QSeparator: true,
|
|
QTabs: true,
|
|
QTab: true,
|
|
QTabPanels: false,
|
|
QTabPanel: false,
|
|
QList: false,
|
|
QItem: false,
|
|
QItemSection: false,
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(wrapper.vm.rowData).toEqual(mockRowData);
|
|
});
|
|
|
|
it('should have both table and json tabs', () => {
|
|
const wrapper = mount(DetailTable, {
|
|
global: {
|
|
plugins: [i18n, ],
|
|
stubs: {
|
|
QCard: true,
|
|
QCardSection: true,
|
|
QBtn: true,
|
|
QSeparator: true,
|
|
QTabs: false,
|
|
QTab: false,
|
|
QTabPanels: true,
|
|
QTabPanel: true,
|
|
},
|
|
},
|
|
});
|
|
|
|
const tabs = wrapper.findAll('.q-tab');
|
|
expect(tabs.length).toBeGreaterThanOrEqual(0);
|
|
});
|
|
|
|
it('should set rowData from modelValue on created', () => {
|
|
const wrapper = mount(DetailTable, {
|
|
props: {
|
|
modelValue: mockRowData,
|
|
},
|
|
global: {
|
|
plugins: [i18n, ],
|
|
stubs: {
|
|
QCard: true,
|
|
QCardSection: true,
|
|
QBtn: true,
|
|
QSeparator: true,
|
|
QTabs: true,
|
|
QTab: true,
|
|
QTabPanels: true,
|
|
QTabPanel: true,
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(wrapper.vm.rowData).toEqual(mockRowData);
|
|
});
|
|
|
|
it('should have getImageURL function available', () => {
|
|
const wrapper = mount(DetailTable, {
|
|
global: {
|
|
plugins: [i18n, ],
|
|
stubs: {
|
|
QCard: true,
|
|
QCardSection: true,
|
|
QBtn: true,
|
|
QSeparator: true,
|
|
QTabs: true,
|
|
QTab: true,
|
|
QTabPanels: true,
|
|
QTabPanel: true,
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(wrapper.vm.getImageURL).toBeDefined();
|
|
});
|
|
|
|
it('should handle complex nested data structures', () => {
|
|
const complexData = {
|
|
user: {
|
|
name: 'John',
|
|
email: 'john@example.com',
|
|
},
|
|
tags: ['tag1', 'tag2'],
|
|
count: 42,
|
|
};
|
|
|
|
const wrapper = mount(DetailTable, {
|
|
props: {
|
|
modelValue: complexData,
|
|
},
|
|
global: {
|
|
plugins: [i18n, ],
|
|
stubs: {
|
|
QCard: true,
|
|
QCardSection: true,
|
|
QBtn: true,
|
|
QSeparator: true,
|
|
QTabs: true,
|
|
QTab: true,
|
|
QTabPanels: true,
|
|
QTabPanel: true,
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(wrapper.vm.rowData).toEqual(complexData);
|
|
});
|
|
|
|
it('should render close button', () => {
|
|
const wrapper = mount(DetailTable, {
|
|
global: {
|
|
plugins: [i18n, ],
|
|
stubs: {
|
|
QCard: false,
|
|
QCardSection: false,
|
|
QSeparator: true,
|
|
QTabs: true,
|
|
QTab: true,
|
|
QTabPanels: true,
|
|
QTabPanel: true,
|
|
},
|
|
},
|
|
});
|
|
|
|
const closeButton = wrapper.findAll('button');
|
|
expect(closeButton.length).toBeGreaterThan(0);
|
|
});
|
|
});
|