-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from bcgov/chore/unit-tests
Frontend unit tests
- Loading branch information
Showing
8 changed files
with
710 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { createTestingPinia } from '@pinia/testing'; | ||
import { mount } from '@vue/test-utils'; | ||
|
||
import DocumentCard from '@/components/file/DocumentCard.vue'; | ||
import { userService } from '@/services'; | ||
import { StorageKey } from '@/utils/enums/application'; | ||
import PrimeVue from 'primevue/config'; | ||
import ConfirmationService from 'primevue/confirmationservice'; | ||
import ToastService from 'primevue/toastservice'; | ||
|
||
import type { AxiosResponse } from 'axios'; | ||
import type { Document } from '@/types'; | ||
|
||
const useUserService = vi.spyOn(userService, 'searchUsers'); | ||
|
||
vi.mock('vue-router', () => ({ | ||
useRouter: () => ({ | ||
push: vi.fn(), | ||
replace: vi.fn() | ||
}) | ||
})); | ||
|
||
const currentDate = new Date().toISOString(); | ||
|
||
const testDocument: Document = { | ||
createdBy: 'testCreatedBy', | ||
createdAt: currentDate, | ||
updatedBy: 'testUpdatedAt', | ||
updatedAt: currentDate, | ||
documentId: 'documentUUID', // Primary Key | ||
activityId: 'activityUUID', | ||
filename: 'test file name', | ||
mimeType: 'test mime type', | ||
filesize: 123, | ||
createdByFullName: 'test user' | ||
}; | ||
|
||
const wrapperSettings = (testDocumentProp = testDocument) => ({ | ||
props: { | ||
document: testDocumentProp | ||
}, | ||
global: { | ||
plugins: [ | ||
() => | ||
createTestingPinia({ | ||
initialState: { | ||
auth: { | ||
user: {} | ||
} | ||
} | ||
}), | ||
PrimeVue, | ||
ConfirmationService, | ||
ToastService | ||
], | ||
stubs: ['font-awesome-icon'] | ||
} | ||
}); | ||
|
||
beforeEach(() => { | ||
sessionStorage.setItem( | ||
StorageKey.CONFIG, | ||
JSON.stringify({ | ||
oidc: { | ||
authority: 'abc', | ||
clientId: '123' | ||
} | ||
}) | ||
); | ||
|
||
vi.clearAllMocks(); | ||
|
||
useUserService.mockResolvedValue({ data: [{ fullName: 'dummyName' }] } as AxiosResponse); | ||
}); | ||
|
||
afterEach(() => { | ||
sessionStorage.clear(); | ||
}); | ||
|
||
describe('DocumentCard', () => { | ||
it('renders component', async () => { | ||
const wrapper = mount(DocumentCard, wrapperSettings()); | ||
expect(wrapper).toBeTruthy(); | ||
}); | ||
}); |
87 changes: 87 additions & 0 deletions
87
frontend/tests/unit/components/file/FileSelectModal.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { createTestingPinia } from '@pinia/testing'; | ||
import { mount } from '@vue/test-utils'; | ||
|
||
import FileSelectModal from '@/components/file/FileSelectModal.vue'; | ||
import { userService } from '@/services'; | ||
import { StorageKey } from '@/utils/enums/application'; | ||
import PrimeVue from 'primevue/config'; | ||
import ConfirmationService from 'primevue/confirmationservice'; | ||
import ToastService from 'primevue/toastservice'; | ||
|
||
import type { AxiosResponse } from 'axios'; | ||
import type { Document } from '@/types'; | ||
|
||
const useUserService = vi.spyOn(userService, 'searchUsers'); | ||
|
||
vi.mock('vue-router', () => ({ | ||
useRouter: () => ({ | ||
push: vi.fn(), | ||
replace: vi.fn() | ||
}) | ||
})); | ||
|
||
const currentDate = new Date().toISOString(); | ||
|
||
const testDocument: Array<Document> = [ | ||
{ | ||
createdBy: 'testCreatedBy', | ||
createdAt: currentDate, | ||
updatedBy: 'testUpdatedAt', | ||
updatedAt: currentDate, | ||
documentId: 'documentUUID', // Primary Key | ||
activityId: 'activityUUID', | ||
filename: 'test file name', | ||
mimeType: 'test mime type', | ||
filesize: 123, | ||
createdByFullName: 'test user' | ||
} | ||
]; | ||
|
||
const wrapperSettings = (testDocumentProp = testDocument) => ({ | ||
props: { | ||
documents: testDocumentProp | ||
}, | ||
global: { | ||
plugins: [ | ||
() => | ||
createTestingPinia({ | ||
initialState: { | ||
auth: { | ||
user: {} | ||
} | ||
} | ||
}), | ||
PrimeVue, | ||
ConfirmationService, | ||
ToastService | ||
], | ||
stubs: ['font-awesome-icon'] | ||
} | ||
}); | ||
|
||
beforeEach(() => { | ||
sessionStorage.setItem( | ||
StorageKey.CONFIG, | ||
JSON.stringify({ | ||
oidc: { | ||
authority: 'abc', | ||
clientId: '123' | ||
} | ||
}) | ||
); | ||
|
||
vi.clearAllMocks(); | ||
|
||
useUserService.mockResolvedValue({ data: [{ fullName: 'dummyName' }] } as AxiosResponse); | ||
}); | ||
|
||
afterEach(() => { | ||
sessionStorage.clear(); | ||
}); | ||
|
||
describe('DocumentCard', () => { | ||
it('renders component', async () => { | ||
const wrapper = mount(FileSelectModal, wrapperSettings()); | ||
expect(wrapper).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { createTestingPinia } from '@pinia/testing'; | ||
import { mount } from '@vue/test-utils'; | ||
|
||
import FileUpload from '@/components/file/FileUpload.vue'; | ||
import { userService } from '@/services'; | ||
import { StorageKey } from '@/utils/enums/application'; | ||
import PrimeVue from 'primevue/config'; | ||
import ConfirmationService from 'primevue/confirmationservice'; | ||
import ToastService from 'primevue/toastservice'; | ||
|
||
import type { AxiosResponse } from 'axios'; | ||
|
||
const useUserService = vi.spyOn(userService, 'searchUsers'); | ||
|
||
vi.mock('vue-router', () => ({ | ||
useRouter: () => ({ | ||
push: vi.fn(), | ||
replace: vi.fn() | ||
}) | ||
})); | ||
|
||
const activityId = 'activityUUID'; | ||
|
||
const wrapperSettings = () => ({ | ||
props: { | ||
activityId: activityId | ||
}, | ||
global: { | ||
plugins: [ | ||
() => | ||
createTestingPinia({ | ||
initialState: { | ||
auth: { | ||
user: {} | ||
} | ||
} | ||
}), | ||
PrimeVue, | ||
ConfirmationService, | ||
ToastService | ||
], | ||
stubs: ['font-awesome-icon'] | ||
} | ||
}); | ||
|
||
beforeEach(() => { | ||
sessionStorage.setItem( | ||
StorageKey.CONFIG, | ||
JSON.stringify({ | ||
oidc: { | ||
authority: 'abc', | ||
clientId: '123' | ||
} | ||
}) | ||
); | ||
|
||
vi.clearAllMocks(); | ||
|
||
useUserService.mockResolvedValue({ data: [{ fullName: 'dummyName' }] } as AxiosResponse); | ||
}); | ||
|
||
afterEach(() => { | ||
sessionStorage.clear(); | ||
}); | ||
|
||
describe('FileUpload', () => { | ||
it('renders component', async () => { | ||
const wrapper = mount(FileUpload, wrapperSettings()); | ||
expect(wrapper).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.