Skip to content

Commit

Permalink
[ONL-7877] change isCustomSlotShown prop usage and add missing test i…
Browse files Browse the repository at this point in the history
…n ec-smart table
  • Loading branch information
raulwwq0 committed Sep 19, 2023
1 parent 33baf64 commit cd26da8
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,61 @@ exports[`EcSmartTable #slots should pass ec-table slots 1`] = `
</tr>
`;

exports[`EcSmartTable #slots should render custom slot if window width is lower than 768px 1`] = `
<div
class="ec-smart-table"
data-test="ec-smart-table"
>
<!--v-if-->
<!--v-if-->
<div
class="ec-loading"
data-test="ec-loading"
>
<!--v-if-->
<div
class="ec-loading__content ec-loading__content--is-transparent"
data-test="ec-loading__content"
>
<div>
<!--v-if-->
<div
class="ec-table-scroll-container"
data-test="ec-table-scroll-container"
>
<table
class="ec-table"
>
<!--v-if-->
<tbody>
<tr
class=""
data-test="ec-table__row ec-table__row--0"
>
<div>
Custom slot data: {"key":0,"row":[1,2,3]}
</div>
</tr>
</tbody>
<!--v-if-->
</table>
</div>
</div>
</div>
</div>
</div>
`;

exports[`EcSmartTable #slots should render empty data with custom template 1`] = `
<div
class="ec-smart-table"
Expand Down
21 changes: 21 additions & 0 deletions src/components/ec-smart-table/ec-smart-table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,27 @@ describe('EcSmartTable', () => {
expect(wrapper.findByDataTest('ec-table__row--0').element).toMatchSnapshot();
});

it('should render custom slot if window width is lower than 768px', () => {
window.matchMedia = jest.fn().mockImplementation(query => ({
matches: query === '(max-width: 768px)',
media: '',
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
}));

const wrapper = mountEcSmartTableWithData(data, {
columns,
}, {
slots: {
default: props => h('div', `Custom slot data: ${JSON.stringify(props)}`),
col1: props => h('div', `Cell data: ${JSON.stringify(props)}`),
},
});

expect(wrapper.element).toMatchSnapshot();
});

it('should only render custom slot if "isCustomSlotShown" is true', () => {
const wrapper = mountEcSmartTableWithData(data, {
columns,
Expand Down
2 changes: 1 addition & 1 deletion src/components/ec-smart-table/ec-smart-table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const props = defineProps({
error: [Error, Object, String],
isCustomSlotShown: {
type: Boolean,
default: () => false,
default: () => undefined,
},
});
Expand Down
8 changes: 7 additions & 1 deletion src/components/ec-table/ec-table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,13 @@ describe('EcTable', () => {
});

it('should render custom slot if window width is lower than 768px', () => {
global.innerWidth = 500;
window.matchMedia = jest.fn().mockImplementation(query => ({
matches: query === '(max-width: 768px)',
media: '',
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
}));

const wrapper = mountEcTable({
columns: [
Expand Down
4 changes: 2 additions & 2 deletions src/components/ec-table/ec-table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ const props = defineProps({
title: String,
isCustomSlotShown: {
type: Boolean,
default: () => false,
default: () => undefined,
},
});
const numberOfColumns = computed(() => (props.columns.length || (props.data[0] && props.data[0].length) || null));
const maxHeightStyle = computed(() => (props.maxHeight ? { maxHeight: `${props.maxHeight}` } : null));
const canShowCustomSlot = computed(() => (props.isCustomSlotShown || (hasSlot('default') && isInCustomSlotThreshold.value)));
const canShowCustomSlot = computed(() => (props.isCustomSlotShown || (props.isCustomSlotShown === undefined && hasSlot('default') && isInCustomSlotThreshold.value)));
function onSort(columnName) {
emit('sort', columnName);
Expand Down

0 comments on commit cd26da8

Please sign in to comment.