Skip to content

Commit

Permalink
Merge pull request #4954 from nextcloud-libraries/fix/4941/NcAppSetti…
Browse files Browse the repository at this point in the history
…ngsDialog--respect-show-navigation-prop

fix(NcAppSettingsDialog): respect showNavigation prop
  • Loading branch information
Pytal committed Dec 14, 2023
2 parents 4fff857 + d54ff77 commit d0a4f5b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/components/NcAppSettingsDialog/NcAppSettingsDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default {
<NcDialog v-if="open"
v-bind="dialogProperties"
@update:open="handleCloseModal">
<template #navigation="{ isCollapsed }">
<template v-if="hasNavigation" #navigation="{ isCollapsed }">
<ul v-if="!isCollapsed"
:aria-label="settingsNavigationAriaLabel"
class="navigation-list"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ import { mount } from '@vue/test-utils'
import { emit } from '@nextcloud/event-bus'
import { nextTick } from 'vue'
import NcAppNavigation from '../../../../src/components/NcAppNavigation/NcAppNavigation.vue'

const resizeWindowWidth = async (width) => {
jest.spyOn(document.documentElement, 'clientWidth', 'get').mockReturnValue(width)
window.dispatchEvent(new window.Event('resize'))
await nextTick()
}
import { resizeWindowWidth } from '../../testing-utils.ts'

const NAVIGATION__SELECTOR = 'nav'
const TOGGLE_BUTTON__SELECTOR = 'button[aria-controls="app-navigation-vue"]'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import { mount } from '@vue/test-utils'
import NcAppSettingsDialog from '../../../../src/components/NcAppSettingsDialog/NcAppSettingsDialog.vue'
import { defineComponent, inject, nextTick, onMounted } from 'vue'
import { resizeWindowWidth } from '../../testing-utils'

/**
* Mocked AppSettingsSection that just registers it self
Expand All @@ -37,13 +38,18 @@ const MockSection = defineComponent({
})

describe('NcAppSettingsDialog: Sections registration', () => {
beforeAll(async () => {
await resizeWindowWidth(1024)
})

it('injects register function to children', async () => {
const wrapper = mount(NcAppSettingsDialog, {
slots: {
default: MockSection,
},
propsData: {
open: true,
showNavigation: true,
},
})

Expand All @@ -58,6 +64,7 @@ describe('NcAppSettingsDialog: Sections registration', () => {
const wrapper = mount<Vue & { registerSection: any }>(NcAppSettingsDialog, {
propsData: {
open: true,
showNavigation: true,
},
})

Expand All @@ -72,6 +79,7 @@ describe('NcAppSettingsDialog: Sections registration', () => {
const wrapper = mount<Vue & { registerSection: any }>(NcAppSettingsDialog, {
propsData: {
open: true,
showNavigation: true,
},
})

Expand All @@ -96,6 +104,7 @@ describe('NcAppSettingsDialog: Sections registration', () => {
const wrapper = mount<Vue & { registerSection: any }>(NcAppSettingsDialog, {
propsData: {
open: true,
showNavigation: true,
},
})

Expand All @@ -115,6 +124,7 @@ describe('NcAppSettingsDialog: Sections registration', () => {
const wrapper = mount<Vue & { registerSection: any, unregisterSection: any }>(NcAppSettingsDialog, {
propsData: {
open: true,
showNavigation: true,
},
})

Expand Down
7 changes: 1 addition & 6 deletions tests/unit/composables/useIsMobile.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { isRef, nextTick } from 'vue'
import { mount } from '@vue/test-utils'
import { useIsMobile } from '../../../src/composables/useIsMobile/index.js'

const resizeWindowWidth = async (width) => {
jest.spyOn(document.documentElement, 'clientWidth', 'get').mockReturnValue(width)
window.dispatchEvent(new window.Event('resize'))
await nextTick()
}
import { resizeWindowWidth } from '../testing-utils.ts'

describe('useIsMobile', () => {
it('should return ref', () => {
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/testing-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { nextTick } from 'vue'

/**
* Resize the window to a given width and wait for re-render
*
* @param {number} width - The width of the window
*/
export async function resizeWindowWidth(width) {
jest.spyOn(document.documentElement, 'clientWidth', 'get').mockReturnValue(width)
window.dispatchEvent(new window.Event('resize'))
await nextTick()
}

0 comments on commit d0a4f5b

Please sign in to comment.