blob: 349fab03853b7828882b746f7dd5fbb226ca6324 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
import { mount } from '@vue/test-utils';
import MessagesTable from '~/admin/broadcast_messages/components/messages_table.vue';
import { MOCK_MESSAGES } from '../mock_data';
describe('MessagesTable', () => {
let wrapper;
const findRows = () => wrapper.findAll('[data-testid="message-row"]');
const findTargetRoles = () => wrapper.find('[data-testid="target-roles-th"]');
const findDeleteButton = (id) => wrapper.find(`[data-testid="delete-message-${id}"]`);
function createComponent(props = {}, glFeatures = {}) {
wrapper = mount(MessagesTable, {
provide: {
glFeatures,
},
propsData: {
messages: MOCK_MESSAGES,
...props,
},
});
}
afterEach(() => {
wrapper.destroy();
});
it('renders a table row for each message', () => {
createComponent();
expect(findRows()).toHaveLength(MOCK_MESSAGES.length);
});
it('renders the "Target Roles" column when roleTargetedBroadcastMessages is enabled', () => {
createComponent({}, { roleTargetedBroadcastMessages: true });
expect(findTargetRoles().exists()).toBe(true);
});
it('does not render the "Target Roles" column when roleTargetedBroadcastMessages is disabled', () => {
createComponent();
expect(findTargetRoles().exists()).toBe(false);
});
it('emits a delete-message event when a delete button is clicked', () => {
const { id } = MOCK_MESSAGES[0];
createComponent();
findDeleteButton(id).element.click();
expect(wrapper.emitted('delete-message')).toHaveLength(1);
expect(wrapper.emitted('delete-message')[0]).toEqual([id]);
});
});
|