forked from learningequality/kolibri
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from BabyElias/develop
pr
- Loading branch information
Showing
107 changed files
with
1,658 additions
and
1,061 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
85 changes: 85 additions & 0 deletions
85
kolibri/core/assets/src/composables/__mocks__/useSnackbar.js
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,85 @@ | ||
/** | ||
* `useSnackbar` composable function mock. | ||
* | ||
* If default values are sufficient for tests, | ||
* you only need call `jest.mock('<useSnackbar file path>')` | ||
* at the top of a test file. | ||
* | ||
* If you need to override some default values for some tests, | ||
* or if you need to inspect the state of the refs during tests, | ||
* you can import a helper function `useSnackbarMock` that accepts | ||
* an object with values to be overriden and use it together | ||
* with `mockImplementation` as follows: | ||
* | ||
* ``` | ||
* // eslint-disable-next-line import/named | ||
* import useSnackbar, { useSnackbarMock } from '<useSnackbar file path>'; | ||
* | ||
* jest.mock('<useSnackbar file path>') | ||
* describe('describe test', function () { | ||
* let snackbar = { snackbarIsVisible: ref(false) } | ||
* | ||
* beforeAll(() => { | ||
* useSnackbar.mockImplementation(() => useSnackbarMock(snackbar) | ||
* }) | ||
* | ||
* it('the test', () => { | ||
* expect(get(snackbar.snackbarIsVisible)).toEqual(false); | ||
* ) | ||
* }) | ||
* ``` | ||
*/ | ||
import { ref } from 'kolibri.lib.vueCompositionApi'; | ||
import { get, set } from '@vueuse/core'; | ||
|
||
const MOCK_DEFAULTS = { | ||
snackbarIsVisible: ref(false), | ||
snackbarOptions: ref({ | ||
text: '', | ||
autoDismiss: true, | ||
}), | ||
}; | ||
|
||
export function useSnackbarMock(overrides = {}) { | ||
const mocks = { | ||
...MOCK_DEFAULTS, | ||
...overrides, | ||
}; | ||
|
||
const createSnackbar = (options = {}) => { | ||
// reset | ||
set(mocks.snackbarIsVisible, false); | ||
set(mocks.snackbarOptions, {}); | ||
|
||
// set new options | ||
set(mocks.snackbarIsVisible, true); | ||
|
||
// options include text, autoDismiss, duration, actionText, actionCallback, | ||
// hideCallback, bottomPosition | ||
// if the options are a string, set it as the snackbar text | ||
// and default autoDismiss to true | ||
if (typeof options === 'string') { | ||
set(mocks.snackbarOptions, { text: options, autoDismiss: true }); | ||
} else { | ||
set(mocks.snackbarOptions, options); | ||
} | ||
}; | ||
|
||
const clearSnackbar = () => { | ||
set(mocks.snackbarIsVisible, false); | ||
set(mocks.snackbarOptions, {}); | ||
}; | ||
|
||
const setSnackbarText = text => { | ||
set(mocks.snackbarOptions, { ...get(mocks.snackbarOptions), text }); | ||
}; | ||
|
||
return { | ||
createSnackbar, | ||
clearSnackbar, | ||
setSnackbarText, | ||
...mocks, | ||
}; | ||
} | ||
|
||
export default jest.fn(() => useSnackbarMock()); |
62 changes: 62 additions & 0 deletions
62
kolibri/core/assets/src/composables/__mocks__/useTotalProgress.js
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,62 @@ | ||
/** | ||
* `useTotalProgress` composable function mock. | ||
* | ||
* If default values are sufficient for tests, | ||
* you only need call `jest.mock('<useTotalProgress file path>')` | ||
* at the top of a test file. | ||
* | ||
* If you need to override some default values for some tests, | ||
* or if you need to inspect the state of the refs during tests, | ||
* you can import a helper function `useTotalProgressMock` that accepts | ||
* an object with values to be overriden and use it together | ||
* with `mockImplementation` as follows: | ||
* | ||
* ``` | ||
* // eslint-disable-next-line import/named | ||
* import useTotalProgress, { useTotalProgressMock } from '<useTotalProgress file path>'; | ||
* | ||
* jest.mock('<useTotalProgress file path>') | ||
* describe('describe test', function () { | ||
* let totalProgressMock = { totalProgress: ref(null) } | ||
* | ||
* beforeAll(() => { | ||
* useTotalProgress.mockImplementation(() => useTotalProgressMock(totalProgressMock) | ||
* }) | ||
* | ||
* it('the test', () => { | ||
* expect(get(totalProgressMock.totalProgress)).toEqual(null); | ||
* ) | ||
* }) | ||
* ``` | ||
*/ | ||
import { ref, computed } from 'kolibri.lib.vueCompositionApi'; | ||
import { get, set } from '@vueuse/core'; | ||
import { MaxPointsPerContent } from '../../constants'; | ||
|
||
const MOCK_DEFAULTS = { | ||
totalProgress: ref(null), | ||
}; | ||
|
||
export function useTotalProgressMock(overrides = {}) { | ||
const mocks = { | ||
...MOCK_DEFAULTS, | ||
...overrides, | ||
}; | ||
|
||
const totalPoints = computed(() => mocks.totalProgress.value * MaxPointsPerContent); | ||
|
||
const fetchPoints = jest.fn(); | ||
|
||
const incrementTotalProgress = progress => { | ||
set(mocks.totalProgress, get(mocks.totalProgress) + progress); | ||
}; | ||
|
||
return { | ||
totalPoints, | ||
fetchPoints, | ||
incrementTotalProgress, | ||
...mocks, | ||
}; | ||
} | ||
|
||
export default jest.fn(() => useTotalProgressMock()); |
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,49 @@ | ||
import { ref } from 'kolibri.lib.vueCompositionApi'; | ||
import { get, set } from '@vueuse/core'; | ||
|
||
const snackbarIsVisible = ref(false); | ||
const snackbarOptions = ref({ | ||
text: '', | ||
autoDismiss: true, | ||
}); | ||
|
||
export default function useSnackbar() { | ||
const createSnackbar = (options = {}) => { | ||
// reset | ||
set(snackbarIsVisible, false); | ||
set(snackbarOptions, {}); | ||
|
||
// set new options | ||
set(snackbarIsVisible, true); | ||
|
||
// options include text, autoDismiss, duration, actionText, actionCallback, | ||
// hideCallback, bottomPosition | ||
// if the options are a string, set it as the snackbar text | ||
// and default autoDismiss to true | ||
if (typeof options === 'string') { | ||
set(snackbarOptions, { text: options, autoDismiss: true }); | ||
} else { | ||
set(snackbarOptions, options); | ||
} | ||
}; | ||
|
||
const clearSnackbar = () => { | ||
set(snackbarIsVisible, false); | ||
set(snackbarOptions, {}); | ||
}; | ||
|
||
const setSnackbarText = text => { | ||
set(snackbarOptions, { ...get(snackbarOptions), text }); | ||
}; | ||
|
||
return { | ||
// state | ||
snackbarIsVisible, | ||
snackbarOptions, | ||
|
||
// mutators | ||
createSnackbar, | ||
clearSnackbar, | ||
setSnackbarText, | ||
}; | ||
} |
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,31 @@ | ||
import { ref, computed } from 'kolibri.lib.vueCompositionApi'; | ||
import { get, set } from '@vueuse/core'; | ||
import useUser from 'kolibri.coreVue.composables.useUser'; | ||
import { UserProgressResource } from 'kolibri.resources'; | ||
import { MaxPointsPerContent } from '../constants'; | ||
|
||
const totalProgress = ref(null); | ||
|
||
export default function useTotalProgress() { | ||
const totalPoints = computed(() => totalProgress.value * MaxPointsPerContent); | ||
|
||
const fetchPoints = () => { | ||
const { isUserLoggedIn, currentUserId } = useUser(); | ||
if (get(isUserLoggedIn) && get(totalProgress) === null) { | ||
UserProgressResource.fetchModel({ id: get(currentUserId) }).then(progress => { | ||
set(totalProgress, progress.progress); | ||
}); | ||
} | ||
}; | ||
|
||
const incrementTotalProgress = progress => { | ||
set(totalProgress, get(totalProgress) + progress); | ||
}; | ||
|
||
return { | ||
totalProgress, | ||
totalPoints, | ||
fetchPoints, | ||
incrementTotalProgress, | ||
}; | ||
} |
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
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.