Skip to content

Commit

Permalink
replace inject with injectStrict for schoolsModule
Browse files Browse the repository at this point in the history
  • Loading branch information
davwas committed Sep 12, 2023
1 parent a800c93 commit 5678c54
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 69 deletions.
8 changes: 6 additions & 2 deletions src/components/administration/AdminMigrationSection.unit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import AdminMigrationSection from "@/components/administration/AdminMigrationSection.vue";
import EnvConfigModule from "@/store/env-config";
import SchoolsModule from "@/store/schools";
import { ENV_CONFIG_MODULE_KEY, I18N_KEY } from "@/utils/inject";
import {
ENV_CONFIG_MODULE_KEY,
I18N_KEY,
SCHOOLS_MODULE_KEY,
} from "@/utils/inject";
import { createModuleMocks } from "@/utils/mock-store-module";
import createComponentMocks from "@@/tests/test-utils/componentMocks";
import { Wrapper, mount, shallowMount } from "@vue/test-utils";
Expand Down Expand Up @@ -39,7 +43,7 @@ describe("AdminMigrationSection", () => {
}),
provide: {
[I18N_KEY.valueOf()]: i18nMock,
schoolsModule,
[SCHOOLS_MODULE_KEY.valueOf()]: schoolsModule,
[ENV_CONFIG_MODULE_KEY.valueOf()]: envConfigModule,
},
});
Expand Down
22 changes: 8 additions & 14 deletions src/components/administration/AdminMigrationSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,23 +169,25 @@

<script lang="ts">
import { MigrationBody } from "@/serverApi/v3";
import SchoolsModule from "@/store/schools";
import { OauthMigration, School } from "@/store/types/schools";
import { ENV_CONFIG_MODULE_KEY, I18N_KEY, injectStrict } from "@/utils/inject";
import {
ENV_CONFIG_MODULE_KEY,
injectStrict,
SCHOOLS_MODULE_KEY,
} from "@/utils/inject";
import dayjs from "dayjs";
import {
computed,
ComputedRef,
defineComponent,
inject,
onMounted,
ref,
Ref,
watch,
} from "vue";
import VueI18n from "vue-i18n";
import MigrationWarningCard from "./MigrationWarningCard.vue";
import { RenderHTML } from "@feature-render-html";
import { useI18n } from "@/composables/i18n.composable";
export default defineComponent({
name: "AdminMigrationSection",
Expand All @@ -194,22 +196,14 @@ export default defineComponent({
RenderHTML,
},
setup() {
const i18n = injectStrict(I18N_KEY);
const { t } = useI18n();
const envConfigModule = injectStrict(ENV_CONFIG_MODULE_KEY);
const schoolsModule: SchoolsModule | undefined =
inject<SchoolsModule>("schoolsModule");
if (!schoolsModule || !i18n) {
throw new Error("Injection of dependencies failed");
}
const schoolsModule = injectStrict(SCHOOLS_MODULE_KEY);
onMounted(async () => {
await schoolsModule.fetchSchoolOAuthMigration();
});
// TODO: https://ticketsystem.dbildungscloud.de/browse/BC-443
const t = (key: string, values?: VueI18n.Values): string =>
i18n.tc(key, 0, values);
const oauthMigration: ComputedRef<OauthMigration> = computed(
() => schoolsModule.getOauthMigration
);
Expand Down
3 changes: 2 additions & 1 deletion src/components/organisms/administration/SchoolPolicy.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
AUTH_MODULE_KEY,
I18N_KEY,
PRIVACY_POLICY_MODULE_KEY,
SCHOOLS_MODULE_KEY,
} from "@/utils/inject";
import Vue from "vue";
import { i18nMock } from "@@/tests/test-utils";
Expand Down Expand Up @@ -75,7 +76,7 @@ describe("SchoolPolicy", () => {
[I18N_KEY.valueOf()]: i18nMock,
[PRIVACY_POLICY_MODULE_KEY.valueOf()]: privacyPolicyModule,
[AUTH_MODULE_KEY.valueOf()]: authModule,
schoolsModule,
[SCHOOLS_MODULE_KEY.valueOf()]: schoolsModule,
},
});

Expand Down
19 changes: 3 additions & 16 deletions src/components/organisms/administration/SchoolPolicy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,7 @@
import SchoolPolicyFormDialog from "@/components/organisms/administration/SchoolPolicyFormDialog.vue";
import dayjs from "dayjs";
import { mdiPencilOutline, mdiTrayArrowDown } from "@mdi/js";
import {
computed,
ComputedRef,
defineComponent,
inject,
ref,
Ref,
watch,
} from "vue";
import SchoolsModule from "@/store/schools";
import { computed, ComputedRef, defineComponent, ref, Ref, watch } from "vue";
import { School } from "@/store/types/schools";
import { ConsentVersion } from "@/store/types/consent-version";
import { BusinessError } from "@/store/types/commons";
Expand All @@ -115,6 +106,7 @@ import {
AUTH_MODULE_KEY,
PRIVACY_POLICY_MODULE_KEY,
injectStrict,
SCHOOLS_MODULE_KEY,
} from "@/utils/inject";
export default defineComponent({
Expand All @@ -126,12 +118,7 @@ export default defineComponent({
const { t } = useI18n();
const authModule = injectStrict(AUTH_MODULE_KEY);
const privacyPolicyModule = injectStrict(PRIVACY_POLICY_MODULE_KEY);
const schoolsModule: SchoolsModule | undefined =
inject<SchoolsModule>("schoolsModule");
if (!schoolsModule) {
throw new Error("Injection of dependencies failed");
}
const schoolsModule = injectStrict(SCHOOLS_MODULE_KEY);
const isSchoolPolicyFormDialogOpen: Ref<boolean> = ref(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
I18N_KEY,
NOTIFIER_MODULE_KEY,
PRIVACY_POLICY_MODULE_KEY,
SCHOOLS_MODULE_KEY,
} from "@/utils/inject";
import { i18nMock } from "@@/tests/test-utils";

Expand Down Expand Up @@ -57,7 +58,7 @@ describe("SchoolPolicyFormDialog", () => {
[I18N_KEY.valueOf()]: i18nMock,
[NOTIFIER_MODULE_KEY.valueOf()]: notifierModule,
[PRIVACY_POLICY_MODULE_KEY.valueOf()]: privacyPolicyModule,
schoolsModule,
[SCHOOLS_MODULE_KEY.valueOf()]: schoolsModule,
},
propsData: mockProps,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@

<script lang="ts">
import vCustomDialog from "@/components/organisms/vCustomDialog.vue";
import { computed, ComputedRef, defineComponent, inject, ref, Ref } from "vue";
import SchoolsModule from "@/store/schools";
import { computed, ComputedRef, defineComponent, ref, Ref } from "vue";
import {
injectStrict,
NOTIFIER_MODULE_KEY,
PRIVACY_POLICY_MODULE_KEY,
SCHOOLS_MODULE_KEY,
} from "@/utils/inject";
import { mdiAlert, mdiFileReplaceOutline } from "@mdi/js";
import { School } from "@/store/types/schools";
Expand All @@ -107,12 +107,7 @@ export default defineComponent({
const { t } = useI18n();
const privacyPolicyModule = injectStrict(PRIVACY_POLICY_MODULE_KEY);
const notifierModule = injectStrict(NOTIFIER_MODULE_KEY);
const schoolsModule: SchoolsModule | undefined =
inject<SchoolsModule>("schoolsModule");
if (!schoolsModule) {
throw new Error("Injection of dependencies failed");
}
const schoolsModule = injectStrict(SCHOOLS_MODULE_KEY);
const policyForm: Ref = ref(null);
const isValid: Ref<boolean> = ref(false);
Expand Down
3 changes: 2 additions & 1 deletion src/components/organisms/administration/SchoolTerms.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ConsentVersion } from "@/store/types/consent-version";
import {
AUTH_MODULE_KEY,
I18N_KEY,
SCHOOLS_MODULE_KEY,
TERMS_OF_USE_MODULE_KEY,
} from "@/utils/inject";
import Vue from "vue";
Expand Down Expand Up @@ -75,7 +76,7 @@ describe("SchoolTerms", () => {
[I18N_KEY.valueOf()]: i18nMock,
[TERMS_OF_USE_MODULE_KEY.valueOf()]: termsOfUseModule,
[AUTH_MODULE_KEY.valueOf()]: authModule,
schoolsModule,
[SCHOOLS_MODULE_KEY.valueOf()]: schoolsModule,
},
});

Expand Down
19 changes: 3 additions & 16 deletions src/components/organisms/administration/SchoolTerms.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,7 @@
import SchoolTermsFormDialog from "@/components/organisms/administration/SchoolTermsFormDialog.vue";
import dayjs from "dayjs";
import { mdiPencilOutline, mdiTrayArrowDown } from "@mdi/js";
import {
computed,
ComputedRef,
defineComponent,
inject,
ref,
Ref,
watch,
} from "vue";
import SchoolsModule from "@/store/schools";
import { computed, ComputedRef, defineComponent, ref, Ref, watch } from "vue";
import { School } from "@/store/types/schools";
import { ConsentVersion } from "@/store/types/consent-version";
import { BusinessError } from "@/store/types/commons";
Expand All @@ -111,6 +102,7 @@ import {
injectStrict,
AUTH_MODULE_KEY,
TERMS_OF_USE_MODULE_KEY,
SCHOOLS_MODULE_KEY,
} from "@/utils/inject";
export default defineComponent({
Expand All @@ -122,12 +114,7 @@ export default defineComponent({
const { t } = useI18n();
const authModule = injectStrict(AUTH_MODULE_KEY);
const termsOfUseModule = injectStrict(TERMS_OF_USE_MODULE_KEY);
const schoolsModule: SchoolsModule | undefined =
inject<SchoolsModule>("schoolsModule");
if (!schoolsModule) {
throw new Error("Injection of dependencies failed");
}
const schoolsModule = injectStrict(SCHOOLS_MODULE_KEY);
const isSchoolTermsFormDialogOpen: Ref<boolean> = ref(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Vue from "vue";
import {
I18N_KEY,
NOTIFIER_MODULE_KEY,
SCHOOLS_MODULE_KEY,
TERMS_OF_USE_MODULE_KEY,
} from "@/utils/inject";
import { i18nMock } from "@@/tests/test-utils";
Expand Down Expand Up @@ -57,7 +58,7 @@ describe("SchoolPolicyFormDialog", () => {
[I18N_KEY.valueOf()]: i18nMock,
[NOTIFIER_MODULE_KEY.valueOf()]: notifierModule,
[TERMS_OF_USE_MODULE_KEY.valueOf()]: termsOfUseModule,
schoolsModule,
[SCHOOLS_MODULE_KEY.valueOf()]: schoolsModule,
},
propsData: mockProps,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@

<script lang="ts">
import vCustomDialog from "@/components/organisms/vCustomDialog.vue";
import { computed, ComputedRef, defineComponent, inject, ref, Ref } from "vue";
import SchoolsModule from "@/store/schools";
import { computed, ComputedRef, defineComponent, ref, Ref } from "vue";
import {
injectStrict,
NOTIFIER_MODULE_KEY,
SCHOOLS_MODULE_KEY,
TERMS_OF_USE_MODULE_KEY,
} from "@/utils/inject";
import { mdiAlert, mdiFileReplaceOutline } from "@mdi/js";
Expand All @@ -105,12 +105,7 @@ export default defineComponent({
const { t } = useI18n();
const termsOfUseModule = injectStrict(TERMS_OF_USE_MODULE_KEY);
const notifierModule = injectStrict(NOTIFIER_MODULE_KEY);
const schoolsModule: SchoolsModule | undefined =
inject<SchoolsModule>("schoolsModule");
if (!schoolsModule) {
throw new Error("Injection of dependencies failed");
}
const schoolsModule = injectStrict(SCHOOLS_MODULE_KEY);
const termsForm: Ref = ref(null);
const isFormValid: Ref<boolean> = ref(false);
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import {
VIDEO_CONFERENCE_MODULE_KEY,
PRIVACY_POLICY_MODULE_KEY,
TERMS_OF_USE_MODULE_KEY,
SCHOOLS_MODULE_KEY,
} from "./utils/inject";

Vue.config.productionTip = false;
Expand Down Expand Up @@ -161,7 +162,7 @@ Vue.use(VueDOMPurifyHTML, {
[ROOM_MODULE_KEY.valueOf()]: roomModule,
roomsModule,
[SCHOOL_EXTERNAL_TOOLS_MODULE_KEY.valueOf()]: schoolExternalToolsModule,
schoolsModule,
[SCHOOLS_MODULE_KEY.valueOf()]: schoolsModule,
shareModule,
[STATUS_ALERTS_MODULE_KEY.valueOf()]: statusAlertsModule,
[SYSTEMS_MODULE_KEY.valueOf()]: systemsModule,
Expand Down
3 changes: 3 additions & 0 deletions src/utils/inject/injection-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import UserLoginMigrationModule from "@/store/user-login-migrations";
import SystemsModule from "@/store/systems";
import PrivacyPolicyModule from "@/store/privacy-policy";
import TermsOfUseModule from "@/store/terms-of-use";
import SchoolsModule from "@/store/schools";

export const ENV_CONFIG_MODULE_KEY: InjectionKey<EnvConfigModule> =
Symbol("envConfigModule");
Expand Down Expand Up @@ -42,3 +43,5 @@ export const PRIVACY_POLICY_MODULE_KEY: InjectionKey<PrivacyPolicyModule> =
Symbol("privacyPolicyModule");
export const TERMS_OF_USE_MODULE_KEY: InjectionKey<TermsOfUseModule> =
Symbol("termsOfUseModule");
export const SCHOOLS_MODULE_KEY: InjectionKey<SchoolsModule> =
Symbol("schoolsModule");

0 comments on commit 5678c54

Please sign in to comment.