Skip to content

Commit

Permalink
Fix unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
lookacat authored and AlexAndBear committed Oct 19, 2023
1 parent d722198 commit c372ebc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
25 changes: 18 additions & 7 deletions packages/web-pkg/tests/unit/components/AppTopBar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
import { mock } from 'jest-mock-extended'
import { defaultPlugins, shallowMount } from 'web-test-helpers'
import {
createStore,
defaultPlugins,
defaultStoreMockOptions,
shallowMount
} from 'web-test-helpers'
import { Resource } from '@ownclouders/web-client/src/helpers'
import AppTopBar from '../../../src/components/AppTopBar.vue'
import { Action } from '../../../src/composables/actions'

describe('AppTopBar', () => {
describe('if no resource is present', () => {
it('renders only a close button', () => {
const { wrapper } = getWrapper()
const { wrapper } = getWrapper(mock<Resource>({ path: '/test.txt' }))
expect(wrapper.html()).toMatchSnapshot()
})
})
describe('if a resource is present', () => {
it('renders a resource and no actions (if none given) and a close button', () => {
const { wrapper } = getWrapper(mock<Resource>())
const { wrapper } = getWrapper(mock<Resource>({ path: '/test.txt' }))
expect(wrapper.html()).toMatchSnapshot()
})

it('renders a resource and mainActions (if given) and a close button', () => {
const { wrapper } = getWrapper(mock<Resource>(), [], [mock<Action>()])
const { wrapper } = getWrapper(mock<Resource>({ path: '/test.txt' }), [], [mock<Action>()])
expect(wrapper.html()).toMatchSnapshot()
})

it('renders a resource and dropdownActions (if given) and a close button', () => {
const { wrapper } = getWrapper(mock<Resource>(), [mock<Action>()], [])
const { wrapper } = getWrapper(mock<Resource>({ path: '/test.txt' }), [mock<Action>()], [])
expect(wrapper.html()).toMatchSnapshot()
})
it('renders a resource and dropdownActions as well as mainActions (if both are passed) and a close button', () => {
const { wrapper } = getWrapper(mock<Resource>(), [mock<Action>()], [mock<Action>()])
const { wrapper } = getWrapper(
mock<Resource>({ path: '/test.txt' }),
[mock<Action>()],
[mock<Action>()]
)
expect(wrapper.html()).toMatchSnapshot()
})
})
Expand All @@ -38,6 +47,8 @@ function getWrapper(
dropDownActions: Action[] = [],
mainActions: Action[] = []
) {
const storeOptions = { ...defaultStoreMockOptions }
const store = createStore(storeOptions)
return {
wrapper: shallowMount(AppTopBar, {
props: {
Expand All @@ -46,7 +57,7 @@ function getWrapper(
resource
},
global: {
plugins: [...defaultPlugins()]
plugins: [...defaultPlugins(), store]
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`AppTopBar if a resource is present renders a resource and dropdownActio
<div class="oc-app-top-bar oc-flex">
<span class="oc-app-top-bar-inner oc-px-m oc-flex oc-flex-middle oc-flex-between">
<div class="open-file-bar oc-flex">
<oc-resource-stub id="app-top-bar-resource" isextensiondisplayed="true" isicondisplayed="true" ispathdisplayed="false" isresourceclickable="true" isthumbnaildisplayed="false" parentfoldername="" resource="undefined"></oc-resource-stub>
<oc-resource-stub id="app-top-bar-resource" isextensiondisplayed="true" isicondisplayed="true" ispathdisplayed="true" isresourceclickable="true" isthumbnaildisplayed="false" parentfolderlinkiconadditionalattributes="[object Object]" parentfoldername="All files and folders" resource="undefined"></oc-resource-stub>
</div>
<div class="oc-flex main-actions">
<!--v-if-->
Expand All @@ -23,7 +23,7 @@ exports[`AppTopBar if a resource is present renders a resource and dropdownActio
<div class="oc-app-top-bar oc-flex">
<span class="oc-app-top-bar-inner oc-px-m oc-flex oc-flex-middle oc-flex-between">
<div class="open-file-bar oc-flex">
<oc-resource-stub id="app-top-bar-resource" isextensiondisplayed="true" isicondisplayed="true" ispathdisplayed="false" isresourceclickable="true" isthumbnaildisplayed="false" parentfoldername="" resource="undefined"></oc-resource-stub>
<oc-resource-stub id="app-top-bar-resource" isextensiondisplayed="true" isicondisplayed="true" ispathdisplayed="true" isresourceclickable="true" isthumbnaildisplayed="false" parentfolderlinkiconadditionalattributes="[object Object]" parentfoldername="All files and folders" resource="undefined"></oc-resource-stub>
</div>
<div class="oc-flex main-actions">
<context-action-menu-stub actionoptions="[object Object]" appearance="raw-inverse" menusections="[object Object]" variation="brand"></context-action-menu-stub>
Expand All @@ -41,7 +41,7 @@ exports[`AppTopBar if a resource is present renders a resource and mainActions (
<div class="oc-app-top-bar oc-flex">
<span class="oc-app-top-bar-inner oc-px-m oc-flex oc-flex-middle oc-flex-between">
<div class="open-file-bar oc-flex">
<oc-resource-stub id="app-top-bar-resource" isextensiondisplayed="true" isicondisplayed="true" ispathdisplayed="false" isresourceclickable="true" isthumbnaildisplayed="false" parentfoldername="" resource="undefined"></oc-resource-stub>
<oc-resource-stub id="app-top-bar-resource" isextensiondisplayed="true" isicondisplayed="true" ispathdisplayed="true" isresourceclickable="true" isthumbnaildisplayed="false" parentfolderlinkiconadditionalattributes="[object Object]" parentfoldername="All files and folders" resource="undefined"></oc-resource-stub>
</div>
<div class="oc-flex main-actions">
<context-action-menu-stub actionoptions="[object Object]" appearance="raw-inverse" menusections="[object Object]" variation="brand"></context-action-menu-stub>
Expand All @@ -58,7 +58,7 @@ exports[`AppTopBar if a resource is present renders a resource and no actions (i
<div class="oc-app-top-bar oc-flex">
<span class="oc-app-top-bar-inner oc-px-m oc-flex oc-flex-middle oc-flex-between">
<div class="open-file-bar oc-flex">
<oc-resource-stub id="app-top-bar-resource" isextensiondisplayed="true" isicondisplayed="true" ispathdisplayed="false" isresourceclickable="true" isthumbnaildisplayed="false" parentfoldername="" resource="undefined"></oc-resource-stub>
<oc-resource-stub id="app-top-bar-resource" isextensiondisplayed="true" isicondisplayed="true" ispathdisplayed="true" isresourceclickable="true" isthumbnaildisplayed="false" parentfolderlinkiconadditionalattributes="[object Object]" parentfoldername="All files and folders" resource="undefined"></oc-resource-stub>
</div>
<div class="oc-flex main-actions">
<!--v-if-->
Expand All @@ -75,7 +75,7 @@ exports[`AppTopBar if no resource is present renders only a close button 1`] = `
<div class="oc-app-top-bar oc-flex">
<span class="oc-app-top-bar-inner oc-px-m oc-flex oc-flex-middle oc-flex-between">
<div class="open-file-bar oc-flex">
<!--v-if-->
<oc-resource-stub id="app-top-bar-resource" isextensiondisplayed="true" isicondisplayed="true" ispathdisplayed="true" isresourceclickable="true" isthumbnaildisplayed="false" parentfolderlinkiconadditionalattributes="[object Object]" parentfoldername="All files and folders" resource="undefined"></oc-resource-stub>
</div>
<div class="oc-flex main-actions">
<!--v-if-->
Expand Down

0 comments on commit c372ebc

Please sign in to comment.