-
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.
- Loading branch information
1 parent
e9cf843
commit a128c52
Showing
3 changed files
with
224 additions
and
19 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
163 changes: 163 additions & 0 deletions
163
src/components/feature-board-external-tool-element/ExternalToolElementAlert.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,163 @@ | ||
import { BusinessError } from "@/store/types/commons"; | ||
import { I18N_KEY } from "@/utils/inject"; | ||
import { i18nMock } from "@@/tests/test-utils"; | ||
import createComponentMocks from "@@/tests/test-utils/componentMocks"; | ||
import { useBoardPermissions } from "@data-board"; | ||
import { createMock, DeepMocked } from "@golevelup/ts-jest"; | ||
import { WarningAlert } from "@ui-alert"; | ||
import { mount, MountOptions, Wrapper } from "@vue/test-utils"; | ||
import Vue from "vue"; | ||
import ExternalToolElementAlert from "./ExternalToolElementAlert.vue"; | ||
|
||
jest.mock("@data-board"); | ||
|
||
describe("ExternalToolElementAlert", () => { | ||
let useBoardPermissionsMock: DeepMocked< | ||
ReturnType<typeof useBoardPermissions> | ||
>; | ||
|
||
beforeEach(() => { | ||
useBoardPermissionsMock = | ||
createMock<ReturnType<typeof useBoardPermissions>>(); | ||
|
||
jest.mocked(useBoardPermissions).mockReturnValue(useBoardPermissionsMock); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const getWrapper = (propsData: { | ||
error?: BusinessError; | ||
isToolOutdated?: boolean; | ||
}) => { | ||
document.body.setAttribute("data-app", "true"); | ||
|
||
const wrapper: Wrapper<Vue> = mount( | ||
ExternalToolElementAlert as MountOptions<Vue>, | ||
{ | ||
...createComponentMocks({ | ||
i18n: true, | ||
}), | ||
propsData, | ||
provide: { | ||
[I18N_KEY.valueOf()]: i18nMock, | ||
}, | ||
} | ||
); | ||
|
||
return { | ||
wrapper, | ||
}; | ||
}; | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe("when an error exists", () => { | ||
describe("when the user is a teacher", () => { | ||
const setup = () => { | ||
const error: BusinessError = { | ||
statusCode: 418, | ||
message: "Loading error", | ||
}; | ||
|
||
useBoardPermissionsMock.isTeacher = true; | ||
|
||
const { wrapper } = getWrapper({ error }); | ||
|
||
return { | ||
wrapper, | ||
}; | ||
}; | ||
|
||
it("should display a teacher friendly error message", () => { | ||
const { wrapper } = setup(); | ||
|
||
const alerts = wrapper.findAllComponents(WarningAlert); | ||
|
||
expect(alerts).toHaveLength(1); | ||
expect(alerts.at(0).text()).toEqual( | ||
"feature-board-external-tool-element.alert.error.teacher" | ||
); | ||
}); | ||
}); | ||
|
||
describe("when the user is a student", () => { | ||
const setup = () => { | ||
const error: BusinessError = { | ||
statusCode: 418, | ||
message: "Loading error", | ||
}; | ||
|
||
useBoardPermissionsMock.isTeacher = false; | ||
|
||
const { wrapper } = getWrapper({ error }); | ||
|
||
return { | ||
wrapper, | ||
}; | ||
}; | ||
|
||
it("should display a student friendly error message", () => { | ||
const { wrapper } = setup(); | ||
|
||
const alerts = wrapper.findAllComponents(WarningAlert); | ||
|
||
expect(alerts).toHaveLength(1); | ||
expect(alerts.at(0).text()).toEqual( | ||
"feature-board-external-tool-element.alert.error.student" | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("when the tool is outdated", () => { | ||
describe("when the user is a teacher", () => { | ||
const setup = () => { | ||
useBoardPermissionsMock.isTeacher = true; | ||
|
||
const { wrapper } = getWrapper({ isToolOutdated: true }); | ||
|
||
return { | ||
wrapper, | ||
}; | ||
}; | ||
|
||
it("should display a teacher friendly message", () => { | ||
const { wrapper } = setup(); | ||
|
||
const alerts = wrapper.findAllComponents(WarningAlert); | ||
|
||
expect(alerts).toHaveLength(1); | ||
expect(alerts.at(0).text()).toEqual( | ||
"feature-board-external-tool-element.alert.outdated.teacher" | ||
); | ||
}); | ||
}); | ||
|
||
describe("when the user is a student", () => { | ||
const setup = () => { | ||
useBoardPermissionsMock.isTeacher = false; | ||
|
||
const { wrapper } = getWrapper({ isToolOutdated: true }); | ||
|
||
return { | ||
wrapper, | ||
}; | ||
}; | ||
|
||
it("should display a student friendly message", () => { | ||
const { wrapper } = setup(); | ||
|
||
const alerts = wrapper.findAllComponents(WarningAlert); | ||
|
||
expect(alerts).toHaveLength(1); | ||
expect(alerts.at(0).text()).toEqual( | ||
"feature-board-external-tool-element.alert.outdated.student" | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |