1
1
describe ( "Cards" , function ( ) {
2
- var reveal ;
2
+ beforeEach ( async function ( ) {
3
+ await XloadFixtures ( [ 'cards/cardsFixture.html' ] ) ;
4
+ } ) ;
3
5
4
- beforeEach ( function ( ) {
5
- loadFixtures ( 'cards/cardsFixture.html' ) ;
6
+ afterEach ( function ( ) {
7
+ XunloadFixtures ( ) ;
6
8
} ) ;
7
9
8
10
describe ( "reveal cards" , function ( ) {
9
- var revealCard ;
11
+ let revealCard ;
10
12
11
13
beforeEach ( function ( ) {
12
- revealCard = $ ( '.card.reveal' ) ;
14
+ revealCard = document . querySelector ( '.card.reveal' ) ;
13
15
} ) ;
14
16
15
17
it ( "should have a hidden card-reveal" , function ( done ) {
16
- var revealDiv = revealCard . find ( '.card-reveal' ) ;
17
- var activator = revealCard . find ( '.activator' ) ;
18
+ let revealDiv = revealCard . querySelector ( '.card-reveal' ) ;
19
+ let activator = revealCard . querySelector ( '.activator' ) ;
18
20
19
21
expect ( revealDiv ) . toBeHidden ( 'reveal div should be hidden initially' ) ;
20
22
21
23
setTimeout ( function ( ) {
22
- activator . click ( ) ;
24
+ click ( activator ) ;
23
25
24
26
setTimeout ( function ( ) {
25
27
expect ( revealDiv ) . toBeVisible ( 'reveal did not appear after activator was clicked.' ) ;
26
28
27
29
// Check revealDiv covers reveal card.
28
- expect ( revealDiv . outerWidth ( ) ) . toEqual ( revealCard . outerWidth ( ) , 'activator was not as wide as reveal card.' ) ;
29
- expect ( revealDiv . outerHeight ( ) ) . toEqual ( revealCard . outerHeight ( ) , 'activator was not as high as reveal card.' ) ;
30
- expect ( revealDiv . offset ( ) . top ) . toEqual ( revealCard . offset ( ) . top , 'activator was not as in the same y as reveal card.' ) ;
31
- expect ( revealDiv . offset ( ) . left ) . toEqual ( revealCard . offset ( ) . left , 'activator was not as in the same x as reveal card.' ) ;
30
+ let revealDivPositions = revealDiv . getBoundingClientRect ( ) ;
31
+ let revealCardPositions = revealCard . getBoundingClientRect ( ) ;
32
+ expect ( revealDivPositions . width ) . toEqual ( revealCardPositions . width , 'activator was not as wide as reveal card.' ) ;
33
+ expect ( revealDivPositions . height ) . toEqual ( revealCardPositions . height , 'activator was not as high as reveal card.' ) ;
34
+ expect ( revealDivPositions . top ) . toEqual ( revealCardPositions . top , 'activator was not as in the same y as reveal card.' ) ;
35
+ expect ( revealDivPositions . left ) . toEqual ( revealCardPositions . left , 'activator was not as in the same x as reveal card.' ) ;
32
36
33
37
done ( ) ;
34
38
} , 400 ) ;
@@ -38,64 +42,78 @@ describe( "Cards", function () {
38
42
} ) ;
39
43
40
44
describe ( "image cards" , function ( ) {
41
- var imageCard ;
45
+ let imageCard ;
42
46
43
47
beforeEach ( function ( ) {
44
- imageCard = $ ( '.card.image' ) ;
48
+ imageCard = document . querySelector ( '.card.image' ) ;
45
49
} ) ;
46
50
47
51
it ( "should have an image that fills to full width of card" , function ( ) {
48
- var image = imageCard . find ( '.card-image > img' ) ;
52
+ let image = imageCard . querySelector ( '.card-image > img' ) ;
53
+ let imagePositions = image . getBoundingClientRect ( ) ;
54
+ let imageCardPositions = imageCard . getBoundingClientRect ( ) ;
49
55
50
- expect ( image . outerWidth ( ) ) . toEqual ( imageCard . outerWidth ( ) , 'image does not fill width of card' ) ;
51
- expect ( image . offset ( ) . top ) . toEqual ( imageCard . offset ( ) . top , 'image was not as in the same y as card.' ) ;
56
+ expect ( imagePositions . width ) . toEqual ( imageCardPositions . width , 'image does not fill width of card' ) ;
57
+ expect ( imagePositions . top ) . toEqual ( imageCardPositions . top , 'image was not as in the same y as card.' ) ;
52
58
} ) ;
53
59
} ) ;
54
60
55
61
56
62
describe ( "sized cards" , function ( ) {
57
- var small , medium , large ;
63
+ let small , medium , large ;
58
64
59
65
beforeEach ( function ( ) {
60
- small = $ ( '.card.small' ) ;
61
- medium = $ ( '.card.medium' ) ;
62
- large = $ ( '.card.large' ) ;
66
+ small = document . querySelector ( '.card.small' ) ;
67
+ medium = document . querySelector ( '.card.medium' ) ;
68
+ large = document . querySelector ( '.card.large' ) ;
63
69
} ) ;
64
70
65
71
it ( "should have small card dimensions" , function ( ) {
66
- var cardImage = small . find ( '.card-image' ) ;
67
- var cardContent = small . find ( '.card-content' ) ;
68
- var cardAction = small . find ( '.card-action' ) ;
69
-
70
- expect ( small . outerHeight ( ) ) . toEqual ( 300 , 'small card should be 300px high' ) ;
71
- expect ( cardImage . outerHeight ( ) ) . toBeLessThan ( 181 , 'small image should be <= 180px or 60% high' ) ;
72
- expect ( cardContent . outerHeight ( ) ) . toBeLessThan ( 121 , 'small content should be <= 120px or 40% high' ) ;
73
- expect ( cardAction . offset ( ) . top + cardAction . outerHeight ( ) )
74
- . toEqual ( small . offset ( ) . top + small . outerHeight ( ) , 'small action should be at bottom of card' ) ;
72
+ let cardImage = small . querySelector ( '.card-image' ) ;
73
+ let cardContent = small . querySelector ( '.card-content' ) ;
74
+ let cardAction = small . querySelector ( '.card-action' ) ;
75
+ let smallRect = small . getBoundingClientRect ( ) ;
76
+ let cardImageRect = cardImage . getBoundingClientRect ( ) ;
77
+ let cardContentRect = cardContent . getBoundingClientRect ( ) ;
78
+ let cardActionRect = cardAction . getBoundingClientRect ( ) ;
79
+
80
+ expect ( smallRect . height ) . toEqual ( 300 , 'small card should be 300px high' ) ;
81
+ expect ( cardImageRect . height ) . toBeLessThan ( 181 , 'small image should be <= 180px or 60% high' ) ;
82
+ expect ( cardContentRect . height ) . toBeLessThan ( 121 , 'small content should be <= 120px or 40% high' ) ;
83
+ expect ( cardActionRect . top + cardActionRect . height )
84
+ . toEqual ( smallRect . top + smallRect . height , 'small action should be at bottom of card' ) ;
75
85
} ) ;
76
86
77
87
it ( "should have medium card dimensions" , function ( ) {
78
- var cardImage = medium . find ( '.card-image' ) ;
79
- var cardContent = medium . find ( '.card-content' ) ;
80
- var cardAction = medium . find ( '.card-action' ) ;
81
-
82
- expect ( medium . outerHeight ( ) ) . toEqual ( 400 , 'medium card should be 400px high' ) ;
83
- expect ( cardImage . outerHeight ( ) ) . toBeLessThan ( 241 , 'medium image should be <= 240 or 60% high' ) ;
84
- expect ( cardContent . outerHeight ( ) ) . toBeLessThan ( 161 , 'medium content should be <= 160px or 40% high' ) ;
85
- expect ( cardAction . offset ( ) . top + cardAction . outerHeight ( ) )
86
- . toEqual ( medium . offset ( ) . top + medium . outerHeight ( ) , 'medium action should be at bottom of card' ) ;
88
+ let cardImage = medium . querySelector ( '.card-image' ) ;
89
+ let cardContent = medium . querySelector ( '.card-content' ) ;
90
+ let cardAction = medium . querySelector ( '.card-action' ) ;
91
+ let mediumRect = medium . getBoundingClientRect ( ) ;
92
+ let cardImageRect = cardImage . getBoundingClientRect ( ) ;
93
+ let cardContentRect = cardContent . getBoundingClientRect ( ) ;
94
+ let cardActionRect = cardAction . getBoundingClientRect ( ) ;
95
+
96
+ expect ( mediumRect . height ) . toEqual ( 400 , 'medium card should be 400px high' ) ;
97
+ expect ( cardImageRect . height ) . toBeLessThan ( 241 , 'medium image should be <= 240 or 60% high' ) ;
98
+ expect ( cardContentRect . height ) . toBeLessThan ( 161 , 'medium content should be <= 160px or 40% high' ) ;
99
+ expect ( cardActionRect . top + cardActionRect . height )
100
+ . toEqual ( mediumRect . top + mediumRect . height , 'medium action should be at bottom of card' ) ;
87
101
} ) ;
88
102
89
103
it ( "should have large card dimensions" , function ( ) {
90
- var cardImage = large . find ( '.card-image' ) ;
91
- var cardContent = large . find ( '.card-content' ) ;
92
- var cardAction = large . find ( '.card-action' ) ;
93
-
94
- expect ( large . outerHeight ( ) ) . toEqual ( 500 , 'large card should be 500px high' ) ;
95
- expect ( cardImage . outerHeight ( ) ) . toBeLessThan ( 301 , 'large image should be <= 300 or 60% high' ) ;
96
- expect ( cardContent . outerHeight ( ) ) . toBeLessThan ( 201 , 'large content should be <= 200 or 40% high' ) ;
97
- expect ( cardAction . offset ( ) . top + cardAction . outerHeight ( ) )
98
- . toEqual ( large . offset ( ) . top + large . outerHeight ( ) , 'large action should be at bottom of card' ) ;
104
+ let cardImage = large . querySelector ( '.card-image' ) ;
105
+ let cardContent = large . querySelector ( '.card-content' ) ;
106
+ let cardAction = large . querySelector ( '.card-action' ) ;
107
+ let largeRect = large . getBoundingClientRect ( ) ;
108
+ let cardImageRect = cardImage . getBoundingClientRect ( ) ;
109
+ let cardContentRect = cardContent . getBoundingClientRect ( ) ;
110
+ let cardActionRect = cardAction . getBoundingClientRect ( ) ;
111
+
112
+ expect ( largeRect . height ) . toEqual ( 500 , 'large card should be 500px high' ) ;
113
+ expect ( cardImageRect . height ) . toBeLessThan ( 301 , 'large image should be <= 300 or 60% high' ) ;
114
+ expect ( cardContentRect . height ) . toBeLessThan ( 201 , 'large content should be <= 200 or 40% high' ) ;
115
+ expect ( cardActionRect . top + cardActionRect . height )
116
+ . toEqual ( largeRect . top + largeRect . height , 'large action should be at bottom of card' ) ;
99
117
} ) ;
100
118
} ) ;
101
119
0 commit comments