Skip to content

Commit

Permalink
Add appStore to all tests that use formStore (there is now a dependen…
Browse files Browse the repository at this point in the history
…cy to check for features).

Signed-off-by: Jason Sherman <[email protected]>
  • Loading branch information
usingtechnology committed Aug 15, 2024
1 parent c66b5cd commit dda2634
Show file tree
Hide file tree
Showing 39 changed files with 118 additions and 6 deletions.
3 changes: 3 additions & 0 deletions app/frontend/tests/unit/components/base/BaseDialog.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import { createTestingPinia } from '@pinia/testing';

import BaseDialog from '~/components/base/BaseDialog.vue';
import { useFormStore } from '~/store/form';
import { useAppStore } from '~/store/app';

describe('BaseDialog.vue', () => {
const pinia = createTestingPinia();
setActivePinia(pinia);
const formStore = useFormStore();
const appStore = useAppStore(pinia);

beforeEach(() => {
formStore.$reset();
appStore.$reset();
});

it('renders with ok button', async () => {
Expand Down
3 changes: 3 additions & 0 deletions app/frontend/tests/unit/components/base/BaseFilter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import { describe, it } from 'vitest';
import { createTestingPinia } from '@pinia/testing';
import BaseFilter from '~/components/base/BaseFilter.vue';
import { useFormStore } from '~/store/form';
import { useAppStore } from '~/store/app';

describe('BaseFilter.vue', () => {
const pinia = createTestingPinia();
const formStore = useFormStore();
const appStore = useAppStore(pinia);

beforeEach(() => {
formStore.$reset();
appStore.$reset();
});

it('renders', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import { beforeEach, describe, it } from 'vitest';

import BaseInternationalization from '~/components/base/BaseInternationalization.vue';
import { useFormStore } from '~/store/form';
import { useAppStore } from '~/store/app';

describe('BaseInternationalization.vue', () => {
const pinia = createPinia();
setActivePinia(pinia);
const formStore = useFormStore(pinia);
const appStore = useAppStore(pinia);

beforeEach(() => {
formStore.$reset();
appStore.$reset();

formStore.isRTL = false;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import getRouter from '~/router';
import FormViewer from '~/components/designer/FormViewer.vue';
import { useAuthStore } from '~/store/auth';
import { useFormStore } from '~/store/form';
import { useAppStore } from '~/store/app';

describe('FormViewer.vue', () => {
const formId = '123-456';
Expand All @@ -22,10 +23,12 @@ describe('FormViewer.vue', () => {
setActivePinia(pinia);
const authStore = useAuthStore(pinia);
const formStore = useFormStore(pinia);
const appStore = useAppStore(pinia);

beforeEach(() => {
authStore.$reset();
formStore.$reset();
appStore.$reset();

authStore.keycloak = {
tokenParsed: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import { createTestingPinia } from '@pinia/testing';
import { setActivePinia } from 'pinia';
import { mount } from '@vue/test-utils';
import { nextTick } from 'vue';
import { useAppStore } from '~/store/app';

describe('FormAPIProfile.vue', () => {
const pinia = createTestingPinia();
setActivePinia(pinia);
const formStore = useFormStore(pinia);
const appStore = useAppStore(pinia);

beforeEach(() => {
formStore.$reset();
appStore.$reset();
});

it('renders properly', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import { setActivePinia } from 'pinia';
import { mount } from '@vue/test-utils';
import { FormProfileValues } from '~/utils/constants';
import { nextTick } from 'vue';
import { useAppStore } from '~/store/app';

describe('FormDeploymentProfile.vue', () => {
const pinia = createTestingPinia();
setActivePinia(pinia);
const formStore = useFormStore(pinia);
const appStore = useAppStore(pinia);

beforeEach(() => {
formStore.$reset();
appStore.$reset();
});

it('renders properly', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ import FormLabelProfile from '~/components/designer/profile/FormLabelProfile.vue
import { userService } from '~/services';
import { useFormStore } from '~/store/form';
import { useNotificationStore } from '~/store/notification';
import { useAppStore } from '~/store/app';

describe('FormLabelProfile.vue', () => {
const pinia = createTestingPinia();
setActivePinia(pinia);
const formStore = useFormStore(pinia);
const notificationStore = useNotificationStore(pinia);
const appStore = useAppStore(pinia);

const getUserLabelsSpy = vi.spyOn(userService, 'getUserLabels');
const addNotificationSpy = vi.spyOn(notificationStore, 'addNotification');

beforeEach(() => {
formStore.$reset();
appStore.$reset();
notificationStore.$reset();
getUserLabelsSpy.mockReset();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import { FormProfileValues } from '~/utils/constants';
import { createTestingPinia } from '@pinia/testing';
import { setActivePinia } from 'pinia';
import { mount } from '@vue/test-utils';
import { useAppStore } from '~/store/app';

describe('FormUseCaseProfile.vue', () => {
const pinia = createTestingPinia();
setActivePinia(pinia);
const formStore = useFormStore(pinia);
const appStore = useAppStore(pinia);

beforeEach(() => {
formStore.$reset();
appStore.$reset();
});

it('renders properly', () => {
Expand All @@ -36,6 +39,7 @@ describe('FormUseCaseProfile.vue', () => {
const select = wrapper.findComponent('[data-test="case-select"]');

const items = select.componentVM.items;
// eslint-disable-next-line no-console
console.log(items);
expect(items).toEqual(FormProfileValues.USE_CASE);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import { nextTick, ref } from 'vue';
import { useFormStore } from '~/store/form';
import FormAccessSettings from '~/components/designer/settings/FormAccessSettings.vue';
import { IdentityMode } from '~/utils/constants';
import { useAppStore } from '~/store/app';

describe('FormAccessSettings.vue', () => {
const pinia = createTestingPinia();
setActivePinia(pinia);

const formStore = useFormStore(pinia);
const appStore = useAppStore(pinia);

beforeEach(() => {
formStore.$reset();
appStore.$reset();
});

it('renders and displays 3 radio buttons', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useFormStore } from '~/store/form';
import { useIdpStore } from '~/store/identityProviders';
import FormFunctionalitySettings from '~/components/designer/settings/FormFunctionalitySettings.vue';
import { FormRoleCodes, AppPermissions } from '~/utils/constants';
import { useAppStore } from '~/store/app';

const IDIR = {
active: true,
Expand Down Expand Up @@ -109,11 +110,13 @@ describe('FormFunctionalitySettings.vue', () => {
const authStore = useAuthStore(pinia);
const formStore = useFormStore(pinia);
const idpStore = useIdpStore(pinia);
const appStore = useAppStore(pinia);

beforeEach(() => {
authStore.$reset();
formStore.$reset();
idpStore.$reset();
appStore.$reset();

authStore.identityProvider = ref({
code: 'idir',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ import { useFormStore } from '~/store/form';
import FormScheduleSettings from '~/components/designer/settings/FormScheduleSettings.vue';
import { ScheduleType } from '~/utils/constants';
import { getSubmissionPeriodDates } from '~/utils/transformUtils';
import { useAppStore } from '~/store/app';

describe('FormScheduleSettings.vue', () => {
const pinia = createTestingPinia();
setActivePinia(pinia);

const formStore = useFormStore(pinia);
const appStore = useAppStore(pinia);

beforeEach(() => {
formStore.$reset();
appStore.$reset();
formStore.form = ref({
schedule: {
enabled: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import { beforeEach, describe, expect, it } from 'vitest';
import { useFormStore } from '~/store/form';
import FormSubmissionSettings from '~/components/designer/settings/FormSubmissionSettings.vue';
import { nextTick } from 'vue';
import { useAppStore } from '~/store/app';

describe('FormSubmissionSettings.vue', () => {
const pinia = createTestingPinia();
setActivePinia(pinia);

const formStore = useFormStore(pinia);
const appStore = useAppStore(pinia);

beforeEach(() => {
formStore.$reset();
appStore.$reset();
});

it('renders and tests default values', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import getRouter from '~/router';
import ExportSubmissions from '~/components/forms/ExportSubmissions.vue';
import { useAuthStore } from '~/store/auth';
import { useFormStore } from '~/store/form';
import { useAppStore } from '~/store/app';

describe('ExportSubmissions.vue', () => {
const formId = '123-456';
Expand All @@ -22,10 +23,12 @@ describe('ExportSubmissions.vue', () => {
setActivePinia(pinia);
const authStore = useAuthStore(pinia);
const formStore = useFormStore(pinia);
const appStore = useAppStore(pinia);

beforeEach(() => {
authStore.$reset();
formStore.$reset();
appStore.$reset();
});

it('renders', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import getRouter from '~/router';
import SubmissionsTable from '~/components/forms/SubmissionsTable.vue';
import { useAuthStore } from '~/store/auth';
import { useFormStore } from '~/store/form';
import { useAppStore } from '~/store/app';

describe('SubmissionsTable.vue', () => {
const formId = '123-456';
Expand All @@ -22,10 +23,12 @@ describe('SubmissionsTable.vue', () => {
setActivePinia(pinia);
const authStore = useAuthStore(pinia);
const formStore = useFormStore(pinia);
const appStore = useAppStore(pinia);

beforeEach(() => {
authStore.$reset();
formStore.$reset();
appStore.$reset();
});

it('renders', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { describe, beforeEach, vi } from 'vitest';
import ApiKey from '~/components/forms/manage/ApiKey.vue';
import { useFormStore } from '~/store/form';
import { FormPermissions } from '~/utils/constants';
import { useAppStore } from '~/store/app';

const STUBS = {
BaseCopyToClipboard: {
Expand All @@ -32,9 +33,11 @@ describe('ApiKey.vue', () => {
setActivePinia(pinia);

const formStore = useFormStore(pinia);
const appStore = useAppStore(pinia);

beforeEach(() => {
formStore.$reset();
appStore.$reset();
});

it('renders', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useFormStore } from '~/store/form';
import { useNotificationStore } from '~/store/notification';
import getRouter from '~/router';
import { ref } from 'vue';
import { useAppStore } from '~/store/app';

const STUBS = {
VDataTableServer: {
Expand All @@ -33,7 +34,7 @@ const STUBS = {
};

describe('DocumentTemplate.vue', () => {
let router, pinia, formStore, notificationStore;
let router, pinia, formStore, notificationStore, appStore;
let createObjectURLSpy = vi.spyOn(window.URL, 'createObjectURL');

beforeEach(() => {
Expand All @@ -47,9 +48,11 @@ describe('DocumentTemplate.vue', () => {

formStore = useFormStore(pinia);
notificationStore = useNotificationStore(pinia);
appStore = useAppStore(pinia);

formStore.$reset();
notificationStore.$reset();
appStore.$reset();

// Explicitly mock/spy on global functions
createObjectURLSpy.mockImplementation(() => '#');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ref } from 'vue';
import EmailTemplate from '~/components/forms/manage/EmailTemplate.vue';
import { useFormStore } from '~/store/form';
import { useNotificationStore } from '~/store/notification';
import { useAppStore } from '~/store/app';

const STUBS = {};

Expand All @@ -16,10 +17,11 @@ describe('EmailTemplate.vue', () => {

const formStore = useFormStore(pinia);
const notificationStore = useNotificationStore(pinia);
const appStore = useAppStore(pinia);

beforeEach(() => {
formStore.$reset();

appStore.$reset();
formStore.emailTemplates = ref([
{
body: 'Thank you for your {{ form.name }} submission. You can view your submission details by visiting the following links:',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import getRouter from '~/router';
import { useFormStore } from '~/store/form';
import { useNotificationStore } from '~/store/notification';
import { FormPermissions } from '~/utils/constants';
import { useAppStore } from '~/store/app';

const STUBS = {
VDataTable: {
Expand Down Expand Up @@ -42,12 +43,14 @@ describe('ManageForm.vue', () => {
setActivePinia(pinia);
const formStore = useFormStore(pinia);
const notificationStore = useNotificationStore(pinia);
const appStore = useAppStore(pinia);
const readFormSpy = vi.spyOn(formStore, 'readFormSubscriptionData');
const addNotificationSpy = vi.spyOn(notificationStore, 'addNotification');

beforeEach(() => {
formStore.$reset();
notificationStore.$reset();
appStore.$reset();
readFormSpy.mockReset();
addNotificationSpy.mockReset();
readFormSpy.mockImplementationOnce(async () => {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ManageFormActions from '~/components/forms/manage/ManageFormActions.vue';
import { useFormStore } from '~/store/form';
import { FormPermissions } from '~/utils/constants';
import { ref } from 'vue';
import { useAppStore } from '~/store/app';

vi.mock('vue-router', () => ({
useRouter: vi.fn(() => ({
Expand All @@ -30,9 +31,11 @@ describe('ManageForm.vue', () => {

setActivePinia(pinia);
const formStore = useFormStore(pinia);
const appStore = useAppStore(pinia);

beforeEach(() => {
formStore.$reset();
appStore.$reset();
});

it('renders', async () => {
Expand Down
Loading

0 comments on commit dda2634

Please sign in to comment.