Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saw-jan committed Dec 9, 2021
1 parent 81c9026 commit 3a54934
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 54 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-vue": "^7.13.0",
"eslint-plugin-vuejs-accessibility": "^0.7.1",
"flush-promises": "^1.0.2",
"focus-trap": "^6.4.0",
"focus-trap-vue": "^1.1.1",
"jest": "^26.6.3",
Expand Down
70 changes: 39 additions & 31 deletions packages/web-app-files/tests/unit/views/SharedViaLink.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { shallowMount, mount } from '@vue/test-utils'
import flushPromises from 'flush-promises'
import { useTask } from 'vue-concurrency'
import { getStore, localVue, createFile } from './views.setup.js'
import MixinFilesListPagination from '@files/src/mixins/filesListPagination'
import FileActions from '@files/src/mixins/fileActions'
import SharedViaLink from '@files/src/views/SharedViaLink.vue'

const $router = {
afterEach: jest.fn(),
currentRoute: {
query: {
name: null
}
}
}

const $route = {
params: {
fileId: '2147491323'
Expand All @@ -14,21 +22,19 @@ const $route = {
}
}

const activeFilesCurrentPage = [createFile({ id: 1234, type: 'file' })]

const activeFilesCurrentPage = [createFile({ id: 2147491323, type: 'file' })]
localVue.use(useTask)
localVue.prototype.$client.requests = {
ocs: jest.fn(() =>
Promise.resolve({
status: 200,
json: jest.fn(() =>
Promise.resolve({
ocs: {
data: activeFilesCurrentPage
}
})
)
})
)
ocs: jest.fn(() => ({
status: 200,
json: jest.fn(() =>
Promise.resolve({
ocs: {
data: activeFilesCurrentPage
}
})
)
}))
}

const stubs = {
Expand All @@ -41,17 +47,14 @@ const stubs = {
}

const selectors = {
listLoader: 'list-loader-stub',
listLoader: '#files-list-progress',
noContentMessage: '#files-shared-via-link-empty',
ocTableFiles: '#files-shared-via-link-table',
contextActions: 'context-actions-stub',
listInfo: 'list-info-stub'
}

describe('SharedViaLink view', () => {
jest
.spyOn(MixinFilesListPagination.methods, '$_filesListPagination_updateCurrentPage')
.mockImplementation()
const spyTriggerDefaultAction = jest
.spyOn(FileActions.methods, '$_fileActions_triggerDefaultAction')
.mockImplementation()
Expand All @@ -61,10 +64,10 @@ describe('SharedViaLink view', () => {
jest.clearAllMocks()
})

describe('when the view is still loading', () => {
describe.only('when the view is still loading', () => {
it('should show list-loader component', () => {
const store = createStore()
const wrapper = getShallowWrapper(store)
const wrapper = getWrapper(store)
const listLoader = wrapper.find(selectors.listLoader)

expect(listLoader.exists()).toBeTruthy()
Expand All @@ -73,11 +76,17 @@ describe('SharedViaLink view', () => {
})

describe('when the view is not loading anymore', () => {
it('should not show list-loader component', async () => {
it.only('should not show list-loader component', async () => {
const store = createStore()
const wrapper = getShallowWrapper(store)
await flushPromises()

const wrapper = getWrapper(store)
// these are required to wait for all async tasks to resolve
// and loadResourcesTask.isRunning to be false
// or we can use fulsh-promises
await wrapper.vm.$nextTick()
await wrapper.vm.$nextTick()
await wrapper.vm.$nextTick()
await wrapper.vm.$nextTick()
await wrapper.vm.$nextTick()
expect(wrapper.find(selectors.listLoader).exists()).toBeFalsy()
})

Expand All @@ -87,7 +96,6 @@ describe('SharedViaLink view', () => {
stubs['no-content-message'] = false
const store = createStore()
wrapper = getWrapper(store)
await flushPromises()
})

it('should show no-content-message component', () => {
Expand All @@ -106,7 +114,6 @@ describe('SharedViaLink view', () => {
beforeEach(async () => {
const store = createStore(activeFilesCurrentPage)
wrapper = getWrapper(store)
await flushPromises()
})

it('should not show no-content-message component', () => {
Expand Down Expand Up @@ -149,7 +156,6 @@ describe('SharedViaLink view', () => {
it('should set props on context-actions component', async () => {
const store = createStore(activeFilesCurrentPage, activeFilesCurrentPage[0])
const wrapper = getWrapper(store)
await flushPromises()

const contextActions = wrapper.find(selectors.contextActions)

Expand All @@ -167,7 +173,8 @@ function getWrapper(store) {
store,
stubs,
mocks: {
$route
$route,
$router
}
})
}
Expand All @@ -177,7 +184,8 @@ function getShallowWrapper(store) {
localVue,
store,
mocks: {
$route
$route,
$router
}
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SharedViaLink view when the view is not loading anymore when there are no files to be displayed should show no-content-message component 1`] = `
<div>
<div class="uk-height-1-1 uk-flex uk-flex-column uk-flex-center uk-flex-middle uk-text-center files-empty" id="files-shared-via-link-empty">
<div class="oc-icon oc-icon-xxl oc-icon-passive"><svg viewBox="0 0 24 24" height="24" width="24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
<path xmlns="http://www.w3.org/2000/svg" d="M0 0h24v24H0z" fill="none"></path>
<path xmlns="http://www.w3.org/2000/svg" d="M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5c-1.66 0-3 1.34-3 3s1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5C6.34 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V19h14v-2.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05 1.16.84 1.97 1.97 1.97 3.45V19h6v-2.5c0-2.33-4.67-3.5-7-3.5z"></path>
</svg></div>
<div class="oc-text-muted uk-text-large"><span data-msgid="There are no resources with a public link at the moment" data-current-language="en_US">There are no resources with a public link at the moment</span></div>
<div class="oc-text-muted"></div>
</div>
</div>
`;

exports[`SharedViaLink view when the view is still loading should show list-loader component 1`] = `
<div>
<list-loader-stub></list-loader-stub>
<div class="uk-flex uk-flex-middle uk-flex-center uk-height-1-1"><span aria-label="" tabindex="-1" role="img" class="oc-spinner oc-spinner-l" id="files-list-progress" aria-hidden="true"></span></div>
</div>
`;
8 changes: 0 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6725,13 +6725,6 @@ __metadata:
languageName: node
linkType: hard

"flush-promises@npm:^1.0.2":
version: 1.0.2
resolution: "flush-promises@npm:1.0.2"
checksum: 4451bfb21a11e64b8359c496cc875f7279a62c17e0cd3dba4adea83c098bb4497cdd8685d04dec46926d268e21e61b8d76cc92eedf396e18df8e501c9e9eb772
languageName: node
linkType: hard

"focus-trap-vue@npm:^1.1.1":
version: 1.1.1
resolution: "focus-trap-vue@npm:1.1.1"
Expand Down Expand Up @@ -12826,7 +12819,6 @@ __metadata:
eslint-plugin-promise: ^5.1.0
eslint-plugin-vue: ^7.13.0
eslint-plugin-vuejs-accessibility: ^0.7.1
flush-promises: ^1.0.2
focus-trap: ^6.4.0
focus-trap-vue: ^1.1.1
jest: ^26.6.3
Expand Down

0 comments on commit 3a54934

Please sign in to comment.