Skip to content

Commit

Permalink
feat(jest): 75% coverage for components/mixins/UserPermissions
Browse files Browse the repository at this point in the history
  • Loading branch information
drepram committed Mar 17, 2022
1 parent 7e68620 commit 1865939
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
20 changes: 20 additions & 0 deletions components/mixins/UserPermissions/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`index.UserPermissions.created 0 1`] = `undefined`;

exports[`index.exportForTesting.formatDevices 0 1`] = `
Array [
Object {
"text": "videoinput: FaceTime HD Camera (Built-in) ",
"value": "id=csO9c0YpAf274OuCPUA53CNE0YHlIr2yXCi+SqfBZZ8=",
},
Object {
"text": "audioinput: default (Built-in Microphone) ",
"value": "id=RKxXByjnabbADGQNNZqLVLdmXlS0YkETYCIbg+XxnvM=",
},
Object {
"text": "audioinput: Built-in Microphone ",
"value": "id=r2/xw1xUPIyZunfV1lGrKOma5wTOvCkWfZ368XCndm0=",
},
]
`;
48 changes: 48 additions & 0 deletions components/mixins/UserPermissions/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,55 @@
import { result } from 'lodash'
import * as index from '~/components/mixins/UserPermissions/index'

describe('index.UserPermissions.created', () => {
test('0', () => {
const result: any = index.UserPermissions.created()
expect(result).toMatchSnapshot()
})
})
describe('index.UserPermissions.methods.getUserPermissions', () => {
test('0', async () => {
await index.UserPermissions.methods.getUserPermissions()
})
})
describe('index.UserPermissions.methods.requestUserPermissions', () => {
test('0', async () => {
const mockObj = { a: 'b' }
window.navigator = jest.fn()
window.navigator.mediaDevices = jest.fn()
window.navigator.mediaDevices.getUserMedia = jest
.fn()
.mockReturnValueOnce(mockObj)

const result = await index.UserPermissions.methods.requestUserPermissions({
audio: true,
peerIdentity: 'identity',
preferCurrentTab: true,
video: false,
})

expect(result).toMatchObject(mockObj)
})
})
describe('index.exportForTesting.formatDevices', () => {
test('0', async () => {
const devices = [
{
label: 'videoinput: FaceTime HD Camera (Built-in) ',
deviceId: 'id=csO9c0YpAf274OuCPUA53CNE0YHlIr2yXCi+SqfBZZ8=',
},
{
label: 'audioinput: default (Built-in Microphone) ',
deviceId: 'id=RKxXByjnabbADGQNNZqLVLdmXlS0YkETYCIbg+XxnvM=',
},
{
label: 'audioinput: Built-in Microphone ',
deviceId: 'id=r2/xw1xUPIyZunfV1lGrKOma5wTOvCkWfZ368XCndm0=',
},
]

const result = await index.exportForTesting.formatDevices(devices)

expect(result).toMatchSnapshot()
})
})
4 changes: 4 additions & 0 deletions components/mixins/UserPermissions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,7 @@ export const UserPermissions = {
}

export default UserPermissions

export const exportForTesting = {
formatDevices,
}

0 comments on commit 1865939

Please sign in to comment.