Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
This should fix the tests issue in relation to upgrading to Phoenix 1.6.2
  • Loading branch information
ajmeese7 committed Oct 23, 2021
1 parent d041332 commit c5ff63a
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 26 deletions.
27 changes: 12 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ If you run the following command in your terminal:
mix phx.new -v
```

You should see:
You should see something similar to the following:

```sh
Phoenix v1.6.2
Phoenix installer v1.6.0
```

If you have an earlier version,
Expand Down Expand Up @@ -288,9 +288,6 @@ in your web browser.

![welcome-to-phoenix](https://user-images.githubusercontent.com/194400/76152198-ae210200-60b4-11ea-956f-68935daddfe0.png)

😱 If you are having problems with the server hanging, try
[this](#problems-with-dependencies)

> 🏁 Snapshot of code at the end of Step 1:
> [`#c48488`](https://github.com/dwyl/phoenix-liveview-counter-tutorial/tree/c4848853beb2df3327663270d1018a128bbcf0fa)
Expand Down Expand Up @@ -582,14 +579,14 @@ will now _fail_:
Compiling 1 file (.ex)
..

1) test disconnected and connected render (LiveViewCounterWeb.PageLiveTest)
test/live_view_counter_web/live/page_live_test.exs:6
1) test GET / (LiveViewCounterWeb.PageControllerTest)
test/live_view_counter_web/controllers/page_controller_test.exs:4
Assertion with =~ failed
code: assert disconnected_html =~ "Welcome to Phoenix!"
code: assert html_response(conn, 200) =~ "Welcome to Phoenix!"
left: "<html lang=\"en\"><head><meta charset=\"utf-8\"/><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/><meta charset=\"UTF-8\" content=\"IHQLHHISBjZlWTskHjAmHBETKCFnGWUloYSOGMkDRhaSvIBtkycvQNUF\" csrf-param=\"_csrf_token\" method-param=\"_method\" name=\"csrf-token\"/><title data-suffix=\" · Phoenix Framework\">LiveViewCounter · Phoenix Framework</title><link phx-track-static=\"phx-track-static\" rel=\"stylesheet\" href=\"/css/app.css\"/><script defer=\"defer\" phx-track-static=\"phx-track-static\" type=\"text/javascript\" src=\"/js/app.js\"></script></head><body><header><section class=\"container\"><nav role=\"navigation\"><ul><li><a href=\"https://hexdocs.pm/phoenix/overview.html\">Get Started</a></li><li><a href=\"/dashboard\">LiveDashboard</a></li></ul></nav><a href=\"https://phoenixframework.org/\" class=\"phx-logo\"><img src=\"/images/phoenix.png\" alt=\"Phoenix Framework Logo\"/></a></section></header><div data-phx-main=\"true\" data-phx-session=\"SFMyNTY" data-phx-view=\"Counter\" id=\"phx-FhQ9AJF6KACJPAEm\"><div><h1>The count is: 0</h1><button phx-click=\"dec\">-</button><button phx-click=\"inc\">+</button></div></div></body></html>"
right: "Welcome to Phoenix!"
stacktrace:
test/live_view_counter_web/live/page_live_test.exs:8: (test)
test/live_view_counter_web/controllers/page_controller_test.exs:6: (test)


Finished in 0.1 seconds
Expand All @@ -600,12 +597,11 @@ This just tells us that the test is looking for the string
`"Welcome to Phoenix!"` in the page and did not find it.

To fix the broken test, open the
`test/live_view_counter_web/live/page_live_test.exs`
file and locate the lines:
`test/live_view_counter_web/controllers/page_controller_test.exs`
file and locate the line:

```elixir
assert disconnected_html =~ "Welcome to Phoenix!"
assert render(page_live) =~ "Welcome to Phoenix!"
assert html_response(conn, 200) =~ "Welcome to Phoenix!"
```

Update the string from `"Welcome to Phoenix!"`
Expand All @@ -614,7 +610,8 @@ e.g:
`"The count is"`

> 🏁 The `page_live_test.exs` file should now look like this:
> [`test/live_view_counter_web/live/page_live_test.exs#L8-L9`](https://github.com/dwyl/phoenix-liveview-counter-tutorial/blob/8b12dd70f6b1693a4f39a1cb53f8fc1b4ced33f1/test/live_view_counter_web/live/page_live_test.exs#L8-L9)
> [`test/live_view_counter_web/live/page_live_test.exs#L8-L9`](https://github.com/dwyl/phoenix-liveview-counter-tutorial/blob/master/test/live_view_counter_web/controllers/page_controller_test.exs#L6)

Confirm the tests pass again by running:

Expand Down Expand Up @@ -956,7 +953,7 @@ We hope you enjoyed learning with us! <br />
If you found this useful, please ⭐️and _share_ the GitHub repo
so we know you like it!

<br /><br /><br />
<br />

## Future Steps

Expand Down
157 changes: 157 additions & 0 deletions assets/vendor/topbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/**
* @license MIT
* topbar 1.0.0, 2021-01-06
* http://buunguyen.github.io/topbar
* Copyright (c) 2021 Buu Nguyen
*/
(function (window, document) {
"use strict";

// https://gist.github.com/paulirish/1579671
(function () {
var lastTime = 0;
var vendors = ["ms", "moz", "webkit", "o"];
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame =
window[vendors[x] + "RequestAnimationFrame"];
window.cancelAnimationFrame =
window[vendors[x] + "CancelAnimationFrame"] ||
window[vendors[x] + "CancelRequestAnimationFrame"];
}
if (!window.requestAnimationFrame)
window.requestAnimationFrame = function (callback, element) {
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function () {
callback(currTime + timeToCall);
}, timeToCall);
lastTime = currTime + timeToCall;
return id;
};
if (!window.cancelAnimationFrame)
window.cancelAnimationFrame = function (id) {
clearTimeout(id);
};
})();

var canvas,
progressTimerId,
fadeTimerId,
currentProgress,
showing,
addEvent = function (elem, type, handler) {
if (elem.addEventListener) elem.addEventListener(type, handler, false);
else if (elem.attachEvent) elem.attachEvent("on" + type, handler);
else elem["on" + type] = handler;
},
options = {
autoRun: true,
barThickness: 3,
barColors: {
0: "rgba(26, 188, 156, .9)",
".25": "rgba(52, 152, 219, .9)",
".50": "rgba(241, 196, 15, .9)",
".75": "rgba(230, 126, 34, .9)",
"1.0": "rgba(211, 84, 0, .9)",
},
shadowBlur: 10,
shadowColor: "rgba(0, 0, 0, .6)",
className: null,
},
repaint = function () {
canvas.width = window.innerWidth;
canvas.height = options.barThickness * 5; // need space for shadow

var ctx = canvas.getContext("2d");
ctx.shadowBlur = options.shadowBlur;
ctx.shadowColor = options.shadowColor;

var lineGradient = ctx.createLinearGradient(0, 0, canvas.width, 0);
for (var stop in options.barColors)
lineGradient.addColorStop(stop, options.barColors[stop]);
ctx.lineWidth = options.barThickness;
ctx.beginPath();
ctx.moveTo(0, options.barThickness / 2);
ctx.lineTo(
Math.ceil(currentProgress * canvas.width),
options.barThickness / 2
);
ctx.strokeStyle = lineGradient;
ctx.stroke();
},
createCanvas = function () {
canvas = document.createElement("canvas");
var style = canvas.style;
style.position = "fixed";
style.top = style.left = style.right = style.margin = style.padding = 0;
style.zIndex = 100001;
style.display = "none";
if (options.className) canvas.classList.add(options.className);
document.body.appendChild(canvas);
addEvent(window, "resize", repaint);
},
topbar = {
config: function (opts) {
for (var key in opts)
if (options.hasOwnProperty(key)) options[key] = opts[key];
},
show: function () {
if (showing) return;
showing = true;
if (fadeTimerId !== null) window.cancelAnimationFrame(fadeTimerId);
if (!canvas) createCanvas();
canvas.style.opacity = 1;
canvas.style.display = "block";
topbar.progress(0);
if (options.autoRun) {
(function loop() {
progressTimerId = window.requestAnimationFrame(loop);
topbar.progress(
"+" + 0.05 * Math.pow(1 - Math.sqrt(currentProgress), 2)
);
})();
}
},
progress: function (to) {
if (typeof to === "undefined") return currentProgress;
if (typeof to === "string") {
to =
(to.indexOf("+") >= 0 || to.indexOf("-") >= 0
? currentProgress
: 0) + parseFloat(to);
}
currentProgress = to > 1 ? 1 : to;
repaint();
return currentProgress;
},
hide: function () {
if (!showing) return;
showing = false;
if (progressTimerId != null) {
window.cancelAnimationFrame(progressTimerId);
progressTimerId = null;
}
(function loop() {
if (topbar.progress("+.1") >= 1) {
canvas.style.opacity -= 0.05;
if (canvas.style.opacity <= 0.05) {
canvas.style.display = "none";
fadeTimerId = null;
return;
}
}
fadeTimerId = window.requestAnimationFrame(loop);
})();
},
};

if (typeof module === "object" && typeof module.exports === "object") {
module.exports = topbar;
} else if (typeof define === "function" && define.amd) {
define(function () {
return topbar;
});
} else {
this.topbar = topbar;
}
}.call(this, window, document));
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule LiveViewCounterWeb.PageControllerTest do
use LiveViewCounterWeb.ConnCase

test "GET /", %{conn: conn} do
conn = get(conn, "/")
assert html_response(conn, 200) =~ "The count is"
end
end
11 changes: 0 additions & 11 deletions test/live_view_counter_web/live/page_live_test.exs

This file was deleted.

3 changes: 3 additions & 0 deletions test/live_view_counter_web/views/page_view_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule LiveViewCounterWeb.PageViewTest do
use LiveViewCounterWeb.ConnCase, async: true
end

0 comments on commit c5ff63a

Please sign in to comment.