Skip to content
Snippets Groups Projects

Show list of stream audit event types in UI

Merged Lorenz van Herwaarden requested to merge render-audit-events-backend into master
2 unresolved threads
2 files
+ 72
21
Compare changes
  • Side-by-side
  • Inline
Files
2
import { GlFormCheckboxTree } from '@gitlab/ui';
import { GlCollapsibleListbox } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import StreamFilters from 'ee/audit_events/components/stream/stream_filters.vue';
import { AUDIT_STREAMS_FILTERING } from 'ee/audit_events/constants';
import { mockExternalDestinations, mockFiltersOptions } from '../../mock_data';
import {
mockExternalDestinations,
mockAuditEventDefinitions,
mockStreamFiltersOptions,
} from '../../mock_data';
describe('StreamWithFilters', () => {
let wrapper;
const createComponent = () => {
const createComponent = (props) => {
wrapper = shallowMount(StreamFilters, {
propsData: {
filterOptions: mockFiltersOptions,
filterSelected: mockExternalDestinations[1].eventTypeFilters,
value: mockExternalDestinations[1].eventTypeFilters,
...props,
},
provide: {
auditEventDefinitions: mockAuditEventDefinitions,
},
});
};
const findFilterCheckboxTree = () => wrapper.findComponent(GlFormCheckboxTree);
const findCollapsibleListbox = () => wrapper.findComponent(GlCollapsibleListbox);
beforeEach(() => {
createComponent();
});
it('should render correctly', () => {
const options = mockFiltersOptions.map((value) => ({ value }));
expect(findFilterCheckboxTree().props()).toStrictEqual({
hideToggleAll: false,
label: 'Checkbox tree',
options,
labelSrOnly: true,
value: mockExternalDestinations[1].eventTypeFilters,
selectAllLabel: AUDIT_STREAMS_FILTERING.SELECT_ALL,
unselectAllLabel: AUDIT_STREAMS_FILTERING.UNSELECT_ALL,
it('renders correctly', () => {
expect(findCollapsibleListbox().props()).toMatchObject({
items: mockStreamFiltersOptions,
selected: mockExternalDestinations[1].eventTypeFilters,
showSelectAllButtonLabel: AUDIT_STREAMS_FILTERING.SELECT_ALL,
resetButtonLabel: AUDIT_STREAMS_FILTERING.UNSELECT_ALL,
headerText: AUDIT_STREAMS_FILTERING.SELECT_EVENTS,
multiple: true,
toggleClass: 'gl-max-w-full',
});
expect(findCollapsibleListbox().classes('gl-max-w-full')).toBe(true);
});
describe('toggleText', () => {
it('is a placeholder when no events are selected', () => {
createComponent({ value: [] });
expect(findCollapsibleListbox().props('toggleText')).toBe(
AUDIT_STREAMS_FILTERING.SELECT_EVENTS,
);
});
it('is humanized event when 1 event is selected', () => {
createComponent({ value: ['repository_download_operation'] });
expect(findCollapsibleListbox().props('toggleText')).toBe('Repository download operation');
});
it('is comma-separated list of humanized events when multiple events are selected', () => {
createComponent({ value: ['repository_download_operation', 'update_merge_approval_rule'] });
expect(findCollapsibleListbox().props('toggleText')).toBe(
'Repository download operation, Update merge approval rule',
);
});
});
it('should emit `updateFilters` event', () => {
findFilterCheckboxTree().vm.$emit('change', mockExternalDestinations[1].eventTypeFilters);
describe('events', () => {
it('emits `input` event when selecting event', () => {
findCollapsibleListbox().vm.$emit('select', mockExternalDestinations[1].eventTypeFilters);
expect(wrapper.emitted('input')).toStrictEqual([
[mockExternalDestinations[1].eventTypeFilters],
]);
});
it('emits `input` with empty array when unselecting all', () => {
findCollapsibleListbox().vm.$emit('reset');
expect(wrapper.emitted('updateFilters')).toStrictEqual([
[mockExternalDestinations[1].eventTypeFilters],
]);
expect(wrapper.emitted('input')).toEqual([[[]]]);
});
it('emits `input` with all events when selecting all', () => {
findCollapsibleListbox().vm.$emit('select-all');
expect(wrapper.emitted('input')).toEqual([[Object.keys(mockAuditEventDefinitions)]]);
});
});
});
Loading