Skip to content

Commit

Permalink
format: prettier and lint updates
Browse files Browse the repository at this point in the history
  • Loading branch information
seenanair committed Nov 8, 2024
1 parent 880c157 commit 672d98e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
3 changes: 1 addition & 2 deletions app/frontend/javascript/vue_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const missingUserIdError = `
Click log out and swipe in again to resolve this.
If this problem occurs repeatedly, let us know.`

/**
/**
* Helper function to initialize and render a Vue component.
*
* @param {string} selector - The CSS selector of the DOM element to mount the Vue instance on.
Expand All @@ -65,7 +65,6 @@ export const renderVueComponent = (selector, component, props = {}, data = {}, u
el: selector_val,
render: (h) => h('div', missingUserIdError),
})

} else {
app = new Vue({
el: selector_val,
Expand Down
22 changes: 10 additions & 12 deletions app/frontend/javascript/vue_app.spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { renderVueComponent, missingUserIdError} from './vue_app.js'
import { mount } from '@vue/test-utils'
import Vue from 'vue'
import { renderVueComponent, missingUserIdError } from './vue_app.js'
import * as cookieJarLib from '@/javascript/shared/cookieJar.js'

describe('renderVueComponent', () => {
let component, props, data, selector, element, userIdRequired

beforeEach(() => {
component = {
name: 'TestComponent',
render(h) {
return h('div','Test string')
}
};
name: 'TestComponent',
render(h) {
return h('div', 'Test string')
},
}
props = { propA: 'valueA' }
data = { dataA: 'valueA' }
selector = 'test-selector'
Expand Down Expand Up @@ -39,20 +38,19 @@ describe('renderVueComponent', () => {
})
it('renders the Vue component when userId is required and found', () => {
userIdRequired = true
vi.spyOn(cookieJarLib,'default').mockReturnValue({ user_id: 'mocked_user_id' })
vi.spyOn(cookieJarLib, 'default').mockReturnValue({ user_id: 'mocked_user_id' })
renderVueComponent(selector, component, props, data, userIdRequired)
expect(document.body.innerHTML).toContain('Test string')
})
it('renders missingUserIdError when userId is required but not found', () => {
vi.spyOn(cookieJarLib,'default').mockReturnValue({ user_id: null })
vi.spyOn(cookieJarLib, 'default').mockReturnValue({ user_id: null })
userIdRequired = true
const app = renderVueComponent(selector, component, props, data, userIdRequired)
expect(app.$el.innerHTML).toContain(missingUserIdError)
})
it('renders the Vue component when userId is not required and not found', () => {
vi.spyOn(cookieJarLib,'default').mockReturnValue({ user_id: null })
vi.spyOn(cookieJarLib, 'default').mockReturnValue({ user_id: null })
const app = renderVueComponent(selector, component, props, data, userIdRequired)
expect(app.$el.innerHTML).toContain('Test string')
})

})

0 comments on commit 672d98e

Please sign in to comment.