1- import Stacks from "./stacks" ;
21import $ from "jquery" ;
2+ import Stacks from "./stacks" ;
33import { jest } from "@jest/globals" ;
44
55describe ( "pat-stacks" , function ( ) {
@@ -11,90 +11,82 @@ describe("pat-stacks", function () {
1111 $ ( "#lab" ) . remove ( ) ;
1212 } ) ;
1313
14- describe ( "The init method" , function ( ) {
15- it ( "Returns the jQuery-wrapped DOM node" , function ( ) {
16- var $el = $ ( '<div class="pat-stacks"></div>' ) ;
17- var pattern = new Stacks ( $el ) ;
18- expect ( pattern . init ( $el ) ) . toBe ( $el ) ;
19- } ) ;
20- } ) ;
21-
22- describe ( "_base_URL" , function ( ) {
23- it ( "URL without fragment" , function ( ) {
24- var $el = $ ( '<div class="pat-stacks"></div>' ) ;
25- var pattern = new Stacks ( $el ) ;
14+ describe ( "1 - _base_URL" , function ( ) {
15+ it ( "1.1 - URL without fragment" , function ( ) {
16+ const $el = $ ( '<div class="pat-stacks"></div>' ) ;
17+ const pattern = new Stacks ( $el ) ;
2618 pattern . document = { URL : document . URL } ;
2719 pattern . document . URL = "http://www.example.com/folder/file.png" ;
2820 expect ( pattern . _base_URL ( ) ) . toBe ( "http://www.example.com/folder/file.png" ) ;
2921 } ) ;
3022
31- it ( "URL with fragment" , function ( ) {
32- var $el = $ ( '<div class="pat-stacks"></div>' ) ;
33- var pattern = new Stacks ( $el ) ;
23+ it ( "1.2 - URL with fragment" , function ( ) {
24+ const $el = $ ( '<div class="pat-stacks"></div>' ) ;
25+ const pattern = new Stacks ( $el ) ;
3426 pattern . document = { URL : document . URL } ;
3527 pattern . document . URL = "http://www.example.com/folder/file.png#fragment" ;
3628 expect ( pattern . _base_URL ( ) ) . toBe ( "http://www.example.com/folder/file.png" ) ;
3729 } ) ;
3830 } ) ;
3931
40- describe ( "_currentFragment" , function ( ) {
41- it ( " without fragment" , function ( ) {
42- var $el = $ ( '<div class="pat-stacks"></div>' ) ;
43- var pattern = new Stacks ( $el ) ;
32+ describe ( "2 - _currentFragment" , function ( ) {
33+ it ( "2.1 - without fragment" , function ( ) {
34+ const $el = $ ( '<div class="pat-stacks"></div>' ) ;
35+ const pattern = new Stacks ( $el ) ;
4436 pattern . document = { URL : document . URL } ;
4537 pattern . document . URL = "http://www.example.com/folder/file.png" ;
4638 expect ( pattern . _currentFragment ( ) ) . toBeNull ( ) ;
4739 } ) ;
4840
49- it ( "URL with fragment" , function ( ) {
50- var $el = $ ( '<div class="pat-stacks"></div>' ) ;
51- var pattern = new Stacks ( $el ) ;
41+ it ( "2.2 - URL with fragment" , function ( ) {
42+ const $el = $ ( '<div class="pat-stacks"></div>' ) ;
43+ const pattern = new Stacks ( $el ) ;
5244 pattern . document = { URL : document . URL } ;
5345 pattern . document . URL = "http://www.example.com/folder/file.png#fragment" ;
5446 expect ( pattern . _currentFragment ( ) ) . toBe ( "fragment" ) ;
5547 } ) ;
5648 } ) ;
5749
58- describe ( "The _onClick method" , function ( ) {
50+ describe ( "3 - The _onClick method" , function ( ) {
5951 beforeEach ( function ( ) {
6052 $ ( "#lab" ) . html (
6153 "<a id='l1' href='#s1'>1</a><a id='l2' href='#s2'>2</a>" +
6254 "<article class='pat-stacks' id='stack'><section id='s1'></section><section id='s2'></section></article>"
6355 ) ;
6456 } ) ;
6557
66- it ( "gets triggered when you click on an external link" , function ( ) {
67- var e = { currentTarget : { href : "http://other.domain#s1" } } ;
68- var pattern = new Stacks ( $ ( ".pat-stacks" ) ) ;
69- var spy_update = jest . spyOn ( pattern , "_updateAnchors" ) ;
58+ it ( "3.1 - gets triggered when you click on an external link" , function ( ) {
59+ const e = { currentTarget : { href : "http://other.domain#s1" } } ;
60+ const pattern = new Stacks ( $ ( ".pat-stacks" ) ) ;
61+ const spy_update = jest . spyOn ( pattern , "_updateAnchors" ) ;
7062 pattern . _onClick ( e ) ;
7163 expect ( spy_update ) . not . toHaveBeenCalled ( ) ;
7264 } ) ;
7365
74- it ( "gets triggered when you click on a link without fragment" , function ( ) {
75- var pattern = new Stacks ( $ ( ".pat-stacks" ) ) ;
66+ it ( "3.2 - gets triggered when you click on a link without fragment" , function ( ) {
67+ const pattern = new Stacks ( $ ( ".pat-stacks" ) ) ;
7668 pattern . document = { URL : document . URL } ;
7769 pattern . document . URL = "http://www.example.com" ;
78- var e = { currentTarget : { href : "http://www.example.com" } } ;
79- var spy_update = jest . spyOn ( pattern , "_updateAnchors" ) ;
70+ const e = { currentTarget : { href : "http://www.example.com" } } ;
71+ const spy_update = jest . spyOn ( pattern , "_updateAnchors" ) ;
8072 pattern . _onClick ( e ) ;
8173 expect ( spy_update ) . not . toHaveBeenCalled ( ) ;
8274 } ) ;
8375
84- it ( "gets tirggered when you click on a non-stack link" , function ( ) {
85- var pattern = new Stacks ( $ ( ".pat-stacks" ) ) ;
76+ it ( "3.3 - gets tirggered when you click on a non-stack link" , function ( ) {
77+ const pattern = new Stacks ( $ ( ".pat-stacks" ) ) ;
8678 pattern . document = { URL : document . URL } ;
8779 pattern . document . URL = "http://www.example.com" ;
88- var e = {
80+ const e = {
8981 currentTarget : { href : "http://www.example.com#other" } ,
9082 } ;
91- var spy_update = jest . spyOn ( pattern , "_updateAnchors" ) ;
83+ const spy_update = jest . spyOn ( pattern , "_updateAnchors" ) ;
9284 pattern . _onClick ( e ) ;
9385 expect ( spy_update ) . not . toHaveBeenCalled ( ) ;
9486 } ) ;
9587
96- it ( "gets called when you click on the stack link" , function ( ) {
97- var pattern = new Stacks ( $ ( ".pat-stacks" ) ) ;
88+ it ( "3.4 - gets called when you click on the stack link" , function ( ) {
89+ const pattern = new Stacks ( $ ( ".pat-stacks" ) ) ;
9890 pattern . document = { URL : document . URL } ;
9991 pattern . document . URL = "http://www.example.com" ;
10092 const e_mock = {
@@ -110,13 +102,13 @@ describe("pat-stacks", function () {
110102 expect ( spy_switch ) . toHaveBeenCalled ( ) ;
111103 } ) ;
112104
113- it ( "triggers a pat-update event, which other patterns can listen for" , function ( ) {
114- var $el = $ ( ".pat-stacks" ) ;
115- var pattern = new Stacks ( $el ) ;
105+ it ( "3.5 - triggers a pat-update event, which other patterns can listen for" , function ( ) {
106+ const $el = $ ( ".pat-stacks" ) ;
107+ const pattern = new Stacks ( $el ) ;
116108 pattern . document = { URL : document . URL } ;
117109 pattern . document . URL = "http://www.example.com" ;
118- var spy_trigger = jest . spyOn ( $ . fn , "trigger" ) ;
119- var e = {
110+ const spy_trigger = jest . spyOn ( $ . fn , "trigger" ) ;
111+ const e = {
120112 target : $el ,
121113 type : "click" ,
122114 preventDefault : function ( ) { } ,
@@ -130,25 +122,25 @@ describe("pat-stacks", function () {
130122 } ) ;
131123 } ) ;
132124
133- describe ( "The _updateAnchors method" , function ( ) {
125+ describe ( "4 - The _updateAnchors method" , function ( ) {
134126 beforeEach ( function ( ) {
135127 $ ( "#lab" ) . html (
136128 "<a id='l1' href='#s1'>1</a><a id='l2' href='#s2'>2</a>" +
137129 "<article class='pat-stacks' id='stack'><section id='s1'></section><section id='s2'></section></article>"
138130 ) ;
139131 } ) ;
140132
141- it ( "adds a selected class" , function ( ) {
142- var $container = $ ( "#stack" ) ;
143- var pattern = new Stacks ( $container ) ;
133+ it ( "4.1 - adds a selected class" , function ( ) {
134+ const $container = $ ( "#stack" ) ;
135+ const pattern = new Stacks ( $container ) ;
144136 pattern . _updateAnchors ( "s1" ) ;
145137 expect ( $ ( "#l1" ) . hasClass ( "current" ) ) . toBe ( true ) ;
146138 expect ( $ ( "#l2" ) . hasClass ( "current" ) ) . toBe ( false ) ;
147139 } ) ;
148140
149- it ( "removes a selected class" , function ( ) {
150- var $container = $ ( "#stack" ) ;
151- var pattern = new Stacks ( $container ) ;
141+ it ( "4.2 - removes a selected class" , function ( ) {
142+ const $container = $ ( "#stack" ) ;
143+ const pattern = new Stacks ( $container ) ;
152144 $ ( "#l1" ) . addClass ( "selected" ) ;
153145 pattern . _updateAnchors ( "s2" ) ;
154146 expect ( $ ( "#l1" ) . hasClass ( "current" ) ) . toBe ( false ) ;
0 commit comments