Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:(SC-3320) Added tests for layout components and bucket components #134

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/src/components/bucket/BucketList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ onMounted(async () => {
v-if="usePermissionStore().isUserElevatedRights()"
label="Primary"
class="p-button-outlined mt-4"
data-test="connect-bucket"
@click="showBucketConfig()"
>
<font-awesome-icon icon="fa-solid fa-plus" />
Expand Down
79 changes: 79 additions & 0 deletions frontend/tests/unit/components/bucket/BucketConfigForm.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { createTestingPinia } from '@pinia/testing';
import { mount, shallowMount, RouterLinkStub } from '@vue/test-utils';

import BucketConfigForm from '@/components/bucket/BucketConfigForm.vue';
import * as primevue from '@/lib/primevue';
import { StorageKey } from '@/utils/constants';
import PrimeVue from 'primevue/config';
import ToastService from 'primevue/toastservice';

const mockToast = vi.fn();
const useToastSpy = vi.spyOn(primevue, 'useToast');

beforeEach(() => {
sessionStorage.setItem(StorageKey.CONFIG, JSON.stringify(
{
oidc: {
authority: 'abc',
clientId: '123'
}
}
));

vi.clearAllMocks();
useToastSpy.mockImplementation(() => ({ error: mockToast, info: mockToast, success: mockToast, warn: mockToast }));
});

afterEach(() => {
sessionStorage.clear();
});

describe('BucketConfigForm.vue', () => {
it('renders', () => {
const wrapper = shallowMount(BucketConfigForm, {
global: {
plugins: [PrimeVue, createTestingPinia(), ToastService],
stubs: {
RouterLink: RouterLinkStub
},
},
props: {}
});
expect(wrapper).toBeTruthy();
});

it('emits cancel config', async () => {
const wrapper = mount(BucketConfigForm, {
global: {
plugins: [PrimeVue, createTestingPinia(), ToastService],
stubs: {
RouterLink: RouterLinkStub
},
},
props: {}
});

const cancelButton = wrapper.get('[aria-label="Cancel"]');
await cancelButton.trigger('click');

expect(wrapper.emitted()).toHaveProperty('cancel-bucket-config');
});

it('emits triggers onSubmit error', async () => {
const wrapper = mount(BucketConfigForm, {
global: {
plugins: [PrimeVue, createTestingPinia(), ToastService],
stubs: {
RouterLink: RouterLinkStub
},
},
props: {}
});

const submitBtn = wrapper.get('[aria-label="Apply"]');
await submitBtn.trigger('click');

expect(useToastSpy).toHaveBeenCalled();
expect(wrapper).toBeTruthy();
});
});
80 changes: 80 additions & 0 deletions frontend/tests/unit/components/bucket/BucketList.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { createTestingPinia } from '@pinia/testing';
import { mount, shallowMount } from '@vue/test-utils';

import BucketList from '@/components/bucket/BucketList.vue';
import * as primevue from '@/lib/primevue';
import { usePermissionStore } from '@/store';
import { StorageKey } from '@/utils/constants';
import PrimeVue from 'primevue/config';
import ToastService from 'primevue/toastservice';

const mockToast = vi.fn();
const useToastSpy = vi.spyOn(primevue, 'useToast');

beforeEach(() => {
sessionStorage.setItem(StorageKey.CONFIG, JSON.stringify(
{
oidc: {
authority: 'abc',
clientId: '123'
}
}
));

vi.clearAllMocks();
useToastSpy.mockImplementation(() => ({ error: mockToast, info: mockToast, success: mockToast, warn: mockToast }));
});

afterEach(() => {
sessionStorage.clear();
});

describe('BucketList.vue', async () => {
it('renders', () => {
const testingPinia = createTestingPinia({
initialState: {
auth: {
user: {}
}
}
});

const wrapper = shallowMount(BucketList, {
global: {
plugins: [
testingPinia,
PrimeVue,
ToastService,
],
stubs: ['font-awesome-icon']
},
});

expect(wrapper).toBeTruthy();
});

it('shows connect bucket button', async () => {
// Mock isUserElevatedRights to return true
const pinia = createTestingPinia();
const permStore = usePermissionStore(pinia);
vi.mocked(permStore.isUserElevatedRights).mockReturnValue(true);

const wrapper = mount(BucketList, {
global: {
plugins: [
PrimeVue,
ToastService,
pinia,
],
stubs: [
'font-awesome-icon',
'BucketTable'
]
},
});

const button = wrapper.find('[data-test="connect-bucket"]');

expect(button.isVisible()).toBeTruthy();
});
});
59 changes: 59 additions & 0 deletions frontend/tests/unit/components/bucket/BucketPermission.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { createTestingPinia } from '@pinia/testing';
import { mount } from '@vue/test-utils';

import BucketPermission from '@/components/bucket/BucketPermission.vue';
import * as primevue from '@/lib/primevue';
import { StorageKey } from '@/utils/constants';
import PrimeVue from 'primevue/config';
import ConfirmationService from 'primevue/confirmationservice';
import ToastService from 'primevue/toastservice';

const mockToast = vi.fn();
const useToastSpy = vi.spyOn(primevue, 'useToast');

beforeEach(() => {
sessionStorage.setItem(StorageKey.CONFIG, JSON.stringify(
{
oidc: {
authority: 'abc',
clientId: '123'
}
}
));

vi.clearAllMocks();
useToastSpy.mockImplementation(() => ({ error: mockToast, info: mockToast, success: mockToast, warn: mockToast }));
});

afterEach(() => {
sessionStorage.clear();
});

describe('BucketPermission.vue', async () => {
it('renders', () => {
const testingPinia = createTestingPinia({
initialState: {
auth: {
user: {}
}
}
});

const wrapper = mount(BucketPermission, {
props: {
bucketId: 'testBucketId'
},
global: {
plugins: [
ConfirmationService,
PrimeVue,
testingPinia,
ToastService,
],
stubs: ['font-awesome-icon', 'DataTable']
},
});

expect(wrapper).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { createTestingPinia } from '@pinia/testing';
import { shallowMount } from '@vue/test-utils';

import BucketPermissionAddUser from '@/components/bucket/BucketPermissionAddUser.vue';
import * as primevue from '@/lib/primevue';
import { StorageKey } from '@/utils/constants';
import PrimeVue from 'primevue/config';
import ToastService from 'primevue/toastservice';

const mockToast = vi.fn();
const useToastSpy = vi.spyOn(primevue, 'useToast');

beforeEach(() => {
sessionStorage.setItem(StorageKey.CONFIG, JSON.stringify(
{
oidc: {
authority: 'abc',
clientId: '123'
}
}
));

vi.clearAllMocks();
useToastSpy.mockImplementation(() => ({ error: mockToast, info: mockToast, success: mockToast, warn: mockToast }));
});

afterEach(() => {
sessionStorage.clear();
});

describe('BucketPermissionAddUser.vue', async () => {
it('renders', () => {
const testingPinia = createTestingPinia({
initialState: {
auth: {
user: {}
}
}
});

const wrapper = shallowMount(BucketPermissionAddUser, {
global: {
plugins: [
testingPinia,
PrimeVue,
ToastService,
],
stubs: ['font-awesome-icon']
},
});

expect(wrapper).toBeTruthy();
});
});
Loading