Commit 8558730b authored by Clement Ho's avatar Clement Ho

Merge branch...

Merge branch '38056-change-the-clipboardtext-property-requirement-inside-the-panel_type-component' into 'master'

Change the `clipboardText` to optional in panel_type component

Closes #38056

See merge request gitlab-org/gitlab!21717
parents dc323e47 287d19a6
...@@ -97,7 +97,6 @@ export default { ...@@ -97,7 +97,6 @@ export default {
v-for="(graphData, graphIndex) in charts" v-for="(graphData, graphIndex) in charts"
:key="`panel-type-${graphIndex}`" :key="`panel-type-${graphIndex}`"
class="w-100" class="w-100"
clipboard-text=""
:graph-data="graphData" :graph-data="graphData"
:group-id="dashboardUrl" :group-id="dashboardUrl"
/> />
......
...@@ -36,7 +36,8 @@ export default { ...@@ -36,7 +36,8 @@ export default {
props: { props: {
clipboardText: { clipboardText: {
type: String, type: String,
required: true, required: false,
default: '',
}, },
graphData: { graphData: {
type: Object, type: Object,
...@@ -152,6 +153,7 @@ export default { ...@@ -152,6 +153,7 @@ export default {
{{ __('Download CSV') }} {{ __('Download CSV') }}
</gl-dropdown-item> </gl-dropdown-item>
<gl-dropdown-item <gl-dropdown-item
v-if="clipboardText"
v-track-event="generateLinkToChartOptions(clipboardText)" v-track-event="generateLinkToChartOptions(clipboardText)"
class="js-chart-link" class="js-chart-link"
:data-clipboard-text="clipboardText" :data-clipboard-text="clipboardText"
......
...@@ -20,6 +20,16 @@ describe('Panel Type component', () => { ...@@ -20,6 +20,16 @@ describe('Panel Type component', () => {
const dashboardWidth = 100; const dashboardWidth = 100;
const exampleText = 'example_text'; const exampleText = 'example_text';
const createWrapper = props =>
shallowMount(PanelType, {
propsData: {
...props,
},
store,
sync: false,
attachToDocument: true,
});
beforeEach(() => { beforeEach(() => {
setTestTimeout(1000); setTestTimeout(1000);
axiosMock = new AxiosMockAdapter(axios); axiosMock = new AxiosMockAdapter(axios);
...@@ -36,14 +46,9 @@ describe('Panel Type component', () => { ...@@ -36,14 +46,9 @@ describe('Panel Type component', () => {
graphDataNoResult.metrics[0].result = []; graphDataNoResult.metrics[0].result = [];
beforeEach(() => { beforeEach(() => {
panelType = shallowMount(PanelType, { panelType = createWrapper({
propsData: { dashboardWidth,
clipboardText: 'dashboard_link', graphData: graphDataNoResult,
dashboardWidth,
graphData: graphDataNoResult,
},
sync: false,
attachToDocument: true,
}); });
}); });
...@@ -68,41 +73,30 @@ describe('Panel Type component', () => { ...@@ -68,41 +73,30 @@ describe('Panel Type component', () => {
}); });
}); });
describe('when Graph data is available', () => { describe('when graph data is available', () => {
const propsData = { beforeEach(() => {
clipboardText: exampleText,
dashboardWidth,
graphData: graphDataPrometheusQueryRange,
};
beforeEach(done => {
store = createStore(); store = createStore();
panelType = shallowMount(PanelType, { panelType = createWrapper({
propsData, dashboardWidth,
store, graphData: graphDataPrometheusQueryRange,
sync: false,
attachToDocument: true,
}); });
panelType.vm.$nextTick(done);
}); });
afterEach(() => { afterEach(() => {
panelType.destroy(); panelType.destroy();
}); });
it('sets no clipboard copy link on dropdown by default', () => {
const link = () => panelType.find('.js-chart-link');
expect(link().exists()).toBe(false);
});
describe('Time Series Chart panel type', () => { describe('Time Series Chart panel type', () => {
it('is rendered', () => { it('is rendered', () => {
expect(panelType.find(TimeSeriesChart).isVueInstance()).toBe(true); expect(panelType.find(TimeSeriesChart).isVueInstance()).toBe(true);
expect(panelType.find(TimeSeriesChart).exists()).toBe(true); expect(panelType.find(TimeSeriesChart).exists()).toBe(true);
}); });
it('sets clipboard text on the dropdown', () => {
const link = () => panelType.find('.js-chart-link');
const clipboardText = () => link().element.dataset.clipboardText;
expect(clipboardText()).toBe(exampleText);
});
it('includes a default group id', () => { it('includes a default group id', () => {
expect(panelType.vm.groupId).toBe('panel-type-chart'); expect(panelType.vm.groupId).toBe('panel-type-chart');
}); });
...@@ -123,6 +117,30 @@ describe('Panel Type component', () => { ...@@ -123,6 +117,30 @@ describe('Panel Type component', () => {
}); });
}); });
describe('when cliboard data is available', () => {
const clipboardText = 'A value to copy.';
beforeEach(() => {
store = createStore();
panelType = createWrapper({
clipboardText,
dashboardWidth,
graphData: graphDataPrometheusQueryRange,
});
});
afterEach(() => {
panelType.destroy();
});
it('sets clipboard text on the dropdown', () => {
const link = () => panelType.find('.js-chart-link');
expect(link().exists()).toBe(true);
expect(link().element.dataset.clipboardText).toBe(clipboardText);
});
});
describe('when downloading metrics data as CSV', () => { describe('when downloading metrics data as CSV', () => {
beforeEach(done => { beforeEach(done => {
graphDataPrometheusQueryRange.y_label = 'metric'; graphDataPrometheusQueryRange.y_label = 'metric';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment