@@ -4,50 +4,57 @@ import { toast } from "react-toastify";
44
55describe ( "ToastManager" , ( ) => {
66 // -----------------------------------------------------------------------------------------
7- // #region error
7+ // #region dismiss
88 // -----------------------------------------------------------------------------------------
99
10- describe ( "error " , ( ) => {
11- test ( "when toast created with toastId, returns given toastId " , ( ) => {
10+ describe ( "dismiss " , ( ) => {
11+ test ( "when executed, calls dismiss " , ( ) => {
1212 // Arrange
13- const expected = faker . random . number ( 99 ) ;
14- const toastContent = faker . random . word ( ) ;
15- const toastOptions = { toastId : expected } ;
13+ const dismissMethodSpy = jest . spyOn ( toast , "dismiss" ) ;
14+ const testId = faker . random . number ( 99 ) ;
1615
1716 // Act
18- const toastId = ToastManager . error ( toastContent , toastOptions ) ;
17+ ToastManager . dismiss ( testId ) ;
1918
2019 // Assert
21- expect ( toastId ) . toBe ( expected ) ;
20+ expect ( dismissMethodSpy ) . toHaveBeenCalledWith ( testId ) ;
2221 } ) ;
22+ } ) ;
2323
24- test ( "when toast created without toastId, returns new toastId" , ( ) => {
24+ // #endregion dismiss
25+
26+ // -----------------------------------------------------------------------------------------
27+ // #region dismissAll
28+ // -----------------------------------------------------------------------------------------
29+
30+ describe ( "dismissAll" , ( ) => {
31+ test ( "when executed, calls dismiss" , ( ) => {
2532 // Arrange
26- const toastContent = faker . random . word ( ) ;
33+ const dismissMethodSpy = jest . spyOn ( toast , "dismiss" ) ;
2734
2835 // Act
29- const toastId = ToastManager . error ( toastContent ) ;
36+ ToastManager . dismissAll ( ) ;
3037
3138 // Assert
32- expect ( toastId ) . not . toBeNil ( ) ;
39+ expect ( dismissMethodSpy ) . toHaveBeenCalled ( ) ;
3340 } ) ;
3441 } ) ;
3542
36- // #endregion error
43+ // #endregion dismissAll
3744
3845 // -----------------------------------------------------------------------------------------
39- // #region info
46+ // #region error
4047 // -----------------------------------------------------------------------------------------
4148
42- describe ( "info " , ( ) => {
49+ describe ( "error " , ( ) => {
4350 test ( "when toast created with toastId, returns given toastId" , ( ) => {
4451 // Arrange
4552 const expected = faker . random . number ( 99 ) ;
4653 const toastContent = faker . random . word ( ) ;
4754 const toastOptions = { toastId : expected } ;
4855
4956 // Act
50- const toastId = ToastManager . info ( toastContent , toastOptions ) ;
57+ const toastId = ToastManager . error ( toastContent , toastOptions ) ;
5158
5259 // Assert
5360 expect ( toastId ) . toBe ( expected ) ;
@@ -58,28 +65,28 @@ describe("ToastManager", () => {
5865 const toastContent = faker . random . word ( ) ;
5966
6067 // Act
61- const toastId = ToastManager . info ( toastContent ) ;
68+ const toastId = ToastManager . error ( toastContent ) ;
6269
6370 // Assert
6471 expect ( toastId ) . not . toBeNil ( ) ;
6572 } ) ;
6673 } ) ;
6774
68- // #endregion info
75+ // #endregion error
6976
7077 // -----------------------------------------------------------------------------------------
71- // #region success
78+ // #region info
7279 // -----------------------------------------------------------------------------------------
7380
74- describe ( "success " , ( ) => {
81+ describe ( "info " , ( ) => {
7582 test ( "when toast created with toastId, returns given toastId" , ( ) => {
7683 // Arrange
7784 const expected = faker . random . number ( 99 ) ;
7885 const toastContent = faker . random . word ( ) ;
7986 const toastOptions = { toastId : expected } ;
8087
8188 // Act
82- const toastId = ToastManager . success ( toastContent , toastOptions ) ;
89+ const toastId = ToastManager . info ( toastContent , toastOptions ) ;
8390
8491 // Assert
8592 expect ( toastId ) . toBe ( expected ) ;
@@ -90,28 +97,28 @@ describe("ToastManager", () => {
9097 const toastContent = faker . random . word ( ) ;
9198
9299 // Act
93- const toastId = ToastManager . success ( toastContent ) ;
100+ const toastId = ToastManager . info ( toastContent ) ;
94101
95102 // Assert
96103 expect ( toastId ) . not . toBeNil ( ) ;
97104 } ) ;
98105 } ) ;
99106
100- // #endregion success
107+ // #endregion info
101108
102109 // -----------------------------------------------------------------------------------------
103- // #region warn
110+ // #region success
104111 // -----------------------------------------------------------------------------------------
105112
106- describe ( "warn " , ( ) => {
113+ describe ( "success " , ( ) => {
107114 test ( "when toast created with toastId, returns given toastId" , ( ) => {
108115 // Arrange
109116 const expected = faker . random . number ( 99 ) ;
110117 const toastContent = faker . random . word ( ) ;
111118 const toastOptions = { toastId : expected } ;
112119
113120 // Act
114- const toastId = ToastManager . warn ( toastContent , toastOptions ) ;
121+ const toastId = ToastManager . success ( toastContent , toastOptions ) ;
115122
116123 // Assert
117124 expect ( toastId ) . toBe ( expected ) ;
@@ -122,72 +129,65 @@ describe("ToastManager", () => {
122129 const toastContent = faker . random . word ( ) ;
123130
124131 // Act
125- const toastId = ToastManager . warn ( toastContent ) ;
132+ const toastId = ToastManager . success ( toastContent ) ;
126133
127134 // Assert
128135 expect ( toastId ) . not . toBeNil ( ) ;
129136 } ) ;
130137 } ) ;
131138
132- // #endregion warn
139+ // #endregion success
133140
134141 // -----------------------------------------------------------------------------------------
135- // #region dismiss
142+ // #region update
136143 // -----------------------------------------------------------------------------------------
137144
138- describe ( "dismiss " , ( ) => {
139- test ( "when executed, calls dismiss " , ( ) => {
145+ describe ( "update " , ( ) => {
146+ test ( "when executed, calls update " , ( ) => {
140147 // Arrange
141- const dismissMethodSpy = jest . spyOn ( toast , "dismiss" ) ;
148+ const newContent = faker . random . words ( ) ;
142149 const testId = faker . random . number ( 99 ) ;
150+ const updateMethodSpy = jest . spyOn ( ToastManager , "update" ) ;
143151
144152 // Act
145- ToastManager . dismiss ( testId ) ;
153+ ToastManager . update ( testId , newContent ) ;
146154
147155 // Assert
148- expect ( dismissMethodSpy ) . toHaveBeenCalledWith ( testId ) ;
156+ expect ( updateMethodSpy ) . toHaveBeenCalledWith ( testId , newContent ) ;
149157 } ) ;
150158 } ) ;
151159
152- // #endregion dismiss
160+ // #endregion update
153161
154162 // -----------------------------------------------------------------------------------------
155- // #region dismissAll
163+ // #region warn
156164 // -----------------------------------------------------------------------------------------
157165
158- describe ( "dismissAll " , ( ) => {
159- test ( "when executed, calls dismiss " , ( ) => {
166+ describe ( "warn " , ( ) => {
167+ test ( "when toast created with toastId, returns given toastId " , ( ) => {
160168 // Arrange
161- const dismissMethodSpy = jest . spyOn ( toast , "dismiss" ) ;
169+ const expected = faker . random . number ( 99 ) ;
170+ const toastContent = faker . random . word ( ) ;
171+ const toastOptions = { toastId : expected } ;
162172
163173 // Act
164- ToastManager . dismissAll ( ) ;
174+ const toastId = ToastManager . warn ( toastContent , toastOptions ) ;
165175
166176 // Assert
167- expect ( dismissMethodSpy ) . toHaveBeenCalled ( ) ;
177+ expect ( toastId ) . toBe ( expected ) ;
168178 } ) ;
169- } ) ;
170-
171- // #endregion dismissAll
172-
173- // -----------------------------------------------------------------------------------------
174- // #region update
175- // -----------------------------------------------------------------------------------------
176179
177- describe ( "update" , ( ) => {
178- test ( "when executed, calls update" , ( ) => {
180+ test ( "when toast created without toastId, returns new toastId" , ( ) => {
179181 // Arrange
180- const newContent = faker . random . words ( ) ;
181- const testId = faker . random . number ( 99 ) ;
182- const updateMethodSpy = jest . spyOn ( ToastManager , "update" ) ;
182+ const toastContent = faker . random . word ( ) ;
183183
184184 // Act
185- ToastManager . update ( testId , newContent ) ;
185+ const toastId = ToastManager . warn ( toastContent ) ;
186186
187187 // Assert
188- expect ( updateMethodSpy ) . toHaveBeenCalledWith ( testId , newContent ) ;
188+ expect ( toastId ) . not . toBeNil ( ) ;
189189 } ) ;
190190 } ) ;
191191
192- // #endregion update
192+ // #endregion warn
193193} ) ;
0 commit comments