Now easier to write tests for the app, and most pages are at least touched.
This commit is contained in:
		
							parent
							
								
									d095bc9ff4
								
							
						
					
					
						commit
						ecc264db8c
					
				
					 14 changed files with 124 additions and 89 deletions
				
			
		|  | @ -3,7 +3,7 @@ | ||||||
| </script> | </script> | ||||||
| <blockstart> | <blockstart> | ||||||
| <block style="--w: 100%; --value: 7"> | <block style="--w: 100%; --value: 7"> | ||||||
|   <h1>Zed's Trash Ass Games</h1> |   <h1 id="page-title">Zed's Trash Ass Games</h1> | ||||||
| 
 | 
 | ||||||
|   <p>More fun than a barrel full of monkeys with syphilus. |   <p>More fun than a barrel full of monkeys with syphilus. | ||||||
|   </p> |   </p> | ||||||
|  | @ -12,7 +12,7 @@ | ||||||
| <hr/> | <hr/> | ||||||
| <grid x-data="Games" style="--cols: 2"> | <grid x-data="Games" style="--cols: 2"> | ||||||
|   <template x-for="item in theData"> |   <template x-for="item in theData"> | ||||||
|     <shape style="--h: 200px"><a x-text="item.title" x-bind:href="item.url"></a></shape> |     <shape style="--h: 200px"><a data-testid="game-link" x-text="item.title" x-bind:href="item.url"></a></shape> | ||||||
|   </template> |   </template> | ||||||
| </grid> | </grid> | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ | ||||||
| 
 | 
 | ||||||
| <shape style="--w: 100%; --h: 300px"> | <shape style="--w: 100%; --h: 300px"> | ||||||
| <button><a id="streams" href="/stream/">View Past Streams</a></button> | <button><a id="streams" href="/stream/">View Past Streams</a></button> | ||||||
| <button><a href="/live/">Watch Today's Livestream</a></button> | <button><a id="live" href="/live/">Watch Today's Livestream</a></button> | ||||||
| </shape> | </shape> | ||||||
| 
 | 
 | ||||||
| <block data-testid="clickblock"> | <block data-testid="clickblock"> | ||||||
|  |  | ||||||
|  | @ -13,12 +13,12 @@ | ||||||
|   <header> |   <header> | ||||||
|     <blockstart style="background-color: var(--value0)"> |     <blockstart style="background-color: var(--value0)"> | ||||||
|     <block style="--value: 0; --text: 9" class="horizontal"> |     <block style="--value: 0; --text: 9" class="horizontal"> | ||||||
|       <a href="/">🏡</a> |       <a id="home" href="/">🏡</a> | ||||||
|       <a href="/live/">Live</a> |       <a id="live" href="/live/">Live</a> | ||||||
|       <a href="/stream/">Streams</a> |       <a id="stream" href="/stream/">Streams</a> | ||||||
|       <a href="/game/">Games</a> |       <a id="game" href="/game/">Games</a> | ||||||
|       <a href="/register/">Register</a> |       <a id="register" href="/register/">Register</a> | ||||||
|       <a href="/login/">Login</a> |       <a id="login" href="/login/">Login</a> | ||||||
|     </block> |     </block> | ||||||
|     </blockstart> |     </blockstart> | ||||||
|   </header> |   </header> | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| 
 | 
 | ||||||
| <blockstart> | <blockstart> | ||||||
|   <block style="--value: 7"> |   <block style="--value: 7"> | ||||||
|     <h1 id="streams-title">Past Streams</h1> |     <h1 id="page-title">Past Streams</h1> | ||||||
|     <p>This is where you can checkout information we dropped in a past stream. Did I post a link and you need to remember it? Did someone in chat mention something?  Here's where you find it.</p> |     <p>This is where you can checkout information we dropped in a past stream. Did I post a link and you need to remember it? Did someone in chat mention something?  Here's where you find it.</p> | ||||||
|   </block> |   </block> | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -13,12 +13,12 @@ | ||||||
|   <header> |   <header> | ||||||
|     <blockstart style="background-color: var(--value0)"> |     <blockstart style="background-color: var(--value0)"> | ||||||
|     <block style="--value: 0; --text: 9" class="horizontal"> |     <block style="--value: 0; --text: 9" class="horizontal"> | ||||||
|       <a href="/">🏡</a> |       <a id="home" href="/">🏡</a> | ||||||
|       <a href="/live/">Live</a> |       <a id="live" href="/live/">Live</a> | ||||||
|       <a href="/stream/">Streams</a> |       <a id="stream" href="/stream/">Streams</a> | ||||||
|       <a href="/game/">Games</a> |       <a id="game" href="/game/">Games</a> | ||||||
|       <a href="/register/">Register</a> |       <a id="register" href="/register/">Register</a> | ||||||
|       <a href="/login/">Login</a> |       <a id="login" href="/login/">Login</a> | ||||||
|     </block> |     </block> | ||||||
|     </blockstart> |     </blockstart> | ||||||
|   </header> |   </header> | ||||||
|  |  | ||||||
|  | @ -13,12 +13,12 @@ | ||||||
|   <header> |   <header> | ||||||
|     <blockstart style="background-color: var(--value0)"> |     <blockstart style="background-color: var(--value0)"> | ||||||
|     <block style="--value: 0; --text: 9" class="horizontal"> |     <block style="--value: 0; --text: 9" class="horizontal"> | ||||||
|       <a href="/">🏡</a> |       <a id="home" href="/">🏡</a> | ||||||
|       <a href="/live/">Live</a> |       <a id="live" href="/live/">Live</a> | ||||||
|       <a href="/stream/">Streams</a> |       <a id="stream" href="/stream/">Streams</a> | ||||||
|       <a href="/game/">Games</a> |       <a id="game" href="/game/">Games</a> | ||||||
|       <a href="/register/">Register</a> |       <a id="register" href="/register/">Register</a> | ||||||
|       <a href="/login/">Login</a> |       <a id="login" href="/login/">Login</a> | ||||||
|     </block> |     </block> | ||||||
|     </blockstart> |     </blockstart> | ||||||
|   </header> |   </header> | ||||||
|  |  | ||||||
|  | @ -13,12 +13,12 @@ | ||||||
|   <header> |   <header> | ||||||
|     <blockstart style="background-color: var(--value0)"> |     <blockstart style="background-color: var(--value0)"> | ||||||
|     <block style="--value: 0; --text: 9" class="horizontal"> |     <block style="--value: 0; --text: 9" class="horizontal"> | ||||||
|       <a href="/">🏡</a> |       <a id="home" href="/">🏡</a> | ||||||
|       <a href="/live/">Live</a> |       <a id="live" href="/live/">Live</a> | ||||||
|       <a href="/stream/">Streams</a> |       <a id="stream" href="/stream/">Streams</a> | ||||||
|       <a href="/game/">Games</a> |       <a id="game" href="/game/">Games</a> | ||||||
|       <a href="/register/">Register</a> |       <a id="register" href="/register/">Register</a> | ||||||
|       <a href="/login/">Login</a> |       <a id="login" href="/login/">Login</a> | ||||||
|     </block> |     </block> | ||||||
|     </blockstart> |     </blockstart> | ||||||
|   </header> |   </header> | ||||||
|  | @ -28,7 +28,7 @@ | ||||||
| </script> | </script> | ||||||
| <blockstart> | <blockstart> | ||||||
| <block style="--w: 100%; --value: 7"> | <block style="--w: 100%; --value: 7"> | ||||||
|   <h1>Zed's Trash Ass Games</h1> |   <h1 id="page-title">Zed's Trash Ass Games</h1> | ||||||
| 
 | 
 | ||||||
|   <p>More fun than a barrel full of monkeys with syphilus. |   <p>More fun than a barrel full of monkeys with syphilus. | ||||||
|   </p> |   </p> | ||||||
|  | @ -37,7 +37,7 @@ | ||||||
| <hr/> | <hr/> | ||||||
| <grid x-data="Games" style="--cols: 2"> | <grid x-data="Games" style="--cols: 2"> | ||||||
|   <template x-for="item in theData"> |   <template x-for="item in theData"> | ||||||
|     <shape style="--h: 200px"><a x-text="item.title" x-bind:href="item.url"></a></shape> |     <shape style="--h: 200px"><a data-testid="game-link" x-text="item.title" x-bind:href="item.url"></a></shape> | ||||||
|   </template> |   </template> | ||||||
| </grid> | </grid> | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -13,12 +13,12 @@ | ||||||
|   <header> |   <header> | ||||||
|     <blockstart style="background-color: var(--value0)"> |     <blockstart style="background-color: var(--value0)"> | ||||||
|     <block style="--value: 0; --text: 9" class="horizontal"> |     <block style="--value: 0; --text: 9" class="horizontal"> | ||||||
|       <a href="/">🏡</a> |       <a id="home" href="/">🏡</a> | ||||||
|       <a href="/live/">Live</a> |       <a id="live" href="/live/">Live</a> | ||||||
|       <a href="/stream/">Streams</a> |       <a id="stream" href="/stream/">Streams</a> | ||||||
|       <a href="/game/">Games</a> |       <a id="game" href="/game/">Games</a> | ||||||
|       <a href="/register/">Register</a> |       <a id="register" href="/register/">Register</a> | ||||||
|       <a href="/login/">Login</a> |       <a id="login" href="/login/">Login</a> | ||||||
|     </block> |     </block> | ||||||
|     </blockstart> |     </blockstart> | ||||||
|   </header> |   </header> | ||||||
|  | @ -28,7 +28,7 @@ | ||||||
| 
 | 
 | ||||||
| <shape style="--w: 100%; --h: 300px"> | <shape style="--w: 100%; --h: 300px"> | ||||||
| <button><a id="streams" href="/stream/">View Past Streams</a></button> | <button><a id="streams" href="/stream/">View Past Streams</a></button> | ||||||
| <button><a href="/live/">Watch Today's Livestream</a></button> | <button><a id="live" href="/live/">Watch Today's Livestream</a></button> | ||||||
| </shape> | </shape> | ||||||
| 
 | 
 | ||||||
| <block data-testid="clickblock"> | <block data-testid="clickblock"> | ||||||
|  |  | ||||||
|  | @ -13,12 +13,12 @@ | ||||||
|   <header> |   <header> | ||||||
|     <blockstart style="background-color: var(--value0)"> |     <blockstart style="background-color: var(--value0)"> | ||||||
|     <block style="--value: 0; --text: 9" class="horizontal"> |     <block style="--value: 0; --text: 9" class="horizontal"> | ||||||
|       <a href="/">🏡</a> |       <a id="home" href="/">🏡</a> | ||||||
|       <a href="/live/">Live</a> |       <a id="live" href="/live/">Live</a> | ||||||
|       <a href="/stream/">Streams</a> |       <a id="stream" href="/stream/">Streams</a> | ||||||
|       <a href="/game/">Games</a> |       <a id="game" href="/game/">Games</a> | ||||||
|       <a href="/register/">Register</a> |       <a id="register" href="/register/">Register</a> | ||||||
|       <a href="/login/">Login</a> |       <a id="login" href="/login/">Login</a> | ||||||
|     </block> |     </block> | ||||||
|     </blockstart> |     </blockstart> | ||||||
|   </header> |   </header> | ||||||
|  |  | ||||||
|  | @ -13,12 +13,12 @@ | ||||||
|   <header> |   <header> | ||||||
|     <blockstart style="background-color: var(--value0)"> |     <blockstart style="background-color: var(--value0)"> | ||||||
|     <block style="--value: 0; --text: 9" class="horizontal"> |     <block style="--value: 0; --text: 9" class="horizontal"> | ||||||
|       <a href="/">🏡</a> |       <a id="home" href="/">🏡</a> | ||||||
|       <a href="/live/">Live</a> |       <a id="live" href="/live/">Live</a> | ||||||
|       <a href="/stream/">Streams</a> |       <a id="stream" href="/stream/">Streams</a> | ||||||
|       <a href="/game/">Games</a> |       <a id="game" href="/game/">Games</a> | ||||||
|       <a href="/register/">Register</a> |       <a id="register" href="/register/">Register</a> | ||||||
|       <a href="/login/">Login</a> |       <a id="login" href="/login/">Login</a> | ||||||
|     </block> |     </block> | ||||||
|     </blockstart> |     </blockstart> | ||||||
|   </header> |   </header> | ||||||
|  |  | ||||||
|  | @ -13,12 +13,12 @@ | ||||||
|   <header> |   <header> | ||||||
|     <blockstart style="background-color: var(--value0)"> |     <blockstart style="background-color: var(--value0)"> | ||||||
|     <block style="--value: 0; --text: 9" class="horizontal"> |     <block style="--value: 0; --text: 9" class="horizontal"> | ||||||
|       <a href="/">🏡</a> |       <a id="home" href="/">🏡</a> | ||||||
|       <a href="/live/">Live</a> |       <a id="live" href="/live/">Live</a> | ||||||
|       <a href="/stream/">Streams</a> |       <a id="stream" href="/stream/">Streams</a> | ||||||
|       <a href="/game/">Games</a> |       <a id="game" href="/game/">Games</a> | ||||||
|       <a href="/register/">Register</a> |       <a id="register" href="/register/">Register</a> | ||||||
|       <a href="/login/">Login</a> |       <a id="login" href="/login/">Login</a> | ||||||
|     </block> |     </block> | ||||||
|     </blockstart> |     </blockstart> | ||||||
|   </header> |   </header> | ||||||
|  |  | ||||||
|  | @ -13,12 +13,12 @@ | ||||||
|   <header> |   <header> | ||||||
|     <blockstart style="background-color: var(--value0)"> |     <blockstart style="background-color: var(--value0)"> | ||||||
|     <block style="--value: 0; --text: 9" class="horizontal"> |     <block style="--value: 0; --text: 9" class="horizontal"> | ||||||
|       <a href="/">🏡</a> |       <a id="home" href="/">🏡</a> | ||||||
|       <a href="/live/">Live</a> |       <a id="live" href="/live/">Live</a> | ||||||
|       <a href="/stream/">Streams</a> |       <a id="stream" href="/stream/">Streams</a> | ||||||
|       <a href="/game/">Games</a> |       <a id="game" href="/game/">Games</a> | ||||||
|       <a href="/register/">Register</a> |       <a id="register" href="/register/">Register</a> | ||||||
|       <a href="/login/">Login</a> |       <a id="login" href="/login/">Login</a> | ||||||
|     </block> |     </block> | ||||||
|     </blockstart> |     </blockstart> | ||||||
|   </header> |   </header> | ||||||
|  | @ -30,7 +30,7 @@ | ||||||
| 
 | 
 | ||||||
| <blockstart> | <blockstart> | ||||||
|   <block style="--value: 7"> |   <block style="--value: 7"> | ||||||
|     <h1 id="streams-title">Past Streams</h1> |     <h1 id="page-title">Past Streams</h1> | ||||||
|     <p>This is where you can checkout information we dropped in a past stream. Did I post a link and you need to remember it? Did someone in chat mention something?  Here's where you find it.</p> |     <p>This is where you can checkout information we dropped in a past stream. Did I post a link and you need to remember it? Did someone in chat mention something?  Here's where you find it.</p> | ||||||
|   </block> |   </block> | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ package tests | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|   "testing" |   "testing" | ||||||
|   "github.com/stretchr/testify/assert" |   "github.com/stretchr/testify/require" | ||||||
|   browser "github.com/chromedp/chromedp" |   browser "github.com/chromedp/chromedp" | ||||||
|   "zedshaw.games/webapp/data" |   "zedshaw.games/webapp/data" | ||||||
|   sq "github.com/Masterminds/squirrel" |   sq "github.com/Masterminds/squirrel" | ||||||
|  | @ -14,12 +14,12 @@ func deleteTestUser(username string) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestLogin(t *testing.T) { | func TestLogin(t *testing.T) { | ||||||
|   assert := assert.New(t) |   require := require.New(t) | ||||||
|   deleteTestUser("testerzed") |   deleteTestUser("testerzed") | ||||||
| 
 | 
 | ||||||
|   ctx, cancel := Setup(5); defer cancel() |   ctx, cancel := Setup(5); defer cancel() | ||||||
| 
 | 
 | ||||||
|   Run(assert, ctx, |   Run(require, ctx, | ||||||
|   browser.Navigate(`http://127.0.0.1:5002/register/`), |   browser.Navigate(`http://127.0.0.1:5002/register/`), | ||||||
|   browser.WaitVisible(`body > footer`), |   browser.WaitVisible(`body > footer`), | ||||||
|   browser.WaitVisible(`[data-testid="register-index-page"]`), |   browser.WaitVisible(`[data-testid="register-index-page"]`), | ||||||
|  | @ -30,7 +30,7 @@ func TestLogin(t *testing.T) { | ||||||
|   browser.WaitVisible(`body > footer`), |   browser.WaitVisible(`body > footer`), | ||||||
|   browser.WaitVisible(`[data-testid="login-index-page"]`)) |   browser.WaitVisible(`[data-testid="login-index-page"]`)) | ||||||
| 
 | 
 | ||||||
|   Run(assert, ctx, |   Run(require, ctx, | ||||||
|   browser.Navigate(`http://127.0.0.1:5002/login/`), |   browser.Navigate(`http://127.0.0.1:5002/login/`), | ||||||
|   browser.WaitVisible(`body > footer`), |   browser.WaitVisible(`body > footer`), | ||||||
|   browser.WaitVisible(`[data-testid="login-index-page"]`), |   browser.WaitVisible(`[data-testid="login-index-page"]`), | ||||||
|  | @ -44,29 +44,41 @@ func TestLogin(t *testing.T) { | ||||||
|   deleteTestUser("testerzed") |   deleteTestUser("testerzed") | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestStreamPage(t *testing.T) { | 
 | ||||||
|   assert := assert.New(t) | func TestStreamsPage(t *testing.T) { | ||||||
|  |   require := require.New(t) | ||||||
| 
 | 
 | ||||||
|   ctx, cancel := Setup(2); |   ctx, cancel := Setup(2); | ||||||
|   defer cancel(); |   defer cancel(); | ||||||
| 
 | 
 | ||||||
|   var title string |   GoTo(require, ctx, "/", `#streams`) | ||||||
|  |   ClickOn(require, ctx, `#streams`) | ||||||
|  |   WaitFor(require, ctx, `[data-testid="stream-index-page"]`) | ||||||
|  |   ExpectText(require, ctx, `#page-title`, "Past Streams") | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
|   err := browser.Run(ctx, | func TestLivePage(t *testing.T) { | ||||||
|   browser.Navigate(`http://127.0.0.1:5002`), |   require := require.New(t) | ||||||
|   browser.WaitVisible(`body > footer`), |  | ||||||
|   browser.WaitVisible(`#streams`),) |  | ||||||
|   assert.NoError(err) |  | ||||||
| 
 | 
 | ||||||
|   ClickOn(assert, ctx, `#streams`) |   ctx, cancel := Setup(2); | ||||||
|  |   defer cancel(); | ||||||
| 
 | 
 | ||||||
|   err = browser.Run(ctx, browser.WaitVisible(`#streams-title`)) |   GoTo(require, ctx, "/", `#live`) | ||||||
|   assert.NoError(err) |   ClickOn(require, ctx, `#live`) | ||||||
|  |   WaitFor(require, ctx, `[data-testid="live-index-page"]`) | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
|   err = browser.Run(ctx, browser.Text(`#streams-title`, &title)) | func TestGamePage(t *testing.T) { | ||||||
|   assert.NoError(err) |   require := require.New(t) | ||||||
| 
 | 
 | ||||||
|   assert.Equal(title, "Past Streams") |   ctx, cancel := Setup(2); | ||||||
|  |   defer cancel(); | ||||||
|  | 
 | ||||||
|  |   GoTo(require, ctx, "/", `#game`) | ||||||
|  |   ClickOn(require, ctx, `#game`) | ||||||
|  |   WaitFor(require, ctx, `[data-testid="game-index-page"]`) | ||||||
|  |   ExpectText(require, ctx, `#page-title`, "Zed's Trash Ass Games") | ||||||
|  |   ClickOn(require, ctx, `[data-testid="game-link"]`) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestMain(m *testing.M) { | func TestMain(m *testing.M) { | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ import ( | ||||||
|     "log" |     "log" | ||||||
|     "time" |     "time" | ||||||
|     "runtime" |     "runtime" | ||||||
|     "github.com/stretchr/testify/assert" |     "github.com/stretchr/testify/require" | ||||||
|     browser "github.com/chromedp/chromedp" |     browser "github.com/chromedp/chromedp" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | @ -22,16 +22,39 @@ func Setup(timeout time.Duration) (context.Context, context.CancelFunc) { | ||||||
|     return ctx, cancel |     return ctx, cancel | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func ClickOn(assert *assert.Assertions, ctx context.Context, id string) { | func ClickOn(require *require.Assertions, ctx context.Context, id string) { | ||||||
|     err := browser.Run(ctx, browser.WaitVisible(`#streams`),) |     err := browser.Run(ctx, browser.WaitVisible(id),) | ||||||
| 	assert.NoError(err) | 	require.NoError(err) | ||||||
| 
 | 
 | ||||||
|     resp, err := browser.RunResponse(ctx, browser.Click(id, browser.ByID)) |     resp, err := browser.RunResponse(ctx,  | ||||||
|     assert.Equal(resp.Status, int64(200)) | 		browser.WaitVisible(id), | ||||||
|     assert.NoError(err) | 		browser.Click(id)) | ||||||
|  | 
 | ||||||
|  |     require.NoError(err) | ||||||
|  |     require.Equal(resp.Status, int64(200)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func Run(assert *assert.Assertions, ctx context.Context, actions ...browser.Action) { | func GoTo(require *require.Assertions, ctx context.Context, path string, expect string) { | ||||||
|  |   err := browser.Run(ctx, | ||||||
|  |   browser.Navigate(`http://127.0.0.1:5002`), | ||||||
|  |   browser.WaitVisible(`body > footer`), | ||||||
|  |   browser.WaitVisible(expect)) | ||||||
|  |   require.NoError(err) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func WaitFor(require *require.Assertions, ctx context.Context, expect string) { | ||||||
|  |   err := browser.Run(ctx, browser.WaitVisible(expect)) | ||||||
|  |   require.NoError(err) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func ExpectText(require *require.Assertions, ctx context.Context, target string, expect string) { | ||||||
|  | 	var extracted string | ||||||
|  | 	err := browser.Run(ctx, browser.Text(target, &extracted)) | ||||||
|  | 	require.NoError(err) | ||||||
|  | 	require.Equal(expect, extracted) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func Run(require *require.Assertions, ctx context.Context, actions ...browser.Action) { | ||||||
|     err := browser.Run(ctx, actions...) |     err := browser.Run(ctx, actions...) | ||||||
|     assert.NoError(err) |     require.NoError(err) | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Zed A. Shaw
						Zed A. Shaw