debian-mirror-gitlab/spec/frontend/observability/observability_app_spec.js

199 lines
5.8 KiB
JavaScript
Raw Normal View History

2023-01-13 00:05:48 +05:30
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import ObservabilityApp from '~/observability/components/observability_app.vue';
2023-03-04 22:38:38 +05:30
import ObservabilitySkeleton from '~/observability/components/skeleton/index.vue';
2023-05-27 22:25:52 +05:30
import {
MESSAGE_EVENT_TYPE,
INLINE_EMBED_DIMENSIONS,
FULL_APP_DIMENSIONS,
SKELETON_VARIANT_EMBED,
} from '~/observability/constants';
2023-03-04 22:38:38 +05:30
import { darkModeEnabled } from '~/lib/utils/color_utils';
jest.mock('~/lib/utils/color_utils');
2023-01-13 00:05:48 +05:30
2023-05-27 22:25:52 +05:30
describe('ObservabilityApp', () => {
2023-01-13 00:05:48 +05:30
let wrapper;
2023-05-27 22:25:52 +05:30
2023-01-13 00:05:48 +05:30
const $route = {
pathname: 'https://gitlab.com/gitlab-org/',
2023-03-17 16:20:25 +05:30
path: 'https://gitlab.com/gitlab-org/-/observability/dashboards',
2023-01-13 00:05:48 +05:30
query: { otherQuery: 100 },
};
2023-03-04 22:38:38 +05:30
const mockHandleSkeleton = jest.fn();
2023-01-13 00:05:48 +05:30
const findIframe = () => wrapper.findByTestId('observability-ui-iframe');
const TEST_IFRAME_SRC = 'https://observe.gitlab.com/9970/?groupId=14485840';
2023-05-27 22:25:52 +05:30
const TEST_USERNAME = 'test-user';
2023-03-17 16:20:25 +05:30
2023-05-27 22:25:52 +05:30
const mountComponent = (props) => {
2023-01-13 00:05:48 +05:30
wrapper = shallowMountExtended(ObservabilityApp, {
propsData: {
observabilityIframeSrc: TEST_IFRAME_SRC,
2023-05-27 22:25:52 +05:30
...props,
2023-01-13 00:05:48 +05:30
},
2023-03-04 22:38:38 +05:30
stubs: {
'observability-skeleton': ObservabilitySkeleton,
},
2023-01-13 00:05:48 +05:30
mocks: {
2023-05-27 22:25:52 +05:30
$route,
2023-01-13 00:05:48 +05:30
},
});
};
2023-03-04 22:38:38 +05:30
const dispatchMessageEvent = (message) =>
window.dispatchEvent(new MessageEvent('message', message));
2023-05-27 22:25:52 +05:30
beforeEach(() => {
gon.current_username = TEST_USERNAME;
2023-01-13 00:05:48 +05:30
});
2023-03-04 22:38:38 +05:30
describe('iframe src', () => {
it('should render an iframe with observabilityIframeSrc, decorated with light theme and username', () => {
darkModeEnabled.mockReturnValueOnce(false);
mountComponent();
const iframe = findIframe();
expect(iframe.exists()).toBe(true);
expect(iframe.attributes('src')).toBe(
`${TEST_IFRAME_SRC}&theme=light&username=${TEST_USERNAME}`,
);
});
it('should render an iframe with observabilityIframeSrc decorated with dark theme and username', () => {
darkModeEnabled.mockReturnValueOnce(true);
mountComponent();
const iframe = findIframe();
expect(iframe.exists()).toBe(true);
expect(iframe.attributes('src')).toBe(
`${TEST_IFRAME_SRC}&theme=dark&username=${TEST_USERNAME}`,
);
});
2023-01-13 00:05:48 +05:30
});
2023-03-04 22:38:38 +05:30
describe('iframe sandbox', () => {
it('should render an iframe with sandbox attributes', () => {
mountComponent();
const iframe = findIframe();
expect(iframe.exists()).toBe(true);
expect(iframe.attributes('sandbox')).toBe('allow-same-origin allow-forms allow-scripts');
});
2023-01-13 00:05:48 +05:30
});
2023-05-27 22:25:52 +05:30
describe('iframe kiosk query param', () => {
it('when inlineEmbed, it should set the proper kiosk query parameter', () => {
mountComponent({
inlineEmbed: true,
2023-03-04 22:38:38 +05:30
});
2023-05-27 22:25:52 +05:30
const iframe = findIframe();
expect(iframe.attributes('src')).toBe(
`${TEST_IFRAME_SRC}&theme=light&username=${TEST_USERNAME}&kiosk=inline-embed`,
);
2023-03-04 22:38:38 +05:30
});
2023-05-27 22:25:52 +05:30
});
2023-03-04 22:38:38 +05:30
2023-05-27 22:25:52 +05:30
describe('iframe size', () => {
it('should set the specified size', () => {
mountComponent({
height: INLINE_EMBED_DIMENSIONS.HEIGHT,
width: INLINE_EMBED_DIMENSIONS.WIDTH,
});
const iframe = findIframe();
expect(iframe.attributes('width')).toBe(INLINE_EMBED_DIMENSIONS.WIDTH);
expect(iframe.attributes('height')).toBe(INLINE_EMBED_DIMENSIONS.HEIGHT);
});
it('should fallback to default size', () => {
mountComponent({});
const iframe = findIframe();
2023-03-04 22:38:38 +05:30
2023-05-27 22:25:52 +05:30
expect(iframe.attributes('width')).toBe(FULL_APP_DIMENSIONS.WIDTH);
expect(iframe.attributes('height')).toBe(FULL_APP_DIMENSIONS.HEIGHT);
});
});
describe('skeleton variant', () => {
it('sets the specified skeleton variant', () => {
mountComponent({ skeletonVariant: SKELETON_VARIANT_EMBED });
const props = wrapper.findComponent(ObservabilitySkeleton).props();
expect(props.variant).toBe(SKELETON_VARIANT_EMBED);
});
it('should have a default skeleton variant', () => {
mountComponent();
const props = wrapper.findComponent(ObservabilitySkeleton).props();
expect(props.variant).toBe('dashboards');
});
});
describe('on GOUI_ROUTE_UPDATE', () => {
it('should emit a route-update event', () => {
2023-03-04 22:38:38 +05:30
mountComponent();
2023-05-27 22:25:52 +05:30
const payload = { url: '/explore' };
2023-03-04 22:38:38 +05:30
dispatchMessageEvent({
2023-05-27 22:25:52 +05:30
data: { type: MESSAGE_EVENT_TYPE.GOUI_ROUTE_UPDATE, payload },
2023-03-04 22:38:38 +05:30
origin: 'https://observe.gitlab.com',
});
2023-05-27 22:25:52 +05:30
expect(wrapper.emitted('route-update')[0]).toEqual([payload]);
2023-03-04 22:38:38 +05:30
});
});
describe('on GOUI_LOADED', () => {
beforeEach(() => {
mountComponent();
2023-03-17 16:20:25 +05:30
wrapper.vm.$refs.observabilitySkeleton.onContentLoaded = mockHandleSkeleton;
2023-03-04 22:38:38 +05:30
});
2023-03-17 16:20:25 +05:30
it('should call onContentLoaded method', () => {
2023-03-04 22:38:38 +05:30
dispatchMessageEvent({
data: { type: MESSAGE_EVENT_TYPE.GOUI_LOADED },
origin: 'https://observe.gitlab.com',
});
expect(mockHandleSkeleton).toHaveBeenCalled();
});
2023-03-17 16:20:25 +05:30
it('should not call onContentLoaded method if origin is different', () => {
2023-03-04 22:38:38 +05:30
dispatchMessageEvent({
data: { type: MESSAGE_EVENT_TYPE.GOUI_LOADED },
origin: 'https://example.com',
});
expect(mockHandleSkeleton).not.toHaveBeenCalled();
});
2023-03-17 16:20:25 +05:30
it('should not call onContentLoaded method if event type is different', () => {
2023-03-04 22:38:38 +05:30
dispatchMessageEvent({
data: { type: 'UNKNOWN_EVENT' },
origin: 'https://observe.gitlab.com',
});
expect(mockHandleSkeleton).not.toHaveBeenCalled();
});
});
2023-05-27 22:25:52 +05:30
describe('on unmount', () => {
it('should not emit any even on route update', () => {
2023-03-04 22:38:38 +05:30
mountComponent();
wrapper.destroy();
dispatchMessageEvent({
data: { type: MESSAGE_EVENT_TYPE.GOUI_ROUTE_UPDATE, payload: { url: '/explore' } },
origin: 'https://observe.gitlab.com',
});
2023-05-27 22:25:52 +05:30
expect(wrapper.emitted('route-update')).toBeUndefined();
2023-01-13 00:05:48 +05:30
});
});
});