1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { theme, primaryColor, withDisasm } from './appState'; 17import { RootState } from '..'; 18 19export const mockAllState: RootState = { 20 appState: { 21 theme: 'light', 22 primaryColor: '#e32b49', 23 disasm: false, 24 }, 25 options: { 26 isLoading: false, 27 options: [], 28 pickedOptions: {}, 29 }, 30 syntax: { 31 isLoading: false, 32 syntax: { tokenizer: { root: [] } }, 33 }, 34 code: { 35 isRunLoading: false, 36 isCompileLoading: false, 37 code: 'initial code', 38 compileRes: null, 39 runRes: null, 40 }, 41 logs: { 42 compileOut: [], 43 compileErr: [], 44 runOut: [], 45 runErr: [], 46 disasmOut: [], 47 disasmErr: [], 48 out: [], 49 err: [], 50 }, 51}; 52describe('Redux Selectors', () => { 53 let mockState: RootState; 54 55 beforeEach(() => { 56 mockState = mockAllState; 57 }); 58 59 it('should select the theme from appState', () => { 60 expect(theme(mockState)).toBe('light'); 61 mockState.appState.theme = 'dark'; 62 expect(theme(mockState)).toBe('dark'); 63 }); 64 65 it('should select the primaryColor from appState', () => { 66 expect(primaryColor(mockState)).toBe('#e32b49'); 67 mockState.appState.primaryColor = '#000000'; 68 expect(primaryColor(mockState)).toBe('#000000'); 69 }); 70 71 it('should select the disasm value from appState', () => { 72 expect(withDisasm(mockState)).toBe(false); 73 mockState.appState.disasm = true; 74 expect(withDisasm(mockState)).toBe(true); 75 }); 76}); 77