Commit 148d630a authored by Alexander Turinske's avatar Alexander Turinske

Abstract out CSS logic for vulnerability filter

- create class that sets the filter immediately below the header
  and performance bar
- clean up computed property
- add tests
parent 55836b94
.security_dashboard_filters {
top: $header-height;
.with-performance-bar & {
top: $header-height + $performance-bar-height;
}
}
<script> <script>
export default { export default {
stickyHeight: process.env.NODE_ENV === 'development' ? '75px' : '40px',
computed: { computed: {
hasHeaderSlot() { hasHeaderSlot() {
return Boolean(this.$slots.header); return Boolean(this.$slots.header);
...@@ -8,9 +7,6 @@ export default { ...@@ -8,9 +7,6 @@ export default {
hasStickySlot() { hasStickySlot() {
return Boolean(this.$slots.sticky); return Boolean(this.$slots.sticky);
}, },
stickyClasses() {
return this.hasStickySlot ? ['position-sticky', 'gl-z-index-2'] : [];
},
hasAsideSlot() { hasAsideSlot() {
return Boolean(this.$slots.aside); return Boolean(this.$slots.aside);
}, },
...@@ -24,7 +20,7 @@ export default { ...@@ -24,7 +20,7 @@ export default {
<slot name="header"></slot> <slot name="header"></slot>
</header> </header>
<section v-if="hasStickySlot" :class="stickyClasses" :style="{ top: $options.stickyHeight }"> <section v-if="hasStickySlot" class="position-sticky gl-z-index-2 security_dashboard_filters">
<slot name="sticky"></slot> <slot name="sticky"></slot>
</section> </section>
......
...@@ -17,6 +17,7 @@ describe('Security Dashboard Layout component', () => { ...@@ -17,6 +17,7 @@ describe('Security Dashboard Layout component', () => {
const findArticle = () => wrapper.find('article'); const findArticle = () => wrapper.find('article');
const findHeader = () => wrapper.find('header'); const findHeader = () => wrapper.find('header');
const findAside = () => wrapper.find('aside'); const findAside = () => wrapper.find('aside');
const findStickySection = () => wrapper.find('section');
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
...@@ -30,10 +31,11 @@ describe('Security Dashboard Layout component', () => { ...@@ -30,10 +31,11 @@ describe('Security Dashboard Layout component', () => {
}); });
it.each` it.each`
element | exists element | exists
${'article'} | ${true} ${'article'} | ${true}
${'header'} | ${false} ${'header'} | ${false}
${'aside'} | ${false} ${'aside'} | ${false}
${'section section'} | ${false}
`('should find that $element exists is $exists', ({ element, exists }) => { `('should find that $element exists is $exists', ({ element, exists }) => {
expect(wrapper.find(element).exists()).toBe(exists); expect(wrapper.find(element).exists()).toBe(exists);
}); });
...@@ -60,10 +62,11 @@ describe('Security Dashboard Layout component', () => { ...@@ -60,10 +62,11 @@ describe('Security Dashboard Layout component', () => {
}); });
it.each` it.each`
element | exists element | exists
${'article'} | ${true} ${'article'} | ${true}
${'header'} | ${true} ${'header'} | ${true}
${'aside'} | ${false} ${'aside'} | ${false}
${'section section'} | ${false}
`('should find that $element exists is $exists', ({ element, exists }) => { `('should find that $element exists is $exists', ({ element, exists }) => {
expect(wrapper.find(element).exists()).toBe(exists); expect(wrapper.find(element).exists()).toBe(exists);
}); });
...@@ -80,6 +83,36 @@ describe('Security Dashboard Layout component', () => { ...@@ -80,6 +83,36 @@ describe('Security Dashboard Layout component', () => {
expect(header.find(DummyComponent).exists()).toBe(true); expect(header.find(DummyComponent).exists()).toBe(true);
}); });
}); });
describe('with the sticky section and main slots', () => {
beforeEach(() => {
createWrapper({
default: DummyComponent,
sticky: DummyComponent,
});
});
it.each`
element | exists
${'article'} | ${true}
${'header'} | ${false}
${'aside'} | ${false}
${'section section'} | ${true}
`('should find that $element exists is $exists', ({ element, exists }) => {
expect(wrapper.find(element).exists()).toBe(exists);
});
it('should render the dummy component in the main section', () => {
const article = findArticle();
expect(article.find(DummyComponent).exists()).toBe(true);
});
it('should render the dummy component in the sticky section', () => {
const section = findStickySection();
expect(section.find(DummyComponent).exists()).toBe(true);
});
});
describe('with the aside and main slots', () => { describe('with the aside and main slots', () => {
beforeEach(() => { beforeEach(() => {
...@@ -90,10 +123,11 @@ describe('Security Dashboard Layout component', () => { ...@@ -90,10 +123,11 @@ describe('Security Dashboard Layout component', () => {
}); });
it.each` it.each`
element | exists element | exists
${'article'} | ${true} ${'article'} | ${true}
${'header'} | ${false} ${'header'} | ${false}
${'aside'} | ${true} ${'aside'} | ${true}
${'section section'} | ${false}
`('should find that $element exists is $exists', ({ element, exists }) => { `('should find that $element exists is $exists', ({ element, exists }) => {
expect(wrapper.find(element).exists()).toBe(exists); expect(wrapper.find(element).exists()).toBe(exists);
}); });
......
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