Spaces:
Running
Running
Download algospaced-ui/tests/storeWindowUI.test.mjs from iamfebin/algospaced-dsa: direct link, hf CLI and curl.
- Browser
- Download file 5.21 kB
-
https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/algospaced-ui/tests/storeWindowUI.test.mjs
- Command line
-
hf download hf://spaces/iamfebin/algospaced-dsa/algospaced-ui/tests/storeWindowUI.test.mjs
-
curl -L -o storeWindowUI.test.mjs https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/algospaced-ui/tests/storeWindowUI.test.mjs
5.21 kB
| import test from 'node:test'; | |
| import assert from 'node:assert/strict'; | |
| import { STORE_CATALOG, STORE_CATALOG_MAP } from '../src/data/storeCatalog.ts'; | |
| import { AURELIA_GIFT_REACTIONS } from '../src/components/store/giftReactions.ts'; | |
| test('UI-1: Window registry contains store window ID', () => { | |
| const WINDOW_IDS = [ | |
| 'queue', 'journey', 'terminal', 'computer', 'sync', 'github', | |
| 'python', 'mysql', 'settings', 'createProblem', 'editProblem', | |
| 'companion', 'cardManager', 'store' | |
| ]; | |
| assert.strictEqual(WINDOW_IDS.includes('store'), true); | |
| }); | |
| test('UI-2: Store Catalog has complete 12 items with accurate categories', () => { | |
| assert.strictEqual(STORE_CATALOG.length, 12); | |
| const consumables = STORE_CATALOG.filter(i => i.category === 'consumable'); | |
| const cosmetics = STORE_CATALOG.filter(i => i.category === 'cosmetic'); | |
| const gifts = STORE_CATALOG.filter(i => i.category === 'companion_gift'); | |
| assert.strictEqual(consumables.length, 4); | |
| assert.strictEqual(cosmetics.length, 4); | |
| assert.strictEqual(gifts.length, 4); | |
| }); | |
| test('UI-3: Purchase affordance correctly identifies insufficient gold and exact deficit', () => { | |
| function getPurchaseAffordance(playerGold, itemPrice) { | |
| const isAffordable = playerGold >= itemPrice; | |
| return { | |
| isAffordable, | |
| label: isAffordable ? 'Purchase' : 'Insufficient Gold', | |
| deficit: isAffordable ? 0 : itemPrice - playerGold | |
| }; | |
| } | |
| // Exact funds | |
| const exact = getPurchaseAffordance(150, 150); | |
| assert.strictEqual(exact.isAffordable, true); | |
| assert.strictEqual(exact.label, 'Purchase'); | |
| assert.strictEqual(exact.deficit, 0); | |
| // Short by 1 gold | |
| const shortOne = getPurchaseAffordance(149, 150); | |
| assert.strictEqual(shortOne.isAffordable, false); | |
| assert.strictEqual(shortOne.label, 'Insufficient Gold'); | |
| assert.strictEqual(shortOne.deficit, 1); | |
| // Zero balance | |
| const zeroBal = getPurchaseAffordance(0, 75); | |
| assert.strictEqual(zeroBal.isAffordable, false); | |
| assert.strictEqual(zeroBal.label, 'Insufficient Gold'); | |
| assert.strictEqual(zeroBal.deficit, 75); | |
| }); | |
| test('UI-4: Vault Item determines correct action label and button routing', () => { | |
| function getVaultAction(category, isEquipped = false) { | |
| switch (category) { | |
| case 'consumable': | |
| return 'Consume'; | |
| case 'cosmetic': | |
| return isEquipped ? 'Unequip' : 'Equip'; | |
| case 'companion_gift': | |
| return 'Present Gift'; | |
| default: | |
| return 'Inspect'; | |
| } | |
| } | |
| assert.strictEqual(getVaultAction('consumable'), 'Consume'); | |
| assert.strictEqual(getVaultAction('cosmetic', false), 'Equip'); | |
| assert.strictEqual(getVaultAction('cosmetic', true), 'Unequip'); | |
| assert.strictEqual(getVaultAction('companion_gift'), 'Present Gift'); | |
| }); | |
| test('UI-5: Quantity stack badge format conforms to xN convention', () => { | |
| function formatStackBadge(qty) { | |
| return qty > 1 ? `x${qty}` : ''; | |
| } | |
| assert.strictEqual(formatStackBadge(1), ''); | |
| assert.strictEqual(formatStackBadge(2), 'x2'); | |
| assert.strictEqual(formatStackBadge(10), 'x10'); | |
| }); | |
| test('UI-6: Aurelia gift reactions provide emotional feedback and bonus points', () => { | |
| const tea = AURELIA_GIFT_REACTIONS['gift_starflower_tea']; | |
| assert.strictEqual(tea.emotion, 'smiling_warmly'); | |
| assert.strictEqual(tea.bondBonus, 15); | |
| assert.strictEqual(tea.dialogue.includes('starflower warmth'), true); | |
| const shawl = AURELIA_GIFT_REACTIONS['gift_silk_shawl']; | |
| assert.strictEqual(shawl.emotion, 'smiling_warmly'); | |
| assert.strictEqual(shawl.bondBonus, 30); | |
| const musicBox = AURELIA_GIFT_REACTIONS['gift_music_box']; | |
| assert.strictEqual(musicBox.emotion, 'excited_expression'); | |
| assert.strictEqual(musicBox.bondBonus, 60); | |
| const pendant = AURELIA_GIFT_REACTIONS['gift_elixir_pendant']; | |
| assert.strictEqual(pendant.emotion, 'excited_expression'); | |
| assert.strictEqual(pendant.bondBonus, 100); | |
| }); | |
| test('UI-7: Empty vault renders friendly empty state directing to Emporium', () => { | |
| function getEmptyVaultDisplay(inventoryCount) { | |
| if (inventoryCount === 0) { | |
| return { | |
| message: 'Your satchel is empty. Visit the Emporium to acquire items!', | |
| actionText: 'Browse Emporium' | |
| }; | |
| } | |
| return null; | |
| } | |
| const emptyRes = getEmptyVaultDisplay(0); | |
| assert.notStrictEqual(emptyRes, null); | |
| assert.strictEqual(emptyRes.message, 'Your satchel is empty. Visit the Emporium to acquire items!'); | |
| assert.strictEqual(emptyRes.actionText, 'Browse Emporium'); | |
| assert.strictEqual(getEmptyVaultDisplay(1), null); | |
| }); | |
| test('UI-8: Live gold counter formats integer balances and sanitizes negative numbers', () => { | |
| function sanitizeAndFormatGold(gold) { | |
| const safe = Math.max(0, gold || 0); | |
| return `${safe}g`; | |
| } | |
| assert.strictEqual(sanitizeAndFormatGold(0), '0g'); | |
| assert.strictEqual(sanitizeAndFormatGold(250), '250g'); | |
| assert.strictEqual(sanitizeAndFormatGold(-100), '0g'); | |
| }); | |
| test('UI-9: Store catalog lookup via STORE_CATALOG_MAP resolves valid items', () => { | |
| const item = STORE_CATALOG_MAP['consumable_streak_freeze']; | |
| assert.notStrictEqual(item, undefined); | |
| assert.strictEqual(item.name, 'Elixir of Frozen Time'); | |
| assert.strictEqual(item.effect_type, 'streak_freeze'); | |
| }); | |