/*
 * Copyright (C) 2019 Robert Bosch GmbH Copyright (C) 2019 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
 */

import { MediaQueryBuilder } from './media-query-builder';

describe('MediaQueryBuilder', () => {
  it('should created instance', () => {
    const a = MediaQueryBuilder.is();
    expect(a).toBeTruthy();
    expect(MediaQueryBuilder.is()).not.toBe(a);
  });

  describe('with single literals', () => {
    it('should create expression', () => {
      expect(MediaQueryBuilder.is().expression('a').query).toEqual('(a)');
    });

    it('should create min-width expression', () => {
      expect(MediaQueryBuilder.is().ge(42).query).toEqual('(min-width: 42px)');
    });

    it('should create exclusive min-width expression', () => {
      expect(MediaQueryBuilder.is().gt(42).query).toEqual('(min-width: 42.1px)');
    });

    it('should create max-width expression', () => {
      expect(MediaQueryBuilder.is().le(42).query).toEqual('(max-width: 42px)');
    });

    it('should create exclusive max-width expression', () => {
      expect(MediaQueryBuilder.is().lt(42).query).toEqual('(max-width: 41.9px)');
    });

    it('should create landscape expression', () => {
      expect(MediaQueryBuilder.is().landscape.query).toEqual('(orientation: landscape)');
    });

    it('should create portrait expression', () => {
      expect(MediaQueryBuilder.is().portrait.query).toEqual('(orientation: portrait)');
    });
  });

  describe('with logic', () => {
    it('should create and expression', () => {
      expect(MediaQueryBuilder.is().expression('a').and.expression('b').query).toEqual('(a) and (b)');
    });

    it('should create or expression', () => {
      expect(MediaQueryBuilder.is().expression('a').or.expression('b').query).toEqual('(a) or (b)');
    });

    it('should not allow incomplete expression', () => {
      expect(Object.keys(MediaQueryBuilder.is().expression('a').or)).not.toContain('query');
      expect(Object.keys(MediaQueryBuilder.is().expression('a').and)).not.toContain('query');
    });
  });

  describe('with nested expressions', () => {
    it('should create nested expressions', () => {
      expect(
        MediaQueryBuilder.is().expression(MediaQueryBuilder.is().landscape.and.ge(42).query).or.portrait.query
      ).toEqual('((orientation: landscape) and (min-width: 42px)) or (orientation: portrait)');
    });
  });
});
