2020-11-24 15:15:51 +05:30
|
|
|
import { GlFormInputGroup } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import { escape as esc } from 'lodash';
|
2020-11-24 15:15:51 +05:30
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
|
|
|
import EmbedDropdown from '~/snippets/components/embed_dropdown.vue';
|
|
|
|
|
|
|
|
const TEST_URL = `${TEST_HOST}/test/no">'xss`;
|
|
|
|
|
|
|
|
describe('snippets/components/embed_dropdown', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const createComponent = () => {
|
|
|
|
wrapper = mount(EmbedDropdown, {
|
|
|
|
propsData: {
|
|
|
|
url: TEST_URL,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
const findSectionsData = () => {
|
|
|
|
const sections = [];
|
|
|
|
let current = {};
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
wrapper.findAll('[data-testid="header"],[data-testid="input"]').wrappers.forEach((x) => {
|
2020-11-24 15:15:51 +05:30
|
|
|
const type = x.attributes('data-testid');
|
|
|
|
|
|
|
|
if (type === 'header') {
|
|
|
|
current = {
|
|
|
|
header: x.text(),
|
|
|
|
};
|
|
|
|
|
|
|
|
sections.push(current);
|
|
|
|
} else {
|
2022-11-25 23:54:43 +05:30
|
|
|
const value = x.findComponent(GlFormInputGroup).props('value');
|
2020-11-24 15:15:51 +05:30
|
|
|
const copyValue = x.find('button[title="Copy"]').attributes('data-clipboard-text');
|
|
|
|
|
|
|
|
Object.assign(current, {
|
|
|
|
value,
|
|
|
|
copyValue,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return sections;
|
|
|
|
};
|
|
|
|
|
|
|
|
it('renders dropdown items', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
const embedValue = `<script src="${esc(TEST_URL)}.js"></script>`;
|
|
|
|
|
|
|
|
expect(findSectionsData()).toEqual([
|
|
|
|
{
|
|
|
|
header: 'Embed',
|
|
|
|
value: embedValue,
|
|
|
|
copyValue: embedValue,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
header: 'Share',
|
|
|
|
value: TEST_URL,
|
|
|
|
copyValue: TEST_URL,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|