-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
ee7aec6
commit f0e5b79
Showing
14 changed files
with
432 additions
and
12 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
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
107 changes: 107 additions & 0 deletions
107
src/components/administration/VidisMediaSyncSection.unit.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,107 @@ | ||
import NotifierModule from "@/store/notifier"; | ||
import { NOTIFIER_MODULE_KEY } from "@/utils/inject"; | ||
import { createModuleMocks } from "@@/tests/test-utils/mock-store-module"; | ||
import { | ||
createTestingI18n, | ||
createTestingVuetify, | ||
} from "@@/tests/test-utils/setup"; | ||
import { useSchoolLicenseApi } from "@data-license"; | ||
import { createMock, DeepMocked } from "@golevelup/ts-jest"; | ||
import { mount } from "@vue/test-utils"; | ||
import VidisMediaSyncSection from "./VidisMediaSyncSection.vue"; | ||
|
||
jest.mock("@data-license"); | ||
|
||
describe("VidisMediaSyncSection", () => { | ||
let useSchoolLicenseApiMock: DeepMocked< | ||
ReturnType<typeof useSchoolLicenseApi> | ||
>; | ||
|
||
const notifierModule: jest.Mocked<NotifierModule> = | ||
createModuleMocks(NotifierModule); | ||
|
||
const getWrapper = () => { | ||
const wrapper = mount(VidisMediaSyncSection, { | ||
global: { | ||
plugins: [createTestingVuetify(), createTestingI18n()], | ||
provide: { | ||
[NOTIFIER_MODULE_KEY.valueOf()]: notifierModule, | ||
}, | ||
}, | ||
}); | ||
|
||
return { | ||
wrapper, | ||
}; | ||
}; | ||
|
||
beforeEach(() => { | ||
useSchoolLicenseApiMock = | ||
createMock<ReturnType<typeof useSchoolLicenseApi>>(); | ||
|
||
jest.mocked(useSchoolLicenseApi).mockReturnValue(useSchoolLicenseApiMock); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe("Sync button", () => { | ||
describe("when the request is successful", () => { | ||
const setup = () => { | ||
const { wrapper } = getWrapper(); | ||
|
||
return { | ||
wrapper, | ||
}; | ||
}; | ||
|
||
it("should call the api", async () => { | ||
const { wrapper } = setup(); | ||
|
||
const button = wrapper.find('[data-testid="sync-vidis-media-button"]'); | ||
await button.trigger("click"); | ||
|
||
expect(useSchoolLicenseApiMock.updateSchoolLicenses).toHaveBeenCalled(); | ||
}); | ||
|
||
it("should show a success notification", async () => { | ||
const { wrapper } = setup(); | ||
|
||
const button = wrapper.find('[data-testid="sync-vidis-media-button"]'); | ||
await button.trigger("click"); | ||
|
||
expect(notifierModule.show).toHaveBeenCalledWith({ | ||
status: "success", | ||
text: "components.administration.externalToolsSection.vidis.notification.success", | ||
}); | ||
}); | ||
}); | ||
|
||
describe("when the request fails", () => { | ||
const setup = () => { | ||
const { wrapper } = getWrapper(); | ||
|
||
useSchoolLicenseApiMock.updateSchoolLicenses.mockRejectedValueOnce( | ||
new Error() | ||
); | ||
|
||
return { | ||
wrapper, | ||
}; | ||
}; | ||
|
||
it("should show a failure notification", async () => { | ||
const { wrapper } = setup(); | ||
|
||
const button = wrapper.find('[data-testid="sync-vidis-media-button"]'); | ||
await button.trigger("click"); | ||
|
||
expect(notifierModule.show).toHaveBeenCalledWith({ | ||
status: "error", | ||
text: "common.notification.error", | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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,60 @@ | ||
<template> | ||
<div class="mb-4"> | ||
<h5> | ||
{{ $t("components.administration.externalToolsSection.vidis.title") }} | ||
</h5> | ||
<p> | ||
{{ | ||
$t("components.administration.externalToolsSection.vidis.description") | ||
}} | ||
</p> | ||
<div class="d-flex mt-8" data-testid="external-tool-section-table-actions"> | ||
<VSpacer /> | ||
<VBtn | ||
color="primary" | ||
variant="flat" | ||
data-testid="sync-vidis-media-button" | ||
:loading="isLoading" | ||
@click="updateVidisLicenses" | ||
> | ||
{{ $t("components.administration.externalToolsSection.action.sync") }} | ||
</VBtn> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import NotifierModule from "@/store/notifier"; | ||
import { injectStrict, NOTIFIER_MODULE_KEY } from "@/utils/inject"; | ||
import { useSchoolLicenseApi } from "@data-license"; | ||
import { ref } from "vue"; | ||
import { useI18n } from "vue-i18n"; | ||
const notifierModule: NotifierModule = injectStrict(NOTIFIER_MODULE_KEY); | ||
const { t } = useI18n(); | ||
const { updateSchoolLicenses } = useSchoolLicenseApi(); | ||
const isLoading = ref(false); | ||
const updateVidisLicenses = async () => { | ||
isLoading.value = true; | ||
try { | ||
await updateSchoolLicenses(); | ||
notifierModule.show({ | ||
status: "success", | ||
text: t( | ||
"components.administration.externalToolsSection.vidis.notification.success" | ||
), | ||
}); | ||
} catch (e) { | ||
notifierModule.show({ | ||
status: "error", | ||
text: t("common.notification.error"), | ||
}); | ||
} | ||
isLoading.value = false; | ||
}; | ||
</script> |
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
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
Oops, something went wrong.