Skip to content

Commit

Permalink
Added dedicated configSync defaults for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkelM committed Oct 9, 2024
1 parent 5e31b55 commit d42ad6f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 15 deletions.
1 change: 0 additions & 1 deletion test/chromeStorage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe('chromeStorage', function () {
for (let i = 0; i < Object.keys(configSyncDefaults).length; i++) {
expect(setArgs[i + 1]).to.eql([{ [Object.keys(configSyncDefaults)[i]]: Object.values(configSyncDefaults)[i] }]);
}
expect(setArgs[setArgs.length - 1]).to.eql([configSyncDefaults]);

expect(removeArgs).to.eql([["thisKeyShouldBeRemoved"]]);

Expand Down
20 changes: 7 additions & 13 deletions test/playlistPermutations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { configSyncDefaults } from "../src/config.js";
import { configSyncDefaults } from "./testConfig.js";

// ---------- Constants used by the permutations ----------
// Keep these in sync with the values compared against in the tests
Expand All @@ -19,12 +19,6 @@ export const times = {
}

// ---------- Config ----------
// Any overrides to the default that needs to be different for the tests
const overrides = {
shuffleOpenAsPlaylistOption: true
};
const configSyncTestDefaults = { ...configSyncDefaults, ...overrides };

// The configSync should always be the default, with these settings being changed
// This allows us to not have to define something for every setting
const configSyncModifiers = [
Expand Down Expand Up @@ -123,7 +117,7 @@ for (const useCustomApiKeyOption of configSyncModifiers[0]) {
// Exclude invalid combinations
if (!useCustomApiKeyOption && (customYoutubeApiKey !== null || databaseSharingEnabledOption)) continue;

let modifiedConfigSync = deepCopy(configSyncTestDefaults);
let modifiedConfigSync = deepCopy(configSyncDefaults);
modifiedConfigSync.useCustomApiKeyOption = useCustomApiKeyOption;
modifiedConfigSync.customYoutubeApiKey = customYoutubeApiKey;
modifiedConfigSync.databaseSharingEnabledOption = databaseSharingEnabledOption;
Expand All @@ -142,7 +136,7 @@ for (const shuffleOpenInNewTabOption of configSyncModifiers[3]) {
if (!shuffleOpenInNewTabOption && shuffleReUseNewTabOption) continue;
if (!shuffleReUseNewTabOption && shuffleTabId !== null) continue;

let modifiedConfigSync = deepCopy(configSyncTestDefaults);
let modifiedConfigSync = deepCopy(configSyncDefaults);
modifiedConfigSync.shuffleOpenInNewTabOption = shuffleOpenInNewTabOption;
modifiedConfigSync.shuffleReUseNewTabOption = shuffleReUseNewTabOption;
modifiedConfigSync.shuffleTabId = shuffleTabId;
Expand All @@ -156,7 +150,7 @@ configSyncPermutations.openInNewTabPermutations = openInNewTabPermutations;
// Ignore shorts
const ignoreShortsPermutations = [];
for (const shuffleIgnoreShortsOption of configSyncModifiers[6]) {
let modifiedConfigSync = deepCopy(configSyncTestDefaults);
let modifiedConfigSync = deepCopy(configSyncDefaults);
modifiedConfigSync.shuffleIgnoreShortsOption = shuffleIgnoreShortsOption;

ignoreShortsPermutations.push(modifiedConfigSync);
Expand All @@ -167,7 +161,7 @@ configSyncPermutations.ignoreShortsPermutations = ignoreShortsPermutations;
const openAsPlaylistPermutations = [];
for (const shuffleOpenAsPlaylistOption of configSyncModifiers[7]) {
for (const shuffleNumVideosInPlaylist of configSyncModifiers[8]) {
let modifiedConfigSync = deepCopy(configSyncTestDefaults);
let modifiedConfigSync = deepCopy(configSyncDefaults);
// Always open in a new tab, so we can check the stub
modifiedConfigSync.shuffleOpenInNewTabOption = true;

Expand All @@ -189,7 +183,7 @@ for (const activeOption of configSyncModifiers[9]) {
// The allVideosOption and percentageOption do not error out if no value is set
if (["allVideosOption", "percentageOption"].includes(activeOption) && channelSettingsPermutation.type === "empty") continue;

let modifiedConfigSync = deepCopy(configSyncTestDefaults);
let modifiedConfigSync = deepCopy(configSyncDefaults);
let usedChannelSettingsPermutation = deepCopy(channelSettingsPermutation);

usedChannelSettingsPermutation.template.activeOption = activeOption;
Expand Down Expand Up @@ -578,7 +572,7 @@ export function needsDBInteraction(permutation) {
}

// Determine whether or not a permutation needs to interact with the YouTube API
export function needsYTAPIInteraction(permutation, configSync = configSyncTestDefaults) {
export function needsYTAPIInteraction(permutation, configSync = configSyncDefaults) {
const databaseSharing = configSync.databaseSharingEnabledOption;
if (databaseSharing) {
return (needsDBInteraction(permutation) &&
Expand Down
50 changes: 50 additions & 0 deletions test/testConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Contains configuration and other default values, changed to be used as the default in tests

// All keys regarding user settings and their defaults
export const configSyncDefaults = {
// If the user has enabled the custom API key option
"useCustomApiKeyOption": false,
// The custom API key the user has provided. This key is already validated.
"customYoutubeApiKey": null,
// If the user has enabled sharing video ID's with the database
"databaseSharingEnabledOption": true,
// These properties influence the behavior of the "Shuffle" button
"shuffleOpenInNewTabOption": true,
"shuffleReUseNewTabOption": true,
// 0 = only shorts, 1 = no option set (shorts are included), 2 = ignore shorts
"shuffleIgnoreShortsOption": 1,
"shuffleOpenAsPlaylistOption": true,
// How many random videos to add to a playlist (0-50)
"shuffleNumVideosInPlaylist": 10,
// If shuffled videos are opened in a new tab, save the tab ID of that tab here to reuse the tab when the user shuffles again
"shuffleTabId": null,
// channelSettings is a dictionary of channelID -> Dictionary of channel settings
"channelSettings": {},
// These two properties are used by the popup to determine which channel's settings to show
"currentChannelId": null,
"currentChannelName": null,
// The number of videos the user has shuffled so far
// Does not count multiple times if a playlist is shuffled, so is actually numShuffledTimesTotal
"numShuffledVideosTotal": 0,
// These two properties determine the amount of quota remaining today, and the time at which the quota will next reset (daily resets at midnight)
"userQuotaRemainingToday": 200,
// The default reset time is midnight of the next day
"userQuotaResetTime": new Date(new Date().setHours(24, 0, 0, 0)).getTime(),
// We want to regularly check if there are new API keys available (weekly)
"nextAPIKeysCheckTime": new Date(new Date().setHours(168, 0, 0, 0)).getTime(),
// The last version for which the user has viewed the changelog
"lastViewedChangelogVersion": "0",
// For april fools: Will be the number of the year in which the user was last rickrolled (we only want to rickroll the user once per year)
"wasLastRickRolledInYear": "1970",
// Used when updating the extension
"previousVersion": null,
// If the message asking for a review has been shown yet
"reviewMessageShown": false,
// If the message asking for a donation has been shown yet
"donationMessageShown": false,
// The id/date of the last viewed news article
"lastViewedNewsId": null,
// The next time we should check for news (once per day)
// We delay the first check by 24 hours to not immediately show the news after a user has installed the extension
"nextNewsCheckTime": new Date(new Date().setHours(24, 0, 0, 0)).getTime()
};
2 changes: 1 addition & 1 deletion test/testSetup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sinonChrome from 'sinon-chrome';

import { configSyncDefaults } from '../src/config.js';
import { configSyncDefaults } from './testConfig.js';
import { deepCopy, localPlaylistPermutations, databasePermutations } from './playlistPermutations.js';

global.chrome = sinonChrome;
Expand Down

0 comments on commit d42ad6f

Please sign in to comment.