Skip to content

Commit

Permalink
Extract mocked folder to test for privateLink in clipboard-copy unit …
Browse files Browse the repository at this point in the history
…test
  • Loading branch information
pascalwengerter committed Dec 20, 2022
1 parent 7dbe88c commit 1b24555
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import { createStore, defaultPlugins, mount, defaultStoreMockOptions } from 'web

jest.useFakeTimers()

const folder = mockDeep<Resource>({
type: 'folder',
ownerId: 'marie',
ownerDisplayName: 'Marie',
mdate: 'Wed, 21 Oct 2015 07:28:00 GMT',
size: '740',
name: 'lorem.txt',
privateLink: 'https://example.com/fake-private-link'
})

describe('PrivateLinkItem', () => {
it('should render a button', () => {
const { wrapper } = getWrapper()
Expand All @@ -23,9 +33,7 @@ describe('PrivateLinkItem', () => {

await wrapper.trigger('click')
expect(wrapper.html()).toMatchSnapshot()
expect(window.navigator.clipboard.writeText).toHaveBeenCalledWith(
wrapper.vm._provided.displayedItem.privateLink
)
expect(window.navigator.clipboard.writeText).toHaveBeenCalledWith(folder.privateLink)
expect(spyShowMessage).toHaveBeenCalledTimes(1)

jest.advanceTimersByTime(550)
Expand All @@ -37,15 +45,6 @@ describe('PrivateLinkItem', () => {
})

function getWrapper() {
const folder = mockDeep<Resource>({
type: 'folder',
ownerId: 'marie',
ownerDisplayName: 'Marie',
mdate: 'Wed, 21 Oct 2015 07:28:00 GMT',
size: '740',
name: 'lorem.txt',
privateLink: 'https://example.com/fake-private-link'
})
const storeOptions = { ...defaultStoreMockOptions }
storeOptions.getters.capabilities.mockImplementation(() => ({ files: { privateLinks: true } }))
storeOptions.modules.Files.getters.highlightedFile.mockImplementation(() => folder)
Expand Down

0 comments on commit 1b24555

Please sign in to comment.