Skip to content

Commit

Permalink
update tests after component changes
Browse files Browse the repository at this point in the history
  • Loading branch information
saw-jan committed Oct 28, 2021
1 parent f54dea3 commit ee432a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11,461 deletions.
40 changes: 10 additions & 30 deletions packages/web-app-files/tests/unit/views/SharedViaLink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import flushPromises from 'flush-promises'
import { getStore, localVue, createFile } from './views.setup.js'
import MixinFilesListPagination from '@files/src/mixins/filesListPagination'
import FileActions from '@files/src/mixins/fileActions'
import MixinFilesListPositioning from '@files/src/mixins/filesListPositioning'
import SharedViaLink from '@files/src/views/SharedViaLink.vue'

const $route = {
Expand All @@ -15,7 +14,7 @@ const $route = {
}
}

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

localVue.prototype.$client.requests = {
ocs: jest.fn(() =>
Expand All @@ -24,7 +23,7 @@ localVue.prototype.$client.requests = {
json: jest.fn(() =>
Promise.resolve({
ocs: {
data: activeFiles
data: activeFilesCurrentPage
}
})
)
Expand Down Expand Up @@ -53,34 +52,15 @@ describe('SharedViaLink view', () => {
jest
.spyOn(MixinFilesListPagination.methods, '$_filesListPagination_updateCurrentPage')
.mockImplementation()
const spyAdjustTableHeaderPosition = jest.spyOn(
MixinFilesListPositioning.methods,
'adjustTableHeaderPosition'
)
const spyTriggerDefaultAction = jest
.spyOn(FileActions.methods, '$_fileActions_triggerDefaultAction')
.mockImplementation()
const spyLoadResources = jest.spyOn(SharedViaLink.methods, 'loadResources')
const spyRowMounted = jest.spyOn(SharedViaLink.methods, 'rowMounted')

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

describe('when the page has loaded successfully', () => {
beforeEach(async () => {
getShallowWrapper()
await flushPromises()
})

it('should load the resources', () => {
expect(spyLoadResources).toHaveBeenCalledTimes(1)
})
it('should adjust the table header position', () => {
expect(spyAdjustTableHeaderPosition).toHaveBeenCalledTimes(1)
})
})

describe('when the view is still loading', () => {
it('should show list-loader component', () => {
const wrapper = getShallowWrapper()
Expand Down Expand Up @@ -122,7 +102,7 @@ describe('SharedViaLink view', () => {
let wrapper
beforeEach(async () => {
stubs['oc-table-files'] = false
wrapper = getWrapper(activeFiles)
wrapper = getWrapper(activeFilesCurrentPage)
await flushPromises()
})

Expand All @@ -133,20 +113,20 @@ describe('SharedViaLink view', () => {
const ocTableFiles = wrapper.find(selectors.ocTableFiles)

expect(ocTableFiles.exists()).toBeTruthy()
expect(ocTableFiles.props().resources).toMatchObject(activeFiles)
expect(ocTableFiles.props().resources).toMatchObject(activeFilesCurrentPage)
expect(ocTableFiles.props().areThumbnailsDisplayed).toBe(false)
expect(ocTableFiles.props().headerPosition).toBe(0)
expect(ocTableFiles.props().targetRoute).toMatchObject({ name: 'files-personal' })
})
it('should set props on context-actions component', () => {
const contextActions = wrapper.find(selectors.contextActions)

expect(contextActions.props().item).toMatchObject(activeFiles[0])
expect(contextActions.props().item).toMatchObject(activeFilesCurrentPage[0])
})
it('should set props on list-info component', () => {
const listInfo = wrapper.find(selectors.listInfo)

expect(listInfo.props().files).toEqual(activeFiles.length)
expect(listInfo.props().files).toEqual(activeFilesCurrentPage.length)
expect(listInfo.props().folders).toEqual(0)
})
it('should trigger the default action when a "fileClick" event gets emitted', () => {
Expand All @@ -159,7 +139,7 @@ describe('SharedViaLink view', () => {
expect(spyTriggerDefaultAction).toHaveBeenCalledTimes(1)
})
it('should lazily load previews when a "rowMounted" event gets emitted', () => {
expect(spyRowMounted).toHaveBeenCalledTimes(activeFiles.length)
expect(spyRowMounted).toHaveBeenCalledTimes(activeFilesCurrentPage.length)
})
})
})
Expand All @@ -186,9 +166,9 @@ function getShallowWrapper(files = []) {
})
}

function createStore(activeFiles) {
function createStore(activeFilesCurrentPage) {
return getStore({
activeFiles,
totalFilesCount: { files: activeFiles.length, folders: 0 }
activeFilesCurrentPage,
totalFilesCount: { files: activeFilesCurrentPage.length, folders: 0 }
})
}
Loading

0 comments on commit ee432a6

Please sign in to comment.