import { getContent } from '../commonMethods';

describe('commonMethods.js', () => {
  describe('getContent', () => {
    it('should return three spaces for null input', () => {
      const result = getContent(null);
      expect(result).toBe('   ');
    });

    it('should return three spaces for undefined input', () => {
      const result = getContent(undefined);
      expect(result).toBe('   ');
    });

    it('should return three spaces for empty object', () => {
      const result = getContent({});
      expect(result).toBe('   ');
    });

    it('should return three spaces for object without versions', () => {
      const result = getContent({ someOtherProperty: 'value' });
      expect(result).toBe('   ');
    });

    it('should return three spaces for object with empty versions', () => {
      const result = getContent({ versions: {} });
      expect(result).toBe('   ');
    });

    it('should return three spaces for object with versions but no base', () => {
      const result = getContent({ versions: { otherVersion: {} } });
      expect(result).toBe('   ');
    });

    it('should return three spaces for object with empty base', () => {
      const result = getContent({ versions: { base: {} } });
      expect(result).toBe('   ');
    });

    it('should return three spaces for object with base but no platform data', () => {
      const result = getContent({ versions: { base: { otherPlatform: {} } } });
      expect(result).toBe('   ');
    });

    it('should return three spaces for object with empty ANDROID and IOS', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: {},
            IOS: {},
          },
        },
      });
      expect(result).toBe('   ');
    });

    it('should return only Android title when only Android title is present', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: { title: 'Android Title' },
            IOS: {},
          },
        },
      });
      expect(result).toBe('Android Title   ');
    });

    it('should return only Android message when only Android message is present', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: { message: 'Android Message' },
            IOS: {},
          },
        },
      });
      expect(result).toBe(' Android Message  ');
    });

    it('should return only iOS title when only iOS title is present', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: {},
            IOS: { title: 'iOS Title' },
          },
        },
      });
      expect(result).toBe('  iOS Title ');
    });

    it('should return only iOS message when only iOS message is present', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: {},
            IOS: { message: 'iOS Message' },
          },
        },
      });
      expect(result).toBe('   iOS Message');
    });

    it('should return Android title and message when both are present', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: {
              title: 'Android Title',
              message: 'Android Message',
            },
            IOS: {},
          },
        },
      });
      expect(result).toBe('Android Title Android Message  ');
    });

    it('should return iOS title and message when both are present', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: {},
            IOS: {
              title: 'iOS Title',
              message: 'iOS Message',
            },
          },
        },
      });
      expect(result).toBe('  iOS Title iOS Message');
    });

    it('should return Android title and iOS message when only those are present', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: { title: 'Android Title' },
            IOS: { message: 'iOS Message' },
          },
        },
      });
      expect(result).toBe('Android Title   iOS Message');
    });

    it('should return Android message and iOS title when only those are present', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: { message: 'Android Message' },
            IOS: { title: 'iOS Title' },
          },
        },
      });
      expect(result).toBe(' Android Message iOS Title ');
    });

    it('should return all content when all fields are present', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: {
              title: 'Android Title',
              message: 'Android Message',
            },
            IOS: {
              title: 'iOS Title',
              message: 'iOS Message',
            },
          },
        },
      });
      expect(result).toBe('Android Title Android Message iOS Title iOS Message');
    });

    it('should handle null values in Android object', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: {
              title: null,
              message: null,
            },
            IOS: {},
          },
        },
      });
      expect(result).toBe('   ');
    });

    it('should handle null values in iOS object', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: {},
            IOS: {
              title: null,
              message: null,
            },
          },
        },
      });
      expect(result).toBe('   ');
    });

    it('should handle undefined values in Android object', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: {
              title: undefined,
              message: undefined,
            },
            IOS: {},
          },
        },
      });
      expect(result).toBe('   ');
    });

    it('should handle undefined values in iOS object', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: {},
            IOS: {
              title: undefined,
              message: undefined,
            },
          },
        },
      });
      expect(result).toBe('   ');
    });

    it('should handle mixed null and defined values', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: {
              title: 'Android Title',
              message: null,
            },
            IOS: {
              title: null,
              message: 'iOS Message',
            },
          },
        },
      });
      expect(result).toBe('Android Title   iOS Message');
    });

    it('should handle empty string values', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: {
              title: '',
              message: '',
            },
            IOS: {
              title: '',
              message: '',
            },
          },
        },
      });
      expect(result).toBe('   ');
    });

    it('should handle whitespace-only values', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: {
              title: '   ',
              message: '  ',
            },
            IOS: {
              title: ' ',
              message: '   ',
            },
          },
        },
      });
      expect(result).toBe('            ');
    });

    it('should handle special characters in content', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: {
              title: 'Android & Title',
              message: 'Android "Message"',
            },
            IOS: {
              title: 'iOS <Title>',
              message: 'iOS \'Message\'',
            },
          },
        },
      });
      expect(result).toBe('Android & Title Android "Message" iOS <Title> iOS \'Message\'');
    });

    it('should handle numbers as content', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: {
              title: 123,
              message: 456,
            },
            IOS: {
              title: 789,
              message: 0,
            },
          },
        },
      });
      expect(result).toBe('123 456 789 ');
    });

    it('should handle boolean values as content', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: {
              title: true,
              message: false,
            },
            IOS: {
              title: false,
              message: true,
            },
          },
        },
      });
      expect(result).toBe('true   true');
    });

    it('should handle object with only Android platform', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: {
              title: 'Android Only Title',
              message: 'Android Only Message',
            },
          },
        },
      });
      expect(result).toBe('Android Only Title Android Only Message  ');
    });

    it('should handle object with only iOS platform', () => {
      const result = getContent({
        versions: {
          base: {
            IOS: {
              title: 'iOS Only Title',
              message: 'iOS Only Message',
            },
          },
        },
      });
      expect(result).toBe('  iOS Only Title iOS Only Message');
    });

    it('should handle nested object structure with additional properties', () => {
      const result = getContent({
        versions: {
          base: {
            ANDROID: {
              title: 'Android Title',
              message: 'Android Message',
              extraProperty: 'should be ignored',
            },
            IOS: {
              title: 'iOS Title',
              message: 'iOS Message',
              anotherProperty: 'should also be ignored',
            },
            OTHER_PLATFORM: {
              title: 'Other Title',
              message: 'Other Message',
            },
          },
          otherVersion: {
            ANDROID: { title: 'Other Version Title' },
          },
        },
        otherProperty: 'should be ignored',
      });
      expect(result).toBe('Android Title Android Message iOS Title iOS Message');
    });
  });
});
