Skip to content

Commit

Permalink
Added unit tests for resources mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
kiranparajuli589 committed Aug 9, 2021
1 parent c778eda commit 492fe47
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/web-app-files/tests/unit/mixins/resources.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import resources from '@files/src/mixins/resources.js'
import { shallowMount } from '@vue/test-utils'

const getWrapper = () => {
const Component = {
render() {}
}
return shallowMount(Component, {
mixins: [resources]
})
}

describe('resources', () => {
describe('getResourcesSize', () => {
const wrapper = getWrapper()

it('should return empty string if size is less than zero', () => {
expect(wrapper.vm.getResourceSize(-1)).toEqual('')
})

it('should return "?" if size is not a number', () => {
expect(wrapper.vm.getResourceSize('string')).toEqual('?')
})

it.each([
{ size: '0', expectedSize: '0 B' },
{ size: '1', expectedSize: '1 B' },
{ size: '1024', expectedSize: '1 KB' },
{ size: '1048576', expectedSize: '1 MB' }
])('should return formatted size of given resource', sizeInput => {
expect(wrapper.vm.getResourceSize(sizeInput.size)).toEqual(sizeInput.expectedSize)
})

it('should not show round value for size less than a MB', () => {
expect(wrapper.vm.getResourceSize('4321')).toEqual('4 KB')
})

it('should show single round value for size larger than a MB', () => {
expect(wrapper.vm.getResourceSize('4321000')).toEqual('4.1 MB')
})
})
})

0 comments on commit 492fe47

Please sign in to comment.