Skip to content

Commit

Permalink
Add unit tests for useSpaceHelpers
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Apr 4, 2023
1 parent ab66358 commit e7c6b0e
Showing 1 changed file with 40 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,64 @@ import {
defaultStoreMockOptions,
getComposableWrapper
} from 'web-test-helpers'
import { SpaceResource } from 'web-client'
import { useFileActionsSetReadme } from 'web-pkg/src/composables/actions'
import { unref } from 'vue'

describe('useCapability', () => {
describe('useSpaceHelpers', () => {
it('should be valid', () => {
expect(useSpaceHelpers).toBeDefined()
})
describe('method "checkName"', () => {
describe('method "checkSpaceNameModalInput"', () => {
it('should not show an error message with a valid space name', () => {
const { checkSpaceNameModalInput } = useSpaceHelpers()
checkSpaceNameModalInput('Space')

const { wrapper } = getWrapper({
setup: ({ actions }) => {
expect(
unref(actions)[0].isEnabled({
space,
resources: [{ id: 1, mimeType: 'text/plain' }] as SpaceResource[]
})
).toBe(false)
getWrapper({
setup: ({ checkSpaceNameModalInput }, { storeOptions }) => {
checkSpaceNameModalInput('Space')
const { setModalInputErrorMessage } = storeOptions.actions
expect(setModalInputErrorMessage).toHaveBeenCalledWith(expect.anything(), null)
}
})
})
it('should show an error message with an empty name', () => {
getWrapper({
setup: ({ checkSpaceNameModalInput }, { storeOptions }) => {
checkSpaceNameModalInput('')
const { setModalInputErrorMessage } = storeOptions.actions
expect(setModalInputErrorMessage).not.toHaveBeenCalledWith(expect.anything(), null)
}
})
})
it('should show an error with an name longer than 255 characters', () => {
getWrapper({
setup: ({ checkSpaceNameModalInput }, { storeOptions }) => {
checkSpaceNameModalInput('n'.repeat(256))
const { setModalInputErrorMessage } = storeOptions.actions
expect(setModalInputErrorMessage).not.toHaveBeenCalledWith(expect.anything(), null)
}
})
})
it.each(['/', '\\', '.', ':', '?', '*', '"', '>', '<', '|'])(
'should show an error message with a name including a special character',
(specialChar) => {
getWrapper({
setup: ({ checkSpaceNameModalInput }, { storeOptions }) => {
checkSpaceNameModalInput(specialChar)
const { setModalInputErrorMessage } = storeOptions.actions
expect(setModalInputErrorMessage).not.toHaveBeenCalledWith(expect.anything(), null)
}
})
}
)
})
})

function getWrapper({
setup
}: {
setup: (
instance: ReturnType<typeof useFileActionsSetReadme>,
instance: ReturnType<typeof useSpaceHelpers>,
options: { storeOptions: typeof defaultStoreMockOptions }
) => void
}) {
const mocks = {
...defaultComponentMocks({})
}

const storeOptions = {
...defaultStoreMockOptions
}

const mocks = defaultComponentMocks()
const storeOptions = defaultStoreMockOptions
const store = createStore(storeOptions)
return {
wrapper: getComposableWrapper(
Expand Down

0 comments on commit e7c6b0e

Please sign in to comment.