Skip to content

Commit

Permalink
Merge pull request #317 from chrismayer/force-sidebar-open-state
Browse files Browse the repository at this point in the history
Extend 'sidebar-toggle' event to force open state
  • Loading branch information
chrismayer authored Feb 3, 2023
2 parents e845040 + 52b03fb commit fa380b8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
17 changes: 11 additions & 6 deletions app-starter/components/AppSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
absolute
top
color="secondary"
@click="sidebarOpen = !sidebarOpen">
<v-icon color="onsecondary" v-if="sidebarOpen">chevron_left</v-icon>
<v-icon color="onsecondary" v-else>chevron_right</v-icon>
@click="sidebarOpen = !sidebarOpen">
<v-icon color="onsecondary" v-if="sidebarOpen">chevron_left</v-icon>
<v-icon color="onsecondary" v-else>chevron_right</v-icon>
</v-btn>
</template>
<!-- Invisible sidebar resizer -->
<div v-if="resizable"
class="wgu-app-sidebar-resizer"
@mousedown.prevent="onResize"
/>
/>
</v-navigation-drawer>
</template>

Expand Down Expand Up @@ -57,8 +57,13 @@ export default {
WguEventBus.$on('sidebar-scroll', comp => {
this.scrollTo(comp);
});
WguEventBus.$on('sidebar-toggle', () => {
this.sidebarOpen = !this.sidebarOpen;
WguEventBus.$on('sidebar-toggle', (open) => {
// toggle or force a opening state of the sidebar
if (typeof open === 'boolean') {
this.sidebarOpen = open;
} else {
this.sidebarOpen = !this.sidebarOpen;
}
});
},
methods: {
Expand Down
36 changes: 36 additions & 0 deletions test/unit/specs/components/AppSidebar.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import AppSidebar from 'APP/components/AppSidebar';
import { WguEventBus } from '@/WguEventBus';
import { shallowMount } from '@vue/test-utils';

describe('AppSidebar.vue', () => {
describe('data', () => {
let comp;
let vm;
beforeEach(() => {
comp = shallowMount(AppSidebar);
vm = comp.vm;
});

it('has correct default data', () => {
expect(vm.sidebarOpen).to.equal(true);
});
});

describe('events', () => {
let comp;
let vm;
beforeEach(() => {
comp = shallowMount(AppSidebar);
vm = comp.vm;
});

it('event "sidebar-toggle" forces correct open state', () => {
// force closing sidebar by adding 'false' parameter
WguEventBus.$emit('sidebar-toggle', false);
expect(vm.sidebarOpen).to.equal(false);
// toggle sidebar open state by skipping parameter
WguEventBus.$emit('sidebar-toggle');
expect(vm.sidebarOpen).to.equal(true);
});
});
});

0 comments on commit fa380b8

Please sign in to comment.