|
| 1 | +import { canSetConfigWithCurrentFunboxes } from "../../../src/ts/test/funbox/funbox-validation"; |
| 2 | + |
| 3 | +import * as Notifications from "../../../src/ts/elements/notifications"; |
| 4 | +describe("funbox-validation", () => { |
| 5 | + describe("canSetConfigWithCurrentFunboxes", () => { |
| 6 | + const addNotificationMock = vi.spyOn(Notifications, "add"); |
| 7 | + afterEach(() => { |
| 8 | + addNotificationMock.mockReset(); |
| 9 | + }); |
| 10 | + |
| 11 | + const testCases = [ |
| 12 | + //checks for frontendForcedConfig |
| 13 | + { |
| 14 | + key: "mode", |
| 15 | + value: "zen", |
| 16 | + funbox: ["memory"], |
| 17 | + error: "You can't set mode to zen with currently active funboxes.", |
| 18 | + }, |
| 19 | + { key: "mode", value: "words", funbox: ["memory"] }, //ok |
| 20 | + |
| 21 | + //checks for zen mode |
| 22 | + ...[ |
| 23 | + "58008", //getWord |
| 24 | + "wikipedia", //pullSection |
| 25 | + "morse", //alterText |
| 26 | + "polyglot", //withWords |
| 27 | + "rAnDoMcAsE", //changesCapitalisation |
| 28 | + "nospace", //nospace |
| 29 | + "plus_one", //toPush: |
| 30 | + "read_ahead_easy", //changesWordVisibility |
| 31 | + "tts", //speaks |
| 32 | + "layout_mirror", //changesLayout |
| 33 | + "zipf", //changesWordsFrequency |
| 34 | + ].map((funbox) => ({ |
| 35 | + key: "mode", |
| 36 | + value: "zen", |
| 37 | + funbox: [funbox], |
| 38 | + error: "You can't set mode to zen with currently active funboxes.", |
| 39 | + })), |
| 40 | + { key: "mode", value: "zen", funbox: ["mirror"] }, //ok |
| 41 | + { key: "mode", value: "zen", funbox: ["space_balls"] }, //no frontendFunctions |
| 42 | + |
| 43 | + //checks for words and custom |
| 44 | + ...["quote", "custom"].flatMap((value) => |
| 45 | + [ |
| 46 | + "58008", //getWord |
| 47 | + "wikipedia", //pullSection |
| 48 | + "polyglot", //withWords |
| 49 | + "zipf", //changesWordsFrequency |
| 50 | + ].map((funbox) => ({ |
| 51 | + key: "mode", |
| 52 | + value, |
| 53 | + funbox: [funbox], |
| 54 | + error: `You can't set mode to ${value} with currently active funboxes.`, |
| 55 | + })) |
| 56 | + ), |
| 57 | + { key: "mode", value: "quote", funbox: ["space_balls"] }, //no frontendFunctions |
| 58 | + ]; |
| 59 | + it.for(testCases)( |
| 60 | + `check $funbox with $key=$value`, |
| 61 | + ({ key, value, funbox, error }) => { |
| 62 | + expect( |
| 63 | + canSetConfigWithCurrentFunboxes(key, value, funbox.join("#")) |
| 64 | + ).toBe(error === undefined); |
| 65 | + |
| 66 | + if (error !== undefined) { |
| 67 | + expect(addNotificationMock).toHaveBeenCalledWith(error, 0, { |
| 68 | + duration: 5, |
| 69 | + }); |
| 70 | + } |
| 71 | + } |
| 72 | + ); |
| 73 | + }); |
| 74 | +}); |
0 commit comments