Skip to content

Commit

Permalink
frontend: pluginSlice.test: Rework plugin slice test to use new plugi…
Browse files Browse the repository at this point in the history
…n settings

Signed-off-by: Vincent T <vtaylor@microsoft.com>
  • Loading branch information
vyncent-t committed Jan 23, 2025
1 parent 3ff6614 commit 2913e45
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions frontend/src/plugin/pluginSlice.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ describe('pluginsSlice reducers', () => {

test('should handle setting a new plugin settings component when plugin name matches', () => {
const existingPluginName = 'test-plugin';
const initialStateWithPlugin: PluginsState = {
const initialStateWithPlugin = {
...initialState,
pluginSettings: [
{
name: existingPluginName,
settingsComponent: undefined,
displaySettingsComponentWithSaveButton: false,
} as PluginInfo,
],
name: existingPluginName,
settingsComponent: undefined,
displaySettingsComponentWithSaveButton: false,
description: 'Test plugin',
homepage: 'https://example.com',
};

const action = setPluginSettingsComponent({
Expand All @@ -41,21 +39,21 @@ describe('pluginsSlice reducers', () => {

const newState = pluginsSlice.reducer(initialStateWithPlugin, action);

expect(newState.pluginSettings[0].settingsComponent).toBeDefined();
expect(newState.pluginSettings[0].displaySettingsComponentWithSaveButton).toBe(true);
expect((newState.pluginSettings[0] as PluginInfo).settingsComponent).toBeDefined();

Check failure on line 42 in frontend/src/plugin/pluginSlice.test.tsx

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-22.04)

src/plugin/pluginSlice.test.tsx > pluginsSlice reducers > should handle setting a new plugin settings component when plugin name matches

TypeError: Cannot read properties of undefined (reading 'settingsComponent') ❯ src/plugin/pluginSlice.test.tsx:42:55
expect((newState.pluginSettings[0] as PluginInfo).displaySettingsComponentWithSaveButton).toBe(
true
);
});

test('should not modify state when plugin name does not match any existing plugin', () => {
const nonExistingPluginName = 'non-existing-plugin';
const initialStateWithPlugin: PluginsState = {
const initialStateWithPlugin = {
...initialState,
pluginSettings: [
{
name: 'existing-plugin',
settingsComponent: undefined,
displaySettingsComponentWithSaveButton: false,
} as PluginInfo,
],
name: 'test-plugin',
settingsComponent: undefined,
displaySettingsComponentWithSaveButton: false,
description: 'Test plugin',
homepage: 'https://example.com',
};

const action = setPluginSettingsComponent({
Expand Down

0 comments on commit 2913e45

Please sign in to comment.