Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QCollapse, QCollapseItem] Refactoring + snapshots #43

Merged
merged 1 commit into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/qComponents/QCollapse/QCollapse.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Component from './src/QCollapse';

describe('QCollapse', () => {
it('should match snapshot', () => {
const { element } = mount(Component);
expect(element).toMatchSnapshot();
});

it('data should match snapshot', () => {
expect(Component.data()).toMatchSnapshot();
});
});
14 changes: 14 additions & 0 deletions src/qComponents/QCollapse/__snapshots__/QCollapse.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`QCollapse data should match snapshot 1`] = `
Object {
"activeNames": Array [],
"uniqueId": [Function],
}
`;

exports[`QCollapse should match snapshot 1`] = `
<div
class="q-collapse"
/>
`;
10 changes: 8 additions & 2 deletions src/qComponents/QCollapse/src/QCollapse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export default {
name: 'QCollapse',
componentName: 'QCollapse',

provide() {
return {
qCollapse: this
};
},

model: {
prop: 'value',
event: 'change'
Expand Down Expand Up @@ -39,10 +45,10 @@ export default {

watch: {
value: {
immediate: true,
handler(value) {
this.activeNames = [].concat(value);
},
immediate: true
}
}
},

Expand Down
12 changes: 12 additions & 0 deletions src/qComponents/QCollapseItem/QCollapseItem.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Component from './src/QCollapseItem';

describe('QCollapseItem', () => {
it('should match snapshot', () => {
const { element } = mount(Component);
expect(element).toMatchSnapshot();
});

it('data should match snapshot', () => {
expect(Component.data()).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`QCollapseItem data should match snapshot 1`] = `
Object {
"activeNames": Array [],
}
`;

exports[`QCollapseItem should match snapshot 1`] = `
<div
class="q-collapse-item"
>
<button
class="q-collapse-item__header"
>
<div
class="q-collapse-item__title"
>

</div>

<div
class="q-collapse-item__icon q-icon-plus"
/>
</button>

<transition-stub>
<div
class="q-collapse-item__body"
style="display: none;"
>
<div
class="q-collapse-item__content"
/>
</div>
</transition-stub>
</div>
`;
12 changes: 9 additions & 3 deletions src/qComponents/QCollapseItem/src/QCollapseItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export default {

components: { QCollapseTransition },

inject: {
qCollapse: {
default: null
}
},

props: {
title: {
type: String,
Expand All @@ -59,11 +65,11 @@ export default {

computed: {
preparedName() {
return this.name ?? this.$parent?.uniqueId('default-collapse-name-');
return this.name ?? this.qCollapse?.uniqueId('default-collapse-name-');
},

isActive() {
return this.$parent.activeNames?.includes(this.preparedName) ?? false;
return this.qCollapse?.activeNames?.includes(this.preparedName) ?? false;
},

icon() {
Expand All @@ -73,7 +79,7 @@ export default {

methods: {
handleTabClick() {
this.$parent.updateValue(this.preparedName);
this.qCollapse?.updateValue(this.preparedName);
}
}
};
Expand Down