Files
2025-08-06 13:49:11 +08:00

72 lines
2.5 KiB
JavaScript

/* global describe: true, test:true, expect:true */
import { app } from '~/reducers/app';
import {
CHANGE_APP_ROOT,
UPDATE_APP_STATE,
UPDATE_SHOW_NOTIFICATION,
ACCEPT_TNC_LICENSE,
ACCEPT_TNC_LICENSE_SUCCESS,
ACCEPT_TNC_LICENSE_ERROR,
} from '~/store/actionTypes';
describe('app reducer', () => {
test('CASE 1: should return initial state', () => {
const expectedState = {
root: 'splash',
sharedPlaylistOnboardingTutorialState: 0,
location: 'United States',
appStatus: 'active',
hasLoggedInOnce: false,
showNotification: false,
fromSplashScreen: false,
ssid: '',
config: {},
};
expect(app(undefined, { type: 'Default' }))
.toEqual(expectedState);
});
test('CASE 2: should return the correct state when actionType is `CHANGE_APP_ROOT` and payload is valid root', () => {
const expectedState = { root: 'home' };
expect(app({}, { type: CHANGE_APP_ROOT, payload: { root: 'home' } }))
.toEqual(expectedState);
});
test('CASE 3: should return the initial state when actionType is `CHANGE_APP_ROOT` and payload is not valid root', () => {
const expectedState = {};
expect(app({}, { type: CHANGE_APP_ROOT, payload: { root: 'something else' } }))
.toEqual(expectedState);
});
test('CASE 8: default should return the appStatus active', () => {
const expectedState = { appStatus: 'active' };
expect(app({ appStatus: 'active' }, { type: UPDATE_APP_STATE, payload: 'active' }))
.toEqual(expectedState);
});
test('CASE 9: default should return the showNotification false', () => {
const expectedState = { showNotification: false };
expect(app({ showNotification: false }, { type: UPDATE_SHOW_NOTIFICATION, payload: false }))
.toEqual(expectedState);
});
test('CASE 10: default should return the state ACCEPT_TNC_LICENSE', () => {
const expectedState = { config: { user_accepted_tnc: true } };
expect(app({ config: { user_accepted_tnc: true } }, { type: ACCEPT_TNC_LICENSE, payload: false }))
.toEqual(expectedState);
});
test('CASE 11: default should return the state ACCEPT_TNC_LICENSE_SUCCESS', () => {
const expectedState = { config: { user_accepted_tnc: true } };
expect(app({ config: { user_accepted_tnc: true } }, { type: ACCEPT_TNC_LICENSE_SUCCESS, payload: false }))
.toEqual(expectedState);
});
test('CASE 12: default should return the config error', () => {
const expectedState = { config: {} };
expect(app({ config: {} }, { type: ACCEPT_TNC_LICENSE_ERROR, payload: false }))
.toEqual(expectedState);
});
});