customize-header.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* global wp, sinon */
  2. jQuery( function() {
  3. QUnit.module('Custom Header: ChoiceList', {
  4. beforeEach: function() {
  5. wp.customize.HeaderTool.currentHeader = new wp.customize.HeaderTool.ImageModel();
  6. this.apiStub = sinon.stub(wp.customize, 'get').returns('foo');
  7. this.choiceList = new wp.customize.HeaderTool.ChoiceList();
  8. },
  9. afterEach: function() {
  10. this.apiStub.restore();
  11. }
  12. });
  13. QUnit.test('should parse _wpCustomizeHeader.uploads into itself', function( assert ) {
  14. assert.equal(this.choiceList.length, 4);
  15. });
  16. QUnit.test('should sort by newest first', function( assert ) {
  17. assert.equal(this.choiceList.at(2).get('header').attachment_id, 1);
  18. assert.equal(this.choiceList.first().get('header').attachment_id, 3);
  19. });
  20. QUnit.module('Custom Header: DefaultsList', {
  21. beforeEach: function() {
  22. wp.customize.HeaderTool.currentHeader = new wp.customize.HeaderTool.ImageModel();
  23. this.apiStub = sinon.stub(wp.customize, 'get').returns('foo');
  24. this.choiceList = new wp.customize.HeaderTool.DefaultsList();
  25. },
  26. afterEach: function() {
  27. this.apiStub.restore();
  28. }
  29. });
  30. QUnit.test('it should parse _wpCustomizeHeader.defaults into itself', function( assert ) {
  31. assert.equal(this.choiceList.length, 4);
  32. });
  33. QUnit.test('it parses the default image names', function( assert ) {
  34. assert.equal(this.choiceList.first().get('header').defaultName, 'circle');
  35. assert.equal(this.choiceList.at(2).get('header').defaultName, 'star');
  36. });
  37. QUnit.module('Custom Header: HeaderImage shouldBeCropped()', {
  38. beforeEach: function() {
  39. wp.customize.HeaderTool.currentHeader = new wp.customize.HeaderTool.ImageModel();
  40. this.model = new wp.customize.HeaderTool.ImageModel();
  41. this.model.set({
  42. themeWidth: 1000,
  43. themeHeight: 200
  44. });
  45. }
  46. });
  47. QUnit.test('should not be cropped when the theme does not support flex width or height and the image has the same dimensions of the theme image', function( assert ) {
  48. this.model.set({
  49. themeFlexWidth: false,
  50. themeFlexHeight: false,
  51. imageWidth: 1000,
  52. imageHeight: 200
  53. });
  54. assert.equal(this.model.shouldBeCropped(), false);
  55. });
  56. QUnit.test('should be cropped when the image has the same dimensions of the theme image', function( assert ) {
  57. this.model.set({
  58. themeFlexWidth: false,
  59. themeFlexHeight: false,
  60. imageWidth: 2000,
  61. imageHeight: 400
  62. });
  63. assert.equal(this.model.shouldBeCropped(), true);
  64. });
  65. QUnit.test('should not be cropped when the theme only supports flex width and the image has the same height as the theme image', function( assert ) {
  66. this.model.set({
  67. themeFlexWidth: true,
  68. themeFlexHeight: false,
  69. imageWidth: 4000,
  70. imageHeight: 200
  71. });
  72. assert.equal(this.model.shouldBeCropped(), false);
  73. });
  74. QUnit.test('should not be cropped when the theme only supports flex height and the image has the same width as the theme image', function( assert ) {
  75. this.model.set({
  76. themeFlexWidth: false,
  77. themeFlexHeight: true,
  78. imageWidth: 1000,
  79. imageHeight: 600
  80. });
  81. assert.equal(this.model.shouldBeCropped(), false);
  82. });
  83. QUnit.test('should not be cropped when the theme supports flex height AND width', function( assert ) {
  84. this.model.set({
  85. themeFlexWidth: true,
  86. themeFlexHeight: true,
  87. imageWidth: 10000,
  88. imageHeight: 8600
  89. });
  90. assert.equal(this.model.shouldBeCropped(), false);
  91. });
  92. QUnit.test('should not be cropped when the image width is smaller than or equal to theme width', function( assert ) {
  93. this.model.set({
  94. themeFlexWidth: false,
  95. themeFlexHeight: false,
  96. imageWidth: 1000,
  97. imageHeight: 100
  98. });
  99. assert.equal(this.model.shouldBeCropped(), false);
  100. });
  101. QUnit.test('should not be cropped when the image width is smaller than or equal to theme width, theme supports flex height and width', function( assert ) {
  102. this.model.set({
  103. themeFlexWidth: true,
  104. themeFlexHeight: true,
  105. imageWidth: 900,
  106. imageHeight: 100
  107. });
  108. assert.equal(this.model.shouldBeCropped(), false);
  109. });
  110. });