Skip to content

Commit

Permalink
tests(front): test highlighted job field
Browse files Browse the repository at this point in the history
Also update div ids in exiting test to match new anchors names.
  • Loading branch information
rezib committed Nov 11, 2024
1 parent 1611ac3 commit f0deb86
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
41 changes: 32 additions & 9 deletions frontend/tests/views/JobView.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import { ref, nextTick } from 'vue'
import { describe, test, expect, beforeEach, vi } from 'vitest'
import { mount } from '@vue/test-utils'
import { useRuntimeStore } from '@/stores/runtime'
import JobView from '@/views/JobView.vue'
import { init_plugins, getMockClusterDataPoller } from './common'
import type { ClusterIndividualJob } from '@/composables/GatewayAPI'
import jobRunning from '../assets/job-running.json'
import type { RouterMock } from 'vue-router-mock'

const mockClusterDataPoller = getMockClusterDataPoller<ClusterIndividualJob>()

vi.mock('@/composables/DataPoller', () => ({
useClusterDataPoller: () => mockClusterDataPoller
}))

let router: RouterMock

describe('JobView.vue', () => {
beforeEach(() => {
init_plugins()
router = init_plugins()
useRuntimeStore().availableClusters = [
{ name: 'foo', permissions: { roles: [], actions: [] }, infrastructure: 'foo', metrics: true }
]
})
test('display job details', () => {
mockClusterDataPoller.data.value = jobRunning
Expand All @@ -24,13 +32,28 @@ describe('JobView.vue', () => {
}
})
// Check some jobs fields
expect(wrapper.get('dl div#job-user dd').text()).toBe(jobRunning.user)
expect(wrapper.get('dl div#job-group dd').text()).toBe(jobRunning.group)
expect(wrapper.get('dl div#job-account dd').text()).toBe(jobRunning.association.account)
expect(wrapper.get('dl div#job-priority dd').text()).toBe(jobRunning.priority.number.toString())
expect(wrapper.get('dl div#job-workdir dd').text()).toBe(jobRunning.working_directory)
expect(wrapper.get('dl div#job-nodes dd').text()).toBe(jobRunning.nodes)
expect(wrapper.get('dl div#job-partition dd').text()).toBe(jobRunning.partition)
expect(wrapper.get('dl div#job-qos dd').text()).toBe(jobRunning.qos)
expect(wrapper.get('dl div#user dd').text()).toBe(jobRunning.user)
expect(wrapper.get('dl div#group dd').text()).toBe(jobRunning.group)
expect(wrapper.get('dl div#account dd').text()).toBe(jobRunning.association.account)
expect(wrapper.get('dl div#priority dd').text()).toBe(jobRunning.priority.number.toString())
expect(wrapper.get('dl div#workdir dd').text()).toBe(jobRunning.working_directory)
expect(wrapper.get('dl div#nodes dd').text()).toBe(jobRunning.nodes)
expect(wrapper.get('dl div#partition dd').text()).toBe(jobRunning.partition)
expect(wrapper.get('dl div#qos dd').text()).toBe(jobRunning.qos)
})
test('highlight job field in route hash', async () => {
await router.setHash('#user')
mockClusterDataPoller.data.value = jobRunning
const wrapper = mount(JobView, {
props: {
cluster: 'foo',
id: 1234
}
})
await nextTick()
// Check user field is highlighted with specific background color due to
// #user hash in route while group field is not highlighted.
expect(wrapper.get('dl div#user').classes('bg-slurmweb-light')).toBe(true)
expect(wrapper.get('dl div#group').classes('bg-slurmweb-light')).toBe(false)
})
})
3 changes: 2 additions & 1 deletion frontend/tests/views/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { httpPlugin } from '@/plugins/http'
import { createTestingPinia } from '@pinia/testing'
import { config, RouterLinkStub } from '@vue/test-utils'
import { createRouterMock, injectRouterMock } from 'vue-router-mock'
import type { RouterMock } from 'vue-router-mock'

export function init_plugins() {
export function init_plugins(): RouterMock {
config.global.plugins = [
[
runtimeConfiguration,
Expand Down

0 comments on commit f0deb86

Please sign in to comment.