columns.spec.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import {
  2. setMobile,
  3. setTablet,
  4. setDesktop,
  5. setWidescreen,
  6. setFullHD,
  7. } from "../utils";
  8. const SCREENS = [
  9. ["-mobile", setMobile],
  10. ["-tablet", setTablet],
  11. ["-desktop", setDesktop],
  12. ["-widescreen", setWidescreen],
  13. ["-fullhd", setFullHD],
  14. ];
  15. const WIDTHS = [
  16. ["three-quarters", 0.75],
  17. ["two-thirds", 0.6666],
  18. ["half", 0.5],
  19. ["one-third", 0.3333],
  20. ["one-quarter", 0.25],
  21. ["one-fifth", 0.2],
  22. ["two-fifths", 0.4],
  23. ["three-fifths", 0.6],
  24. ["four-fifths", 0.8],
  25. ];
  26. describe("Grid/Columns", () => {
  27. beforeEach(() => {
  28. cy.visit("http://127.0.0.1:4000/cyp/grid/columns/");
  29. setDesktop();
  30. });
  31. it("has Columns", () => {
  32. cy.get(".columns").should("exist");
  33. });
  34. it("has correct Columns", () => {
  35. cy.get("#columns").then(($) => {
  36. const cs = window.getComputedStyle($[0]);
  37. expect(cs.display).to.equal("flex");
  38. expect(cs.marginBottom).to.equal("12px");
  39. expect(cs.marginLeft).to.equal("-12px");
  40. expect(cs.marginRight).to.equal("-12px");
  41. expect(cs.marginTop).to.equal("-12px");
  42. });
  43. });
  44. it("has correct last Columns", () => {
  45. cy.get("#columns-last").then(($) => {
  46. const cs = window.getComputedStyle($[0]);
  47. expect(cs.marginBottom).to.equal("-12px");
  48. });
  49. });
  50. it("has correct centered Columns", () => {
  51. cy.get("#columns-centered").then(($) => {
  52. const cs = window.getComputedStyle($[0]);
  53. expect(cs.justifyContent).to.equal("center");
  54. });
  55. });
  56. it("has correct gapless Columns", () => {
  57. cy.get("#columns-gapless").then(($) => {
  58. const cs = window.getComputedStyle($[0]);
  59. expect(cs.marginBottom).to.equal("24px");
  60. expect(cs.marginLeft).to.equal("0px");
  61. expect(cs.marginRight).to.equal("0px");
  62. expect(cs.marginTop).to.equal("0px");
  63. });
  64. cy.get("#columns-gapless .column").then(($) => {
  65. const cs = window.getComputedStyle($[0]);
  66. expect(cs.margin).to.equal("0px");
  67. expect(cs.padding).to.equal("0px");
  68. });
  69. });
  70. it("has correct gapless last Columns", () => {
  71. cy.get("#columns-gapless-last").then(($) => {
  72. const cs = window.getComputedStyle($[0]);
  73. expect(cs.marginBottom).to.equal("0px");
  74. });
  75. });
  76. it("has correct multiline Columns", () => {
  77. cy.get("#columns-multiline").then(($) => {
  78. const cs = window.getComputedStyle($[0]);
  79. expect(cs.flexWrap).to.equal("wrap");
  80. });
  81. });
  82. it("has correct vcentered Columns", () => {
  83. cy.get("#columns-vcentered").then(($) => {
  84. const cs = window.getComputedStyle($[0]);
  85. expect(cs.alignItems).to.equal("center");
  86. });
  87. });
  88. // Responsiveness
  89. it("has correct mobile Columns", () => {
  90. setMobile();
  91. cy.get("#columns-mobile").then(($) => {
  92. const cs = window.getComputedStyle($[0]);
  93. expect(cs.display).to.equal("flex");
  94. });
  95. setDesktop();
  96. cy.get("#columns-mobile").then(($) => {
  97. const cs = window.getComputedStyle($[0]);
  98. expect(cs.display).to.equal("flex");
  99. });
  100. });
  101. it("has correct desktop Columns", () => {
  102. setMobile();
  103. cy.get("#columns-desktop").then(($) => {
  104. const cs = window.getComputedStyle($[0]);
  105. expect(cs.display).to.equal("block");
  106. });
  107. setTablet();
  108. cy.get("#columns-desktop").then(($) => {
  109. const cs = window.getComputedStyle($[0]);
  110. expect(cs.display).to.equal("block");
  111. });
  112. setDesktop();
  113. cy.get("#columns-desktop").then(($) => {
  114. const cs = window.getComputedStyle($[0]);
  115. expect(cs.display).to.equal("flex");
  116. });
  117. });
  118. });
  119. describe("Grid/Column", () => {
  120. beforeEach(() => {
  121. cy.visit("http://127.0.0.1:4000/cyp/grid/columns/");
  122. setTablet();
  123. });
  124. it("has a Column", () => {
  125. cy.get(".column").should("exist");
  126. });
  127. it("has a correct Column", () => {
  128. cy.get("#columns .column").then(($) => {
  129. const cs = window.getComputedStyle($[0]);
  130. expect(cs.display).to.equal("block");
  131. expect(cs.flexBasis).to.equal("0px");
  132. expect(cs.flexGrow).to.equal("1");
  133. expect(cs.flexShrink).to.equal("1");
  134. expect(cs.padding).to.equal("12px");
  135. });
  136. });
  137. it("has a correct Column sizes", () => {
  138. SCREENS.forEach((screen) => {
  139. const suffix = screen[0];
  140. const fn = screen[1];
  141. fn();
  142. cy.get(`#columns-special${suffix}`).then(($) => {
  143. const columnsWidth = $[0].clientWidth;
  144. const $full = $.find(`.column.is-full${suffix}`);
  145. const csfull = window.getComputedStyle($full[0]);
  146. const actualFullWidth = csfull.width.substring(
  147. 0,
  148. csfull.width.length - 2
  149. );
  150. expect(csfull.flexBasis).to.equal("auto");
  151. expect(csfull.flexGrow).to.equal("0");
  152. expect(csfull.flexShrink).to.equal("0");
  153. expect(`${Math.round(actualFullWidth)}px`).to.equal(
  154. `${Math.round(columnsWidth)}px`
  155. );
  156. const $narrow = $.find(`.column.is-narrow${suffix}`);
  157. const csnarrow = window.getComputedStyle($narrow[0]);
  158. expect(csnarrow.flexBasis).to.equal("auto");
  159. expect(csnarrow.flexGrow).to.equal("0");
  160. expect(csnarrow.flexShrink).to.equal("0");
  161. WIDTHS.forEach((width) => {
  162. const name = width[0];
  163. const factor = width[1];
  164. const $1 = $.find(`.column.is-${name}${suffix}`);
  165. const cs1 = window.getComputedStyle($1[0]);
  166. const actualWidth = cs1.width.substring(0, cs1.width.length - 2);
  167. expect(cs1.flexBasis).to.equal("auto");
  168. expect(cs1.flexGrow).to.equal("0");
  169. expect(cs1.flexShrink).to.equal("0");
  170. expect(`${Math.round(actualWidth)}px`).to.equal(
  171. `${Math.round(factor * columnsWidth)}px`
  172. );
  173. const $2 = $.find(`.column.is-offset-${name}${suffix}`);
  174. const cs2 = window.getComputedStyle($2[0]);
  175. const actualMarginLeft = cs2.marginLeft.substring(
  176. 0,
  177. cs2.marginLeft.length - 2
  178. );
  179. expect(`${Math.round(actualMarginLeft)}px`).to.equal(
  180. `${Math.round(factor * columnsWidth)}px`
  181. );
  182. for (let i = 1; i <= 12; i++) {
  183. const $3 = $.find(`.column.is-${i}${suffix}`);
  184. const cs3 = window.getComputedStyle($3[0]);
  185. const actualWidth = cs3.width.substring(0, cs3.width.length - 2);
  186. expect(cs3.flexBasis).to.equal("auto");
  187. expect(cs3.flexGrow).to.equal("0");
  188. expect(cs3.flexShrink).to.equal("0");
  189. expect(`${Math.round(actualWidth)}px`).to.equal(
  190. `${Math.round((i / 12) * columnsWidth)}px`
  191. );
  192. const $4 = $.find(`.column.is-offset-${i}${suffix}`);
  193. const cs4 = window.getComputedStyle($4[0]);
  194. const actualMarginLeft = cs4.marginLeft.substring(
  195. 0,
  196. cs4.marginLeft.length - 2
  197. );
  198. expect(`${Math.round(actualMarginLeft)}px`).to.equal(
  199. `${Math.round((i / 12) * columnsWidth)}px`
  200. );
  201. }
  202. });
  203. });
  204. });
  205. });
  206. });