-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding achievements store tests and fixing intellisense * vitest imports finally fully working * testing is working * achievements store now fully tested
- Loading branch information
Showing
16 changed files
with
299 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,11 @@ | |
"files": [ | ||
"dist/" | ||
], | ||
"pnpm": { | ||
"patchedDependencies": { | ||
"@types/[email protected]": "patches-@[email protected]" | ||
} | ||
}, | ||
"scripts": { | ||
"test-unit": "vitest", | ||
"coverage": "vitest --coverage", | ||
|
@@ -57,6 +62,7 @@ | |
"@sinclair/typebox": "^0.24.28", | ||
"ajv": "^8.11.0", | ||
"ajv-formats": "^2.1.1", | ||
"clone-deep": "^4.0.1", | ||
"deepmerge": "^4.2.2", | ||
"fuse.js": "^6.6.2", | ||
"howler": "^2.2.3", | ||
|
@@ -68,6 +74,7 @@ | |
"@pinia/testing": "^0.0.16", | ||
"@testing-library/jest-dom": "^5.16.5", | ||
"@testing-library/vue": "^7.0.0", | ||
"@types/clone-deep": "^4.0.1", | ||
"@types/howler": "^2.2.3", | ||
"@types/jest": "^29.5.0", | ||
"@types/js-yaml": "^4.0.5", | ||
|
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,12 @@ | ||
diff --git a/index.d.ts b/index.d.ts | ||
index 43ba6b7fe458e77d152fe0b2f7afeac05d8fc563..3bf91587abf21f15ac166bcae1f5a59b23884b87 100755 | ||
--- a/index.d.ts | ||
+++ b/index.d.ts | ||
@@ -7,7 +7,7 @@ | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// Minimum TypeScript Version: 4.3 | ||
|
||
-/// <reference types="jest" /> | ||
+// See https://github.com/testing-library/jest-dom/issues/427 for reference | ||
|
||
import { TestingLibraryMatchers } from './matchers'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { useRenderingStore } from '@/lib'; | ||
import { useRenderingStore } from '@/stores/rendering-store'; | ||
import { computed, ref } from 'vue'; | ||
import { useMain } from '@/stores/main-store'; |
163 changes: 163 additions & 0 deletions
163
packages/narrat/src/stores/__tests__/achievements-store.spec.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 { setActivePinia, createPinia } from 'pinia'; | ||
import { describe, it, expect, beforeEach, vi } from 'vitest'; | ||
import { | ||
AchievementsSetupConfig, | ||
useAchievements, | ||
} from '../achievements-store'; | ||
import { mockConfig } from '@/tests/mock-config'; | ||
import cloneDeep from 'clone-deep'; | ||
import { useConfig } from '@/stores/config-store'; | ||
import { useNotifications } from '../notification-store'; | ||
|
||
const unlockTime = new Date(2023, 4, 1); | ||
|
||
const mockData: AchievementsSetupConfig = { | ||
normalAchievement: { | ||
name: 'Normal Achievement', | ||
description: 'This is a normal achievement', | ||
icon: 'normal', | ||
}, | ||
secretAchievement: { | ||
name: 'Secret Achievement', | ||
description: 'This is a secret achievement', | ||
icon: 'secret', | ||
}, | ||
}; | ||
|
||
describe('Achievements Store', () => { | ||
beforeEach(() => { | ||
vi.useFakeTimers(); | ||
vi.setSystemTime(unlockTime); | ||
setActivePinia(createPinia()); | ||
const config = cloneDeep(mockConfig); | ||
config.achievements.achievements = mockData; | ||
useConfig().setConfig(config); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.useRealTimers(); | ||
}); | ||
|
||
it('generateSaveData: generates the save data', () => { | ||
const achievements = useAchievements(); | ||
achievements.setupAchievements(mockData); | ||
const unlockTime = new Date().toISOString(); | ||
achievements.unlock('normalAchievement'); | ||
expect(achievements.generateSaveData()).toEqual({ | ||
achievements: { | ||
normalAchievement: { | ||
id: 'normalAchievement', | ||
unlocked: true, | ||
unlockTime, | ||
}, | ||
secretAchievement: { | ||
id: 'secretAchievement', | ||
unlocked: false, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('loadSaveData: loads the save data', () => { | ||
const achievements = useAchievements(); | ||
achievements.setupAchievements(mockData); | ||
achievements.unlock('normalAchievement'); | ||
const saveData = achievements.generateSaveData(); | ||
achievements.reset(mockData); | ||
achievements.loadSaveData(saveData); | ||
expect(achievements.achievements).toEqual({ | ||
normalAchievement: { | ||
id: 'normalAchievement', | ||
unlocked: true, | ||
unlockTime: unlockTime.toISOString(), | ||
}, | ||
secretAchievement: { | ||
id: 'secretAchievement', | ||
unlocked: false, | ||
}, | ||
}); | ||
}); | ||
|
||
it('setupAchievements: sets up the achievements when passed for configuration', () => { | ||
const achievements = useAchievements(); | ||
achievements.setupAchievements(mockData); | ||
expect(achievements.achievements).toEqual({ | ||
normalAchievement: { | ||
id: 'normalAchievement', | ||
unlocked: false, | ||
}, | ||
secretAchievement: { | ||
id: 'secretAchievement', | ||
unlocked: false, | ||
}, | ||
}); | ||
}); | ||
|
||
it('reset: resets the achievements when passed for configuration', () => { | ||
const achievements = useAchievements(); | ||
achievements.setupAchievements(mockData); | ||
achievements.unlock('normalAchievement'); | ||
achievements.reset(mockData); | ||
expect(achievements.achievements).toEqual({ | ||
normalAchievement: { | ||
id: 'normalAchievement', | ||
unlocked: false, | ||
}, | ||
secretAchievement: { | ||
id: 'secretAchievement', | ||
unlocked: false, | ||
}, | ||
}); | ||
}); | ||
|
||
it('hasAchievement: returns true if the achievement is unlocked', () => { | ||
const achievements = useAchievements(); | ||
achievements.setupAchievements(mockData); | ||
achievements.unlock('normalAchievement'); | ||
expect(achievements.hasAchievement('normalAchievement')).toBe(true); | ||
}); | ||
|
||
it('hasAchievement: returns false if the achievement is not unlocked', () => { | ||
const achievements = useAchievements(); | ||
achievements.setupAchievements(mockData); | ||
expect(achievements.hasAchievement('normalAchievement')).toBe(false); | ||
}); | ||
|
||
it('getExistingAchievement: returns the achievement if it exists', () => { | ||
const achievements = useAchievements(); | ||
achievements.setupAchievements(mockData); | ||
expect(achievements.getExistingAchievement('normalAchievement')).toEqual({ | ||
id: 'normalAchievement', | ||
unlocked: false, | ||
}); | ||
}); | ||
|
||
it('unlock: unlocks the achievement', () => { | ||
const achievements = useAchievements(); | ||
achievements.setupAchievements(mockData); | ||
achievements.unlock('normalAchievement'); | ||
expect(achievements.hasAchievement('normalAchievement')).toBe(true); | ||
}); | ||
it('unlock: sends a notification if the option is enabled', () => { | ||
const achievements = useAchievements(); | ||
achievements.setupAchievements(mockData); | ||
const config = useConfig().config; | ||
config.achievements.notifyNewAchievements = true; | ||
useConfig().setConfig(config); | ||
const notifications = useNotifications(); | ||
const spy = vi.spyOn(notifications, 'addNotification'); | ||
achievements.unlock('normalAchievement'); | ||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
it('unlock: does not send a notification if the option is disabled', () => { | ||
const achievements = useAchievements(); | ||
achievements.setupAchievements(mockData); | ||
const config = useConfig().config; | ||
config.achievements.notifyNewAchievements = false; | ||
useConfig().setConfig(config); | ||
const notifications = useNotifications(); | ||
const spy = vi.spyOn(notifications, 'addNotification'); | ||
achievements.unlock('normalAchievement'); | ||
expect(spy).not.toHaveBeenCalled(); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Config, defaultConfig } from '@/config/config-output'; | ||
import { defaultLayoutConfig } from '@/config/layout-config'; | ||
import { useConfig } from '@/stores/config-store'; | ||
|
||
export const mockConfig: Config = defaultConfig; | ||
|
||
export const setMockConfig = () => { | ||
useConfig().setConfig(mockConfig); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "./", | ||
"composite": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"allowSyntheticDefaultImports": true, | ||
"resolveJsonModule": true | ||
"resolveJsonModule": true, | ||
"types": ["jsdom", "vitest/globals", "@testing-library/jest-dom"], | ||
"paths": { | ||
"@/*": ["src/*"] | ||
} | ||
}, | ||
"include": ["vite.config.ts", "package.json"] | ||
} |
Oops, something went wrong.