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

Polyfill Vue Test Utils 2 API #8103

Merged
merged 98 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 88 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
323ed31
Polyfill Vue Test Utils 2 API
dschmidt Dec 11, 2022
710e657
Use new test syntax for SharesNavigation component
JammingBen Dec 12, 2022
a2dd7b0
Use new test syntax for CreateAndUpload component
JammingBen Dec 12, 2022
06ddeae
Use new test syntax for CreateSpace component
JammingBen Dec 12, 2022
2cfc2b4
Use new test syntax for SidebarToggle component
JammingBen Dec 12, 2022
4a60fd0
Use new test syntax for ViewOptions component
JammingBen Dec 12, 2022
1c00626
Use new test syntax for BatchActions component
JammingBen Dec 12, 2022
416ecfc
Use new test syntax for ResourceUpload component
JammingBen Dec 12, 2022
0d32b02
Use new test syntax for ContextActions component
JammingBen Dec 12, 2022
5940043
Use new test syntax for ListInfo component
JammingBen Dec 12, 2022
fe8ed3e
Use new test syntax for NotFoundMessage component
JammingBen Dec 12, 2022
917120b
Use new test syntax for Pagination component
JammingBen Dec 12, 2022
d89026a
Use new test syntax for QuickActions component
JammingBen Dec 12, 2022
2b4073e
Use new test syntax for ResourceTable component
JammingBen Dec 12, 2022
3e7c2a2
Use new test syntax for List component
JammingBen Dec 12, 2022
12a4374
Use new test syntax for Preview component
JammingBen Dec 12, 2022
ddfcd71
Use new test syntax for QuotaModal component
JammingBen Dec 12, 2022
a353263
Use translations in defaultComponentMocks
JammingBen Dec 12, 2022
59c64f9
Add mock Axios test helper
JammingBen Dec 12, 2022
ba4bae3
Use new test syntax for SpaceContextActions component
JammingBen Dec 12, 2022
f34bed1
Use new test syntax for SpaceHeader component
JammingBen Dec 12, 2022
d74737b
Use new test syntax for ActionMenuItem component
JammingBen Dec 12, 2022
3b2c662
Use new test syntax for ContextActionMenu component
JammingBen Dec 12, 2022
86fe4fd
Use new test syntax for SpaceQuota component
JammingBen Dec 12, 2022
24be73d
Use new test syntax for FileInfo component
JammingBen Dec 12, 2022
b1d9c8f
Use new test syntax for PrivaetLinkItem component
JammingBen Dec 12, 2022
8872d38
Use new test syntax for SideBar component
JammingBen Dec 12, 2022
b024569
Use new test syntax for SpaceInfo component
JammingBen Dec 12, 2022
6dec332
Use new test syntax for FileActions component
JammingBen Dec 12, 2022
356f5fc
Use new test syntax for FileDetails component
JammingBen Dec 12, 2022
89dc868
Use new test syntax for FIleDetailsMultiple component
JammingBen Dec 12, 2022
b07d13f
Use new test syntax for SpaceDetails component
JammingBen Dec 12, 2022
ee0c778
Add unit test to-dos
JammingBen Dec 12, 2022
5315852
Add axios to web-test-helpers dependencies
dschmidt Dec 12, 2022
0593e39
Use new test syntax for FileVersions component
JammingBen Dec 12, 2022
9f975da
Remove components.setup.js test helper
JammingBen Dec 12, 2022
3f930f8
Use new test syntax for FileLinks component
JammingBen Dec 12, 2022
15f20a0
Use new test syntax for SharesPanel component
JammingBen Dec 12, 2022
574e51b
Use new test syntax for DetailsAndEdit component
JammingBen Dec 12, 2022
3292b68
Use new test syntax for NameAndCopy component
JammingBen Dec 12, 2022
556ef16
Use new test syntax for RoleDropdown component
JammingBen Dec 12, 2022
53196c7
Use new test syntax for AutoComplete component
JammingBen Dec 12, 2022
896a3e4
Use new test syntax for ExpirationDatepicker component
JammingBen Dec 12, 2022
d8bc335
Use new test syntax for InviteCollaborator component
JammingBen Dec 12, 2022
9f002c8
Use new test syntax for ResolvePublicLink component
JammingBen Dec 12, 2022
6652771
Remove unused jest setup functions
JammingBen Dec 12, 2022
745e0f7
Use new test syntax for ListItem component
JammingBen Dec 13, 2022
2a3b7ab
Use new test syntax for SpaceMembers component
JammingBen Dec 13, 2022
6cc021e
Use new test syntax for ReadmeContentModal component
JammingBen Dec 13, 2022
ce8b722
Use new test syntax for FileShares component
JammingBen Dec 13, 2022
03cb3b3
Use new test syntax for RecipientContainer component
JammingBen Dec 13, 2022
7323b15
Use new test syntax for Favorites view
JammingBen Dec 13, 2022
7935489
Use new test syntax for FilesDrop view
JammingBen Dec 13, 2022
c22612a
Use new test syntax for share views
JammingBen Dec 13, 2022
996c5ad
Use new test syntax for space views
JammingBen Dec 13, 2022
df3c50d
Use new test syntax for action mixins
JammingBen Dec 13, 2022
5303822
Use new test syntax for space action mixins
JammingBen Dec 13, 2022
cab8827
Use new test syntax for AppBar component
JammingBen Dec 13, 2022
ce79e2b
Use new test syntax for file app composables
JammingBen Dec 13, 2022
6c02ca8
Use new test syntax for SDKSearch class
JammingBen Dec 13, 2022
0afeba3
Move RouterLinkStub to our test helpers
JammingBen Dec 13, 2022
367539c
Use new test syntax for external app
JammingBen Dec 13, 2022
e904ff8
Use new test syntax for components in the external app
JammingBen Dec 13, 2022
3794f79
Use new test syntax for the search app
JammingBen Dec 13, 2022
5b2b73d
Remove vuex dependencies when not needed
JammingBen Dec 13, 2022
f6edb11
Use new test syntax for the text editor app
JammingBen Dec 13, 2022
f49bf37
Use new test syntax for web-pkg components
JammingBen Dec 13, 2022
c6b7bad
Use new test syntax for useRoute composables
JammingBen Dec 13, 2022
17166fd
Use new test syntax for Avatar component
JammingBen Dec 13, 2022
e7b0de0
Use new test syntax for useDebouncedRef component
JammingBen Dec 13, 2022
fd2e23d
Use new test syntax for web-pkg composables
JammingBen Dec 13, 2022
36e601a
Use new test syntax for web-runtime components
JammingBen Dec 13, 2022
074eb6a
Use new test syntax for web-runtime components
JammingBen Dec 13, 2022
d69da04
Use new test syntax for web-runtime pages
JammingBen Dec 13, 2022
c30aa8b
Use new test syntax for web-runtime mixins
JammingBen Dec 13, 2022
13aeca9
Use new test syntax for useUpload composable
JammingBen Dec 13, 2022
e0c2857
Use new test syntax for versions container
JammingBen Dec 13, 2022
52bf3ea
Use getStore test helper
JammingBen Dec 13, 2022
58cd116
Remove vuex-mock-store
JammingBen Dec 13, 2022
6371ced
Remove vuex-extensions use from tests
JammingBen Dec 13, 2022
e011797
Remove vuex-extension when not needed
JammingBen Dec 13, 2022
52114d4
Run linter
JammingBen Dec 13, 2022
247cb4d
Use new test syntax for user management components
JammingBen Dec 13, 2022
b8163bd
Use new test syntax for groups view
JammingBen Dec 13, 2022
0cc72c5
Fix tests for the FileActions view
JammingBen Dec 13, 2022
8ddfeca
Fix tests for the ContextActions view
JammingBen Dec 13, 2022
a048f3a
defaultLocalVue is dead, long live defaultPlugins
dschmidt Dec 14, 2022
8d86637
Remove unused slots from ResourceTable test
dschmidt Dec 14, 2022
5a95cee
Remove some superfluous duplicated await nextTicks
dschmidt Dec 14, 2022
6970d53
Use defaultStubs in SidebarNav.spec.ts
dschmidt Dec 14, 2022
c334b84
Sort defaultStubs
dschmidt Dec 14, 2022
42f9092
Get rid of tests/unit/stubs/index.js
dschmidt Dec 14, 2022
e7de287
Simplify web-test-helpers imports
dschmidt Dec 14, 2022
8855eb0
Avatar: handle 404 silently
dschmidt Dec 14, 2022
3440822
Remove web-test-helpers as dependencies
dschmidt Dec 14, 2022
ed28e84
Do not mock out vue-gettext in DeleteUserModal
dschmidt Dec 14, 2022
304cc13
Do not mock out vue-gettext in DeleteGroupModal
dschmidt Dec 14, 2022
d248ae2
Fix lint
dschmidt Dec 14, 2022
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
"typescript": "4.8.4",
"url-search-params-polyfill": "8.1.1",
"vue-template-compiler": "2.6.14",
"vuex-mock-store": "0.0.8",
"wait-for-expect": "3.0.2"
},
"engines": {
Expand Down
216 changes: 73 additions & 143 deletions packages/web-app-external/tests/unit/app.spec.ts
Original file line number Diff line number Diff line change
@@ -1,89 +1,25 @@
import App from '../../src/App.vue'
import { shallowMount, createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import GetTextPlugin from 'vue-gettext'
import { createStore, defaultComponentMocks, defaultPlugins, shallowMount } from 'web-test-helpers'
import { FileContext, useAppDefaults } from 'web-pkg/src/composables/appDefaults'
import { useAppDefaultsMock } from 'web-test-helpers/src/mocks/useAppDefaultsMock'
import { ref } from '@vue/composition-api'
import { mockDeep } from 'jest-mock-extended'
import { defaultStoreMockOptions } from 'web-test-helpers/src/mocks/store/defaultStoreMockOptions'

const localVue = createLocalVue()

localVue.use(GetTextPlugin, {
translations: 'does-not-matter.json',
silent: true
jest.mock('web-pkg/src/composables/appDefaults', () => {
const { queryItemAsString } = jest.requireActual('web-pkg/src/composables/appDefaults')
return {
useAppDefaults: jest.fn(),
useAppFileHandling: jest.fn(),
queryItemAsString
}
})
localVue.use(Vuex)

const componentStubs = {
ErrorScreen: true,
LoadingScreen: true
}

const $route = {
query: {
'public-token': 'a-token',
app: 'exampleApp',
fileId: '2147491323'
},
params: {
filePath: 'someFile.md'
}
}

const mockFileInfo = jest.fn(() => ({
name: $route.params.filePath,
fileInfo: {
'{http://owncloud.org/ns}fileid': '2147491323'
}
}))

const storeOptions = {
getters: {
configuration: jest.fn(() => ({
server: 'http://example.com/',
currentTheme: {
general: {
name: 'some-company'
}
}
})),
capabilities: jest.fn(() => ({
files: {
app_providers: [
{
apps_url: '/app/list',
enabled: true,
open_url: '/app/open'
}
]
}
}))
},
modules: {
External: {
namespaced: true,
getters: {
mimeTypes: jest.fn()
},
actions: {
fetchMimeTypes: jest.fn()
},
mutations: {
SET_MIME_TYPES: jest.fn()
}
},
runtime: {
namespaced: true,
modules: {
auth: {
namespaced: true,
getters: {
accessToken: jest.fn(() => 'GFwHKXdsMgoFwt'),
isUserContextReady: jest.fn(() => true)
}
}
}
}
}
}

const appUrl = 'https://example.test/d12ab86/loe009157-MzBw'

const providerSuccessResponsePost = {
Expand All @@ -102,107 +38,101 @@ const providerSuccessResponseGet = {

describe('The app provider extension', () => {
beforeEach(() => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
jest.spyOn(console, 'error').mockImplementation(() => {})
jest.spyOn(console, 'error').mockImplementation(() => undefined)
})

afterEach(() => {
jest.clearAllMocks()
})

it('should show a loading spinner while loading', async () => {
const makeRequest = jest.fn(
() =>
new Promise((resolve) => {
setTimeout(() => {
resolve({
ok: true,
status: 200
})
}, 500)
})
)
const wrapper = createShallowMountWrapper(makeRequest)
const { wrapper } = createShallowMountWrapper()
await wrapper.vm.$nextTick()
expect(wrapper).toMatchSnapshot()
})
it('should show a meaningful message if an error occurs during loading', async () => {
const makeRequest = jest.fn(() =>
Promise.resolve({
ok: false,
status: 500,
message: 'We encountered an internal error'
})
)
const wrapper = createShallowMountWrapper(makeRequest)
const makeRequest = jest.fn().mockResolvedValue({
ok: false,
status: 500,
message: 'We encountered an internal error'
})
const { wrapper } = createShallowMountWrapper(makeRequest)
await wrapper.vm.$nextTick()
await wrapper.vm.$nextTick()
expect(wrapper).toMatchSnapshot()
})
it('should fail for unauthenticated users', async () => {
const makeRequest = jest.fn(() =>
Promise.resolve({
ok: true,
status: 401,
message: 'Login Required'
})
)
const wrapper = createShallowMountWrapper(makeRequest)
const makeRequest = jest.fn().mockResolvedValue({
ok: true,
status: 401,
message: 'Login Required'
})
const { wrapper } = createShallowMountWrapper(makeRequest)
await wrapper.vm.$nextTick()
await wrapper.vm.$nextTick()
expect(wrapper).toMatchSnapshot()
})
it('should be able to load an iFrame via get', async () => {
const makeRequest = jest.fn(() =>
Promise.resolve({
ok: true,
status: 200,
data: providerSuccessResponseGet
})
)
const makeRequest = jest.fn().mockResolvedValue({
ok: true,
status: 200,
data: providerSuccessResponseGet
})

const wrapper = createShallowMountWrapper(makeRequest)
const { wrapper } = createShallowMountWrapper(makeRequest)
await wrapper.vm.$nextTick()
await wrapper.vm.$nextTick()
await wrapper.vm.$nextTick()
expect(wrapper).toMatchSnapshot()
})
it('should be able to load an iFrame via post', async () => {
const makeRequest = jest.fn(() =>
Promise.resolve({
ok: true,
status: 200,
data: providerSuccessResponsePost
})
)
const wrapper = createShallowMountWrapper(makeRequest)
const makeRequest = jest.fn().mockResolvedValue({
ok: true,
status: 200,
data: providerSuccessResponsePost
})
const { wrapper } = createShallowMountWrapper(makeRequest)
await wrapper.vm.$nextTick()
await wrapper.vm.$nextTick()
await wrapper.vm.$nextTick()
expect(wrapper).toMatchSnapshot()
})
})

function createShallowMountWrapper(makeRequest, options = {}) {
return shallowMount(App, {
localVue,
store: createStore(),
stubs: componentStubs,
mocks: {
$route
},
computed: {
currentFileContext: () => $route.params,
applicationName: () => $route.query.app
},
methods: {
getFileInfo: mockFileInfo,
function createShallowMountWrapper(makeRequest = jest.fn().mockResolvedValue({ status: 200 })) {
jest.mocked(useAppDefaults).mockImplementation(() =>
useAppDefaultsMock({
currentFileContext: ref(mockDeep<FileContext>({ path: 'someFile.md' })),
makeRequest
},
...options
})
}
})
)

function createStore() {
return new Vuex.Store(storeOptions)
const storeOptions = defaultStoreMockOptions
storeOptions.getters.capabilities.mockImplementation(() => ({
files: {
app_providers: [
{
apps_url: '/app/list',
enabled: true,
open_url: '/app/open'
}
]
}
}))

const store = createStore(storeOptions)
return {
wrapper: shallowMount(App, {
global: {
plugins: [...defaultPlugins(), store],
stubs: componentStubs,
mocks: {
...defaultComponentMocks({
gettext: false,
currentRoute: { query: { app: 'exampleApp' } }
})
}
}
})
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
import ErrorScreen from '../../../src/components/ErrorScreen.vue'
import { Wrapper, mount, createLocalVue } from '@vue/test-utils'
import GetTextPlugin from 'vue-gettext'

const localVue = createLocalVue()

localVue.use(GetTextPlugin, {
translations: 'does-not-matter.json',
silent: true
})

let wrapper: Wrapper<any>
import { defaultPlugins, mount } from 'web-test-helpers'

describe('The external app error screen component', () => {
test('displays an icon and a paragraph', () => {
wrapper = mount(ErrorScreen, {
localVue,
stubs: {
OcIcon: true
},
propsData: {
const wrapper = mount(ErrorScreen, {
props: {
message: 'Error when loading the application'
},
global: {
stubs: {
OcIcon: true
},
plugins: [...defaultPlugins()]
}
})
expect(wrapper).toMatchSnapshot()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import LoadingScreen from '../../../src/components/LoadingScreen.vue'
import { Wrapper, mount, createLocalVue } from '@vue/test-utils'
import GetTextPlugin from 'vue-gettext'

const localVue = createLocalVue()

localVue.use(GetTextPlugin, {
translations: 'does-not-matter.json',
silent: true
})

let wrapper: Wrapper<any>
import { defaultPlugins, mount } from 'web-test-helpers'

describe('The external app loading screen component', () => {
test('displays a spinner and a paragraph', () => {
wrapper = mount(LoadingScreen, {
localVue,
stubs: {
OcSpinner: true
const wrapper = mount(LoadingScreen, {
global: {
stubs: {
OcSpinner: true
},
plugins: [...defaultPlugins()]
}
})
expect(wrapper).toMatchSnapshot()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`The external app error screen component displays an icon and a paragraph 1`] = `
<div class="oc-text-center">
<ocicon-stub size="xxlarge" name="error-warning" fill-type="line"></ocicon-stub>
<ocicon-stub name="error-warning" filltype="line" accessiblelabel="" type="span" size="xxlarge" variation="passive" color=""></ocicon-stub>
<p class="oc-text-xlarge">Error when loading the application</p>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`The external app loading screen component displays a spinner and a paragraph 1`] = `
<div class="oc-text-center">
<ocspinner-stub size="xlarge"></ocspinner-stub>
<p class="oc-invisible" data-msgid="Loading app" data-current-language="en_US">Loading app</p>
<ocspinner-stub arialabel="" size="xlarge"></ocspinner-stub>
<p class="oc-invisible">Loading app</p>
</div>
`;
4 changes: 2 additions & 2 deletions packages/web-app-files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"vue-resize": "^1.0.1",
"vue-router": "3.6.5",
"vuex": "^3.6.2",
"vuex-extensions": "^1.1.5",
"web-app-search": "workspace:*",
"web-client": "npm:@ownclouders/web-client",
"web-pkg": "npm:@ownclouders/web-pkg",
"web-runtime": "workspace:*"
"web-runtime": "workspace:*",
"web-test-helpers": "workspace:*"
}
}
4 changes: 2 additions & 2 deletions packages/web-app-files/src/components/Search/Preview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { ImageDimension, ImageType } from '../../constants'
import { loadPreview } from 'web-pkg/src/helpers/preview'
import debounce from 'lodash-es/debounce'
import Vue from 'vue'
import { mapGetters, mapState } from 'vuex'
import { mapGetters } from 'vuex'
import { createLocationShares, createLocationSpaces } from '../../router'
import { basename, dirname } from 'path'
import { useAccessToken, useCapabilityShareJailEnabled, useStore } from 'web-pkg/src/composables'
Expand Down Expand Up @@ -63,7 +63,7 @@ export default defineComponent({
},
computed: {
...mapGetters(['configuration', 'user']),
...mapState('runtime/spaces', ['spaces']),
...mapGetters('runtime/spaces', ['spaces']),

attrs() {
return this.resource.isFolder
Expand Down
Loading