import { fromJS } from 'immutable';
import {
  makeSelectWebPush,
  makeSelectCreateError,
  makeSelectCreateTemplateInProgress,
  makeSelectEditTemplateInProgress,
  makeSelectEditError,
  makeSelectUploadedAssetData,
} from '../selectors';

describe('WebPush selectors', () => {
  // Mock state structures
  const mockWebPushState = {
    createTemplateInProgress: true,
    response: { id: 1, name: 'Test Template', content: 'Test Content' },
    createTemplateErrorMessage: 'Create error occurred',
    editTemplateInProgress: false,
    editResponse: { id: 2, name: 'Edited Template' },
    editTemplateErrorMessage: 'Edit error occurred',
    uploadedAssetData: {
      id: 100,
      url: 'https://example.com/image.jpg',
      fileName: 'test-image.jpg',
      fileSize: 1024000,
    },
    uploadAssetSuccess: true,
    assetUploading: false,
    otherProperty: 'test-value',
  };

  const mockStateWithWebPush = fromJS({
    webPush: mockWebPushState,
    otherState: { value: 'test' },
  });

  const mockStateWithoutWebPush = fromJS({
    otherState: { value: 'test' },
  });

  const mockStateWithEmptyWebPush = fromJS({
    webPush: {},
    otherState: { value: 'test' },
  });

  const mockStateWithPartialWebPush = fromJS({
    webPush: {
      createTemplateInProgress: true,
      uploadedAssetData: { id: 200, url: 'https://example.com/partial.jpg' },
      // Missing other properties to test defaults
    },
    otherState: { value: 'test' },
  });

  describe('makeSelectWebPush', () => {
    it.concurrent('should select the webPush state and convert to JS', () => {
      const selector = makeSelectWebPush();
      const result = selector(mockStateWithWebPush);

      expect(result).toEqual(mockWebPushState);
      expect(typeof result).toBe('object');
      expect(Array.isArray(result)).toBe(false);
    });

    it.concurrent('should return empty object when webPush state does not exist', () => {
      const selector = makeSelectWebPush();
      const result = selector(mockStateWithoutWebPush);

      expect(result).toEqual({});
    });

    it.concurrent('should return empty object when webPush state is empty', () => {
      const selector = makeSelectWebPush();
      const result = selector(mockStateWithEmptyWebPush);

      expect(result).toEqual({});
    });

    it.concurrent('should handle partial webPush state', () => {
      const selector = makeSelectWebPush();
      const result = selector(mockStateWithPartialWebPush);

      expect(result).toEqual({
        createTemplateInProgress: true,
        uploadedAssetData: { id: 200, url: 'https://example.com/partial.jpg' },
      });
    });

    it.concurrent('should convert immutable nested objects to JS', () => {
      const stateWithNested = fromJS({
        webPush: {
          response: {
            id: 1,
            nested: {
              deep: {
                value: 'test',
              },
            },
          },
        },
      });

      const selector = makeSelectWebPush();
      const result = selector(stateWithNested);

      expect(result.response.nested.deep.value).toBe('test');
      expect(typeof result.response).toBe('object');
      expect(Array.isArray(result.response)).toBe(false);
    });
  });

  describe('makeSelectCreateError', () => {
    it.concurrent('should select createTemplateErrorMessage when it exists', () => {
      const selector = makeSelectCreateError();
      const result = selector(mockStateWithWebPush);

      expect(result).toBe('Create error occurred');
    });

    it.concurrent('should return empty string when createTemplateErrorMessage does not exist', () => {
      const selector = makeSelectCreateError();
      const result = selector(mockStateWithoutWebPush);

      expect(result).toBe('');
    });

    it.concurrent('should return empty string when webPush state is empty', () => {
      const selector = makeSelectCreateError();
      const result = selector(mockStateWithEmptyWebPush);

      expect(result).toBe('');
    });

    it.concurrent('should return empty string when createTemplateErrorMessage is missing in partial state', () => {
      const selector = makeSelectCreateError();
      const result = selector(mockStateWithPartialWebPush);

      expect(result).toBe('');
    });

    it.concurrent('should return empty string when createTemplateErrorMessage is null', () => {
      const stateWithNullError = fromJS({
        webPush: {
          createTemplateErrorMessage: null,
        },
      });

      const selector = makeSelectCreateError();
      const result = selector(stateWithNullError);

      expect(result).toBe('');
    });

    it.concurrent('should return empty string when createTemplateErrorMessage is undefined', () => {
      const stateWithUndefinedError = fromJS({
        webPush: {
          createTemplateErrorMessage: undefined,
        },
      });

      const selector = makeSelectCreateError();
      const result = selector(stateWithUndefinedError);

      expect(result).toBe('');
    });

    it.concurrent('should handle empty string error message', () => {
      const stateWithEmptyError = fromJS({
        webPush: {
          createTemplateErrorMessage: '',
        },
      });

      const selector = makeSelectCreateError();
      const result = selector(stateWithEmptyError);

      expect(result).toBe('');
    });
  });

  describe('makeSelectCreateTemplateInProgress', () => {
    it.concurrent('should select createTemplateInProgress when it is true', () => {
      const selector = makeSelectCreateTemplateInProgress();
      const result = selector(mockStateWithWebPush);

      expect(result).toBe(true);
    });

    it.concurrent('should select createTemplateInProgress when it is false', () => {
      const stateWithFalse = fromJS({
        webPush: {
          createTemplateInProgress: false,
        },
      });

      const selector = makeSelectCreateTemplateInProgress();
      const result = selector(stateWithFalse);

      expect(result).toBe(false);
    });

    it.concurrent('should return false when createTemplateInProgress does not exist', () => {
      const selector = makeSelectCreateTemplateInProgress();
      const result = selector(mockStateWithoutWebPush);

      expect(result).toBe(false);
    });

    it.concurrent('should return false when webPush state is empty', () => {
      const selector = makeSelectCreateTemplateInProgress();
      const result = selector(mockStateWithEmptyWebPush);

      expect(result).toBe(false);
    });

    it.concurrent('should return true when createTemplateInProgress is true in partial state', () => {
      const selector = makeSelectCreateTemplateInProgress();
      const result = selector(mockStateWithPartialWebPush);

      expect(result).toBe(true);
    });

    it.concurrent('should return false when createTemplateInProgress is null', () => {
      const stateWithNull = fromJS({
        webPush: {
          createTemplateInProgress: null,
        },
      });

      const selector = makeSelectCreateTemplateInProgress();
      const result = selector(stateWithNull);

      expect(result).toBe(false);
    });

    it.concurrent('should return false when createTemplateInProgress is undefined', () => {
      const stateWithUndefined = fromJS({
        webPush: {
          createTemplateInProgress: undefined,
        },
      });

      const selector = makeSelectCreateTemplateInProgress();
      const result = selector(stateWithUndefined);

      expect(result).toBe(false);
    });
  });

  describe('makeSelectEditTemplateInProgress', () => {
    it.concurrent('should select editTemplateInProgress when it is false', () => {
      const selector = makeSelectEditTemplateInProgress();
      const result = selector(mockStateWithWebPush);

      expect(result).toBe(false);
    });

    it.concurrent('should select editTemplateInProgress when it is true', () => {
      const stateWithTrue = fromJS({
        webPush: {
          editTemplateInProgress: true,
        },
      });

      const selector = makeSelectEditTemplateInProgress();
      const result = selector(stateWithTrue);

      expect(result).toBe(true);
    });

    it.concurrent('should return false when editTemplateInProgress does not exist', () => {
      const selector = makeSelectEditTemplateInProgress();
      const result = selector(mockStateWithoutWebPush);

      expect(result).toBe(false);
    });

    it.concurrent('should return false when webPush state is empty', () => {
      const selector = makeSelectEditTemplateInProgress();
      const result = selector(mockStateWithEmptyWebPush);

      expect(result).toBe(false);
    });

    it.concurrent('should return false when editTemplateInProgress is missing in partial state', () => {
      const selector = makeSelectEditTemplateInProgress();
      const result = selector(mockStateWithPartialWebPush);

      expect(result).toBe(false);
    });

    it.concurrent('should return false when editTemplateInProgress is null', () => {
      const stateWithNull = fromJS({
        webPush: {
          editTemplateInProgress: null,
        },
      });

      const selector = makeSelectEditTemplateInProgress();
      const result = selector(stateWithNull);

      expect(result).toBe(false);
    });

    it.concurrent('should return false when editTemplateInProgress is undefined', () => {
      const stateWithUndefined = fromJS({
        webPush: {
          editTemplateInProgress: undefined,
        },
      });

      const selector = makeSelectEditTemplateInProgress();
      const result = selector(stateWithUndefined);

      expect(result).toBe(false);
    });
  });

  describe('makeSelectEditError', () => {
    it.concurrent('should select editTemplateErrorMessage when it exists', () => {
      const selector = makeSelectEditError();
      const result = selector(mockStateWithWebPush);

      expect(result).toBe('Edit error occurred');
    });

    it.concurrent('should return empty string when editTemplateErrorMessage does not exist', () => {
      const selector = makeSelectEditError();
      const result = selector(mockStateWithoutWebPush);

      expect(result).toBe('');
    });

    it.concurrent('should return empty string when webPush state is empty', () => {
      const selector = makeSelectEditError();
      const result = selector(mockStateWithEmptyWebPush);

      expect(result).toBe('');
    });

    it.concurrent('should return empty string when editTemplateErrorMessage is missing in partial state', () => {
      const selector = makeSelectEditError();
      const result = selector(mockStateWithPartialWebPush);

      expect(result).toBe('');
    });

    it.concurrent('should return empty string when editTemplateErrorMessage is null', () => {
      const stateWithNullError = fromJS({
        webPush: {
          editTemplateErrorMessage: null,
        },
      });

      const selector = makeSelectEditError();
      const result = selector(stateWithNullError);

      expect(result).toBe('');
    });

    it.concurrent('should return empty string when editTemplateErrorMessage is undefined', () => {
      const stateWithUndefinedError = fromJS({
        webPush: {
          editTemplateErrorMessage: undefined,
        },
      });

      const selector = makeSelectEditError();
      const result = selector(stateWithUndefinedError);

      expect(result).toBe('');
    });

    it.concurrent('should handle empty string error message', () => {
      const stateWithEmptyError = fromJS({
        webPush: {
          editTemplateErrorMessage: '',
        },
      });

      const selector = makeSelectEditError();
      const result = selector(stateWithEmptyError);

      expect(result).toBe('');
    });

    it.concurrent('should handle long error messages', () => {
      const longErrorMessage = 'A'.repeat(1000);
      const stateWithLongError = fromJS({
        webPush: {
          editTemplateErrorMessage: longErrorMessage,
        },
      });

      const selector = makeSelectEditError();
      const result = selector(stateWithLongError);

      expect(result).toBe(longErrorMessage);
      expect(result.length).toBe(1000);
    });
  });

  describe('makeSelectUploadedAssetData', () => {
    it.concurrent('should select uploadedAssetData when it exists', () => {
      const selector = makeSelectUploadedAssetData();
      const result = selector(mockStateWithWebPush);

      expect(result).toEqual({
        id: 100,
        url: 'https://example.com/image.jpg',
        fileName: 'test-image.jpg',
        fileSize: 1024000,
      });
      expect(typeof result).toBe('object');
      expect(Array.isArray(result)).toBe(false);
    });

    it.concurrent('should return empty object when uploadedAssetData does not exist', () => {
      const selector = makeSelectUploadedAssetData();
      const result = selector(mockStateWithoutWebPush);

      expect(result).toEqual({});
    });

    it.concurrent('should return empty object when webPush state is empty', () => {
      const selector = makeSelectUploadedAssetData();
      const result = selector(mockStateWithEmptyWebPush);

      expect(result).toEqual({});
    });

    it.concurrent('should return uploadedAssetData from partial state', () => {
      const selector = makeSelectUploadedAssetData();
      const result = selector(mockStateWithPartialWebPush);

      expect(result).toEqual({
        id: 200,
        url: 'https://example.com/partial.jpg',
      });
    });

    it.concurrent('should return empty object when uploadedAssetData is null', () => {
      const stateWithNullAssetData = fromJS({
        webPush: {
          uploadedAssetData: null,
        },
      });

      const selector = makeSelectUploadedAssetData();
      const result = selector(stateWithNullAssetData);

      expect(result).toEqual({});
    });

    it.concurrent('should return empty object when uploadedAssetData is undefined', () => {
      const stateWithUndefinedAssetData = fromJS({
        webPush: {
          uploadedAssetData: undefined,
        },
      });

      const selector = makeSelectUploadedAssetData();
      const result = selector(stateWithUndefinedAssetData);

      expect(result).toEqual({});
    });

    it.concurrent('should convert immutable uploadedAssetData to JS', () => {
      const stateWithNestedAsset = fromJS({
        webPush: {
          uploadedAssetData: {
            id: 300,
            metadata: {
              width: 1920,
              height: 1080,
              format: 'jpg',
            },
          },
        },
      });

      const selector = makeSelectUploadedAssetData();
      const result = selector(stateWithNestedAsset);

      expect(result.metadata.width).toBe(1920);
      expect(result.metadata.height).toBe(1080);
      expect(result.metadata.format).toBe('jpg');
      expect(typeof result.metadata).toBe('object');
    });

    it.concurrent('should handle uploadedAssetData with empty object', () => {
      const stateWithEmptyAsset = fromJS({
        webPush: {
          uploadedAssetData: {},
        },
      });

      const selector = makeSelectUploadedAssetData();
      const result = selector(stateWithEmptyAsset);

      expect(result).toEqual({});
    });

    it.concurrent('should select uploadedAssetData0 when templateType is 0', () => {
      const stateWithAssetData0 = fromJS({
        webPush: {
          uploadedAssetData0: {
            id: 400,
            url: 'https://example.com/image0.jpg',
            fileName: 'image0.jpg',
          },
        },
      });

      const selector = makeSelectUploadedAssetData(0);
      const result = selector(stateWithAssetData0);

      expect(result).toEqual({
        id: 400,
        url: 'https://example.com/image0.jpg',
        fileName: 'image0.jpg',
      });
    });

    it.concurrent('should select uploadedAssetData1 when templateType is 1', () => {
      const stateWithAssetData1 = fromJS({
        webPush: {
          uploadedAssetData1: {
            id: 401,
            url: 'https://example.com/image1.jpg',
            fileName: 'image1.jpg',
          },
        },
      });

      const selector = makeSelectUploadedAssetData(1);
      const result = selector(stateWithAssetData1);

      expect(result).toEqual({
        id: 401,
        url: 'https://example.com/image1.jpg',
        fileName: 'image1.jpg',
      });
    });

    it.concurrent('should return empty object when templateType-specific key does not exist', () => {
      const stateWithoutTemplateType = fromJS({
        webPush: {
          uploadedAssetData: {
            id: 100,
            url: 'https://example.com/default.jpg',
          },
        },
      });

      const selector = makeSelectUploadedAssetData(0);
      const result = selector(stateWithoutTemplateType);

      expect(result).toEqual({});
    });

    it.concurrent('should handle plain JS object stored directly (not Immutable)', () => {
      // Simulate the reducer storing plain JS object directly
      const stateWithPlainJS = fromJS({
        webPush: {
          uploadedAssetData: {
            id: 500,
            url: 'https://example.com/plain.jpg',
          },
        },
      });
      
      // Manually set a plain JS object to simulate the bug scenario
      const plainJSState = stateWithPlainJS.setIn(['webPush', 'uploadedAssetData'], {
        id: 500,
        url: 'https://example.com/plain.jpg',
      });

      const selector = makeSelectUploadedAssetData();
      const result = selector(plainJSState);

      expect(result).toEqual({
        id: 500,
        url: 'https://example.com/plain.jpg',
      });
    });

    it.concurrent('should handle plain JS object with templateType', () => {
      // Simulate the reducer storing plain JS object with templateType
      const stateWithPlainJS = fromJS({
        webPush: {
          uploadedAssetData0: {
            id: 600,
            url: 'https://example.com/plain0.jpg',
          },
        },
      });
      
      // Manually set a plain JS object to simulate the bug scenario
      const plainJSState = stateWithPlainJS.setIn(['webPush', 'uploadedAssetData0'], {
        id: 600,
        url: 'https://example.com/plain0.jpg',
      });

      const selector = makeSelectUploadedAssetData(0);
      const result = selector(plainJSState);

      expect(result).toEqual({
        id: 600,
        url: 'https://example.com/plain0.jpg',
      });
    });
  });

  describe('Selector memoization', () => {
    it.concurrent('should return the same result for identical state (memoization test) - makeSelectWebPush', () => {
      const selector = makeSelectWebPush();
      const result1 = selector(mockStateWithWebPush);
      const result2 = selector(mockStateWithWebPush);

      expect(result1).toBe(result2);
    });

    it.concurrent('should return the same result for identical state (memoization test) - makeSelectCreateError', () => {
      const selector = makeSelectCreateError();
      const result1 = selector(mockStateWithWebPush);
      const result2 = selector(mockStateWithWebPush);

      expect(result1).toBe(result2);
    });

    it.concurrent('should return different results for different states', () => {
      const selector = makeSelectCreateTemplateInProgress();
      const result1 = selector(mockStateWithWebPush);
      const result2 = selector(mockStateWithPartialWebPush);

      expect(result1).toBe(true);
      expect(result2).toBe(true);
      // Even though both are true, they should be different instances if state changed
      const stateWithFalse = fromJS({
        webPush: {
          createTemplateInProgress: false,
        },
      });
      const result3 = selector(stateWithFalse);
      expect(result3).toBe(false);
      expect(result1).not.toBe(result3);
    });
  });

  describe('Edge cases', () => {
    it.concurrent('should handle undefined state gracefully', () => {
      const selector = makeSelectWebPush();
      const undefinedState = fromJS({});
      const result = selector(undefinedState);

      expect(result).toEqual({});
    });

    it.concurrent('should handle state with webPush as null', () => {
      const stateWithNullWebPush = fromJS({
        webPush: null,
      });

      const selector = makeSelectUploadedAssetData();
      const result = selector(stateWithNullWebPush);

      expect(result).toEqual({});
    });

    it.concurrent('should handle deeply nested state access', () => {
      const complexState = fromJS({
        level1: {
          level2: {
            webPush: mockWebPushState,
          },
        },
      });

      // This should return defaults since webPush is not at root level
      const selector = makeSelectCreateTemplateInProgress();
      const result = selector(complexState);

      expect(result).toBe(false);
    });

    it.concurrent('should handle state with webPush as empty Map', () => {
      const stateWithEmptyMap = fromJS({
        webPush: {},
      });

      const selector = makeSelectEditError();
      const result = selector(stateWithEmptyMap);

      expect(result).toBe('');
    });

    it.concurrent('should handle multiple selectors on same state', () => {
      const selectWebPush = makeSelectWebPush();
      const selectCreateError = makeSelectCreateError();
      const selectCreateInProgress = makeSelectCreateTemplateInProgress();
      const selectEditError = makeSelectEditError();
      const selectEditInProgress = makeSelectEditTemplateInProgress();
      const selectUploadedAsset = makeSelectUploadedAssetData();

      const webPushResult = selectWebPush(mockStateWithWebPush);
      const createErrorResult = selectCreateError(mockStateWithWebPush);
      const createInProgressResult = selectCreateInProgress(mockStateWithWebPush);
      const editErrorResult = selectEditError(mockStateWithWebPush);
      const editInProgressResult = selectEditInProgress(mockStateWithWebPush);
      const uploadedAssetResult = selectUploadedAsset(mockStateWithWebPush);

      expect(webPushResult).toEqual(mockWebPushState);
      expect(createErrorResult).toBe('Create error occurred');
      expect(createInProgressResult).toBe(true);
      expect(editErrorResult).toBe('Edit error occurred');
      expect(editInProgressResult).toBe(false);
      expect(uploadedAssetResult).toEqual({
        id: 100,
        url: 'https://example.com/image.jpg',
        fileName: 'test-image.jpg',
        fileSize: 1024000,
      });
    });

    it.concurrent('should handle state transitions correctly', () => {
      const selector = makeSelectCreateTemplateInProgress();

      // Initial state - not in progress
      const initialState = fromJS({
        webPush: {
          createTemplateInProgress: false,
        },
      });
      expect(selector(initialState)).toBe(false);

      // Request state - in progress
      const requestState = fromJS({
        webPush: {
          createTemplateInProgress: true,
        },
      });
      expect(selector(requestState)).toBe(true);

      // Success state - not in progress
      const successState = fromJS({
        webPush: {
          createTemplateInProgress: false,
        },
      });
      expect(selector(successState)).toBe(false);
    });
  });

  describe('Integration with reducer state', () => {
    it.concurrent('should correctly select state after CREATE_TEMPLATE_REQUEST', () => {
      const stateAfterRequest = fromJS({
        webPush: {
          createTemplateInProgress: true,
          createTemplateError: false,
          createTemplateErrorMessage: '',
        },
      });

      const selectInProgress = makeSelectCreateTemplateInProgress();
      const selectError = makeSelectCreateError();

      expect(selectInProgress(stateAfterRequest)).toBe(true);
      expect(selectError(stateAfterRequest)).toBe('');
    });

    it.concurrent('should correctly select state after CREATE_TEMPLATE_FAILURE', () => {
      const stateAfterFailure = fromJS({
        webPush: {
          createTemplateInProgress: false,
          createTemplateError: true,
          createTemplateErrorMessage: 'Network error occurred',
        },
      });

      const selectInProgress = makeSelectCreateTemplateInProgress();
      const selectError = makeSelectCreateError();

      expect(selectInProgress(stateAfterFailure)).toBe(false);
      expect(selectError(stateAfterFailure)).toBe('Network error occurred');
    });

    it.concurrent('should correctly select state after EDIT_TEMPLATE_REQUEST', () => {
      const stateAfterRequest = fromJS({
        webPush: {
          editTemplateInProgress: true,
          editTemplateError: false,
          editTemplateErrorMessage: '',
        },
      });

      const selectInProgress = makeSelectEditTemplateInProgress();
      const selectError = makeSelectEditError();

      expect(selectInProgress(stateAfterRequest)).toBe(true);
      expect(selectError(stateAfterRequest)).toBe('');
    });

    it.concurrent('should correctly select state after EDIT_TEMPLATE_FAILURE', () => {
      const stateAfterFailure = fromJS({
        webPush: {
          editTemplateInProgress: false,
          editTemplateError: true,
          editTemplateErrorMessage: 'Validation failed',
        },
      });

      const selectInProgress = makeSelectEditTemplateInProgress();
      const selectError = makeSelectEditError();

      expect(selectInProgress(stateAfterFailure)).toBe(false);
      expect(selectError(stateAfterFailure)).toBe('Validation failed');
    });

    it.concurrent('should correctly select state after UPLOAD_WEBPUSH_ASSET_SUCCESS', () => {
      const stateAfterUpload = fromJS({
        webPush: {
          uploadAssetSuccess: true,
          assetUploading: false,
          uploadedAssetData: {
            id: 500,
            url: 'https://example.com/uploaded.jpg',
            fileName: 'uploaded.jpg',
          },
        },
      });

      const selectUploadedAsset = makeSelectUploadedAssetData();
      const result = selectUploadedAsset(stateAfterUpload);

      expect(result).toEqual({
        id: 500,
        url: 'https://example.com/uploaded.jpg',
        fileName: 'uploaded.jpg',
      });
    });
  });

  describe('accountData selector (from templates state)', () => {
    // This tests the accountData selector logic used in mapStateToProps
    const createAccountDataSelector = () => {
      return (state) => {
        const templatesState = state.get('templates');
        if (!templatesState) {
          return {};
        }
        const templates = templatesState.toJS();
        return templates?.selectedWebPushAccount || {};
      };
    };

    it.concurrent('should select selectedWebPushAccount from templates state', () => {
      const mockTemplatesState = fromJS({
        selectedWebPushAccount: {
          id: 123,
          accountId: 123,
          name: 'Test WebPush Account',
          configs: {
            websiteLink: 'https://example.com',
          },
        },
      });

      const mockState = fromJS({
        templates: mockTemplatesState,
      });

      const selector = createAccountDataSelector();
      const result = selector(mockState);

      expect(result).toEqual({
        id: 123,
        accountId: 123,
        name: 'Test WebPush Account',
        configs: {
          websiteLink: 'https://example.com',
        },
      });
    });

    it.concurrent('should return empty object when templates state does not exist', () => {
      const mockState = fromJS({
        otherState: { value: 'test' },
      });

      const selector = createAccountDataSelector();
      const result = selector(mockState);

      expect(result).toEqual({});
    });

    it.concurrent('should return empty object when selectedWebPushAccount does not exist', () => {
      const mockTemplatesState = fromJS({
        weCrmAccounts: [],
        templates: [],
      });

      const mockState = fromJS({
        templates: mockTemplatesState,
      });

      const selector = createAccountDataSelector();
      const result = selector(mockState);

      expect(result).toEqual({});
    });

    it.concurrent('should handle selectedWebPushAccount with websiteLink in configs', () => {
      const mockTemplatesState = fromJS({
        selectedWebPushAccount: {
          id: 456,
          accountId: 456,
          name: 'Account with Website',
          configs: {
            websiteLink: 'https://test.com',
            otherConfig: 'value',
          },
        },
      });

      const mockState = fromJS({
        templates: mockTemplatesState,
      });

      const selector = createAccountDataSelector();
      const result = selector(mockState);

      expect(result.configs.websiteLink).toBe('https://test.com');
      expect(result.id).toBe(456);
    });

    it.concurrent('should handle selectedWebPushAccount without websiteLink', () => {
      const mockTemplatesState = fromJS({
        selectedWebPushAccount: {
          id: 789,
          accountId: 789,
          name: 'Account without Website',
          configs: {
            otherConfig: 'value',
          },
        },
      });

      const mockState = fromJS({
        templates: mockTemplatesState,
      });

      const selector = createAccountDataSelector();
      const result = selector(mockState);

      expect(result.configs.websiteLink).toBeUndefined();
      expect(result.id).toBe(789);
    });
  });
});

