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

Extend 'sidebar-toggle' event to force open state #317

Merged
merged 1 commit into from
Feb 3, 2023
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
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);
});
});
});