|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +import { describe, test, expect, vi, beforeEach } from 'vitest' |
| 19 | +import { flushPromises, mount } from '@vue/test-utils' |
| 20 | +// import { createTestingPinia } from '@pinia/testing' |
| 21 | +import { createApp } from 'vue' |
| 22 | +import { createPinia, setActivePinia } from 'pinia' |
| 23 | +import i18n from '@/locales' |
| 24 | +import type { Overview } from '@/service/overview/types' |
| 25 | +import baseInfo from '@/views/overview/baseInfo' |
| 26 | +import { overviewService } from '@/service/overview' |
| 27 | + |
| 28 | +describe('jobs', () => { |
| 29 | + const app = createApp({}) |
| 30 | + beforeEach(() => { |
| 31 | + const pinia = createPinia() |
| 32 | + app.use(pinia) |
| 33 | + setActivePinia(createPinia()) |
| 34 | + }) |
| 35 | + test('BaseInfo component', async () => { |
| 36 | + const mockData = { |
| 37 | + cancelledJobs: '222', |
| 38 | + failedJobs: '0', |
| 39 | + finishedJobs: '3', |
| 40 | + gitCommitAbbrev: '4f812e1', |
| 41 | + projectVersion: '2.3.8-SNAPSHOT', |
| 42 | + runningJobs: '0', |
| 43 | + totalSlot: '111', |
| 44 | + unassignedSlot: '0', |
| 45 | + workers: '1' |
| 46 | + } as Overview |
| 47 | + |
| 48 | + vi.spyOn(overviewService, 'getOverview').mockResolvedValue(mockData) |
| 49 | + |
| 50 | + const wrapper = mount(baseInfo, { |
| 51 | + global: { |
| 52 | + // plugins: [createTestingPinia({ createSpy: vi.fn() }), i18n] |
| 53 | + plugins: [i18n] |
| 54 | + } |
| 55 | + }) |
| 56 | + expect(overviewService.getOverview).toHaveBeenCalledTimes(1) |
| 57 | + expect(overviewService.getOverview).toHaveBeenCalledWith() |
| 58 | + await flushPromises() |
| 59 | + expect(wrapper.text()).toContain('Total Slot: 111') |
| 60 | + expect(wrapper.text()).toContain('Cancelled: 222') |
| 61 | + }) |
| 62 | +}) |
0 commit comments