Improve Page structure and create a redirect middleware to set /films as homepage

This commit is contained in:
2020-12-17 18:28:32 +01:00
parent 467eb68e25
commit 407ef3dcd1
4 changed files with 8 additions and 3 deletions

View File

@@ -9,7 +9,9 @@
</template> </template>
<script> <script>
export default {}; export default {
middleware: ["redirect"]
};
</script> </script>
<style> <style>

3
middleware/redirect.js Normal file
View File

@@ -0,0 +1,3 @@
export default function({ redirect, route }) {
if (route.path === "/") redirect("/films");
}

View File

@@ -1,6 +1,6 @@
import { mount } from "@vue/test-utils"; import { mount } from "@vue/test-utils";
import axios from "axios"; import axios from "axios";
import FilmsView from "@/pages"; import FilmsView from "@/pages/films";
import mockFilms from "./fake-films.json"; import mockFilms from "./fake-films.json";
jest.mock("axios", () => ({ jest.mock("axios", () => ({
@@ -10,7 +10,7 @@ jest.mock("axios", () => ({
describe("Films page", () => { describe("Films page", () => {
it("should render Films page instance", () => { it("should render Films page instance", () => {
const wrapper = mount(FilmsView); const wrapper = mount(FilmsView);
expect(wrapper.find("h1").text()).toBe("Ghibli films"); expect(wrapper.find("h2").text()).toBe("Ghibli films");
}); });
it("should get films from Ghibli API", async () => { it("should get films from Ghibli API", async () => {