Merge branch 'ce-4348-show-dast-results-in-the-mr-widget' into 'master'
Backport of methods and components added in EE See merge request gitlab-org/gitlab-ce!16208
This commit is contained in:
commit
3489ad77c5
|
@ -64,3 +64,12 @@ export const truncate = (string, maxLength) => `${string.substr(0, (maxLength -
|
|||
export function capitalizeFirstCharacter(text) {
|
||||
return `${text[0].toUpperCase()}${text.slice(1)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all html tags from a string with the given replacement.
|
||||
*
|
||||
* @param {String} string
|
||||
* @param {*} replace
|
||||
* @returns {String}
|
||||
*/
|
||||
export const stripeHtml = (string, replace = '') => string.replace(/<[^>]*>/g, replace);
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<script>
|
||||
import { __ } from '~/locale';
|
||||
/**
|
||||
* Port of detail_behavior expand button.
|
||||
*
|
||||
* @example
|
||||
* <expand-button>
|
||||
* <template slot="expanded">
|
||||
* Text goes here.
|
||||
* </template>
|
||||
* </expand-button>
|
||||
*/
|
||||
export default {
|
||||
name: 'expandButton',
|
||||
data() {
|
||||
return {
|
||||
isCollapsed: true,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
ariaLabel() {
|
||||
return __('Click to expand text');
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
onClick() {
|
||||
this.isCollapsed = !this.isCollapsed;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<template>
|
||||
<span>
|
||||
<button
|
||||
type="button"
|
||||
v-show="isCollapsed"
|
||||
class="text-expander btn-blank"
|
||||
:aria-label="ariaLabel"
|
||||
@click="onClick">
|
||||
...
|
||||
</button>
|
||||
<span v-show="!isCollapsed">
|
||||
<slot name="expanded"></slot>
|
||||
</span>
|
||||
</span>
|
||||
</template>
|
|
@ -62,4 +62,14 @@ describe('text_utility', () => {
|
|||
expect(textUtils.slugify('João')).toEqual('joão');
|
||||
});
|
||||
});
|
||||
|
||||
describe('stripeHtml', () => {
|
||||
it('replaces html tag with the default replacement', () => {
|
||||
expect(textUtils.stripeHtml('This is a text with <p>html</p>.')).toEqual('This is a text with html.');
|
||||
});
|
||||
|
||||
it('replaces html tags with the provided replacement', () => {
|
||||
expect(textUtils.stripeHtml('This is a text with <p>html</p>.', ' ')).toEqual('This is a text with html .');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
import Vue from 'vue';
|
||||
import expandButton from '~/vue_shared/components/expand_button.vue';
|
||||
import mountComponent from '../../helpers/vue_mount_component_helper';
|
||||
|
||||
describe('expand button', () => {
|
||||
let vm;
|
||||
|
||||
beforeEach(() => {
|
||||
const Component = Vue.extend(expandButton);
|
||||
vm = mountComponent(Component, {
|
||||
slots: {
|
||||
expanded: '<p>Expanded!</p>',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vm.$destroy();
|
||||
});
|
||||
|
||||
it('renders a collpased button', () => {
|
||||
expect(vm.$el.textContent.trim()).toEqual('...');
|
||||
});
|
||||
|
||||
it('hides expander on click', (done) => {
|
||||
vm.$el.querySelector('button').click();
|
||||
vm.$nextTick(() => {
|
||||
expect(vm.$el.querySelector('button').getAttribute('style')).toEqual('display: none;');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue