Skip to content

Commit

Permalink
Use better placeholder images and automated tests along with pull_req…
Browse files Browse the repository at this point in the history
…uest.yml

* Convert PrimaryButton to a more generic Button component with primary, sec and tert classes

* Use better placeholder images

* Add homepage to package.json

* Add see list of recipes homepage test

* Rename node.js.yml to pull_request.yml

* Use pnpm in pull_request.yml

* Update pull_request.yml using pnpm official docs as guide

* use only node 20

* Add playwright install to download browsers

* update

* use only one job

* reference api key from secrets
  • Loading branch information
luz-ojeda authored May 30, 2024
1 parent c883376 commit 9beaed6
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 64 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/node.js.yml

This file was deleted.

32 changes: 32 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Node.js CI

on:
pull_request:
branches: ['master']

jobs:
build_and_test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20]

steps:
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
- run: pnpm install
- run: pnpm run build
- run: pnpm exec playwright install
- run: pnpm test
env:
API_URL: ${{ secrets.API_URL }}
API_KEY: ${{ secrets.API_KEY }}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "cook-web",
"version": "1.1.0",
"private": true,
"homepage": "https://github.com/luz-ojeda/cook-web",
"scripts": {
"dev": "vite dev",
"build": "vite build",
Expand Down
Binary file removed src/lib/assets/recipe_image_placeholder.png
Binary file not shown.
18 changes: 18 additions & 0 deletions src/lib/assets/recipe_image_placeholder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@
export let disabled = false;
export let loading = false; // Use local state since we not always want it to sync with a global/different one
export let onClick: EventHandler<MouseEvent | SubmitEvent> | undefined = undefined;
export let width = 'auto';
export let size: 'small' | 'large' = 'large';
export let type: 'button' | 'reset' | 'submit' | null | undefined = 'button';
export let buttonType: 'primary' | 'secondary' | 'tertiary' = 'primary';
</script>

<button
class="
{buttonType === 'primary'
? 'primary'
: buttonType === 'secondary'
? 'secondary'
: 'tertiary'} {size === 'small' ? 'small' : 'large'}"
disabled={disabled || loading}
on:click={onClick}
on:submit={type === 'submit' ? onClick : undefined}
{type}
style="width: {width}"
>
{#if loading}
<CircularLoading --background="#a19887" --circle-width="30px" />
Expand All @@ -29,24 +35,11 @@
button {
align-items: center;
background-color: $primaryColor;
border: 0;
border-radius: 7px;
box-shadow:
inset 0 3px 0 $lightestPrimaryColor,
$shadow;
color: $grey200;
display: flex;
font-size: 20px;
font-weight: bold;
height: 48px;
justify-content: center;
padding: 8px 24px;
&:hover {
background-color: $lightPrimaryColor;
transition: background-color 0.3s;
}
&:disabled {
box-shadow:
Expand All @@ -59,4 +52,39 @@
box-shadow: $smallestShadow;
}
}
.small {
font-size: 16px;
height: 32px;
padding: 4px 12px;
}
.large {
font-size: 20px;
height: 48px;
padding: 8px 24px;
width: 100%;
}
.primary {
background-color: $primaryColor;
box-shadow:
inset 0 3px 0 $lightestPrimaryColor,
$shadow;
color: $grey200;
&:hover {
background-color: $lightPrimaryColor;
transition: background-color 0.3s;
}
}
.tertiary {
background-color: transparent;
color: $primaryColor;
&:hover {
text-decoration: underline;
}
}
</style>
8 changes: 3 additions & 5 deletions src/lib/components/RecipeCard.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { SaveRecipeButton, slugify } from '$lib';
import placeholder from '$lib/assets/recipe_image_placeholder.png';
import placeholder from '$lib/assets/recipe_image_placeholder.svg';
export let recipeId: string;
export let recipeImage: string;
Expand All @@ -10,19 +10,18 @@
$: slugifiedRecipeTitle = slugify(recipeTitle);
</script>

<div class="container flex-column">
<div class="container flex-column" data-testid="recipe-card">
<a class="non-text-anchor-element" href={`/recetas/${slugifiedRecipeTitle}`}>
<img
alt={`Photo of the recipe ${recipeTitle}`}
class="rounded-img recipe-image"
class="rounded-img recipe-image {recipeImage ? 'object-fit-cover' : ''}"
crossorigin="anonymous"
loading="lazy"
src={recipeImage ? recipeImage : placeholder}
/>
</a>
<div class="title-container">
<a class="non-text-anchor-element" href={`/recetas/${slugifiedRecipeTitle}`}>

<h2>{recipeTitle}</h2>
</a>
<SaveRecipeButton {recipeId} --iconWidth="32px" --mobileIconWidth="48px" />
Expand Down Expand Up @@ -50,7 +49,6 @@
margin-bottom: 16px;
max-height: 240px;
display: inline-block;
object-fit: cover;
width: 100%;
@media (max-width: $mobileBreakpoint) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/RecipeForm.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { applyAction, enhance } from '$app/forms';
import { ImageUploadInput, slugify } from '$lib';
import PrimaryButton from '$lib/components/PrimaryButton.svelte';
import Button from '$lib/components/Button.svelte';
import type { Recipe } from '$lib/types/Recipe';
import type { RecipeFormDataElems } from '$lib/types/RecipeFormData';
import type { ActionData as CreateRecipeActionData } from '../../routes/admin/crear-receta/$types';
Expand Down Expand Up @@ -215,7 +215,7 @@
/>
</label>

<PrimaryButton disabled={invalidFile} {loading} type="submit">{submitButtonText}</PrimaryButton>
<Button disabled={invalidFile} {loading} type="submit">{submitButtonText}</Button>
</form>
{#if form?.success}
<p class="success">
Expand Down
11 changes: 4 additions & 7 deletions src/lib/components/RecipesSearchForm.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { page, navigating } from '$app/stores';
import { ChipTextInput, PrimaryButton, TextInput } from '$lib';
import { ChipTextInput, Button, TextInput } from '$lib';
import { buildRecipesBrowserUrl } from '$lib/scripts/urls';
import { recipes } from '../../stores/recipes';
import { burgerMenuStore } from '../../stores/burgerMenu';
Expand Down Expand Up @@ -95,9 +95,7 @@
<label for="vegetarian">Solo vegetarianas</label>

{#if $page.url.pathname !== '/'}
<PrimaryButton {loading} onClick={onButtonClick} type="submit" width="100%">
Buscar
</PrimaryButton>
<Button {loading} onClick={onButtonClick} type="submit">Buscar</Button>
{:else}
<a
class="non-text-anchor-element"
Expand All @@ -109,13 +107,12 @@
})}
style={Boolean($navigating) ? 'pointer-events: none' : ''}
>
<PrimaryButton
<Button
disabled={$recipes.loading || Boolean($navigating)}
loading={loading && $navigating?.to?.url.pathname == '/recetas'}
onClick={() => {
loading = true;
}}
width="100%">Buscar</PrimaryButton
}}>Buscar</Button
>
</a>
{/if}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Components
import BurgerMenu from './components/BurgerMenu.svelte';
import Button from './components/Button.svelte';
import ChipTextInput from './components/ChipTextInput.svelte';
import CircularLoading from './components/CircularLoading.svelte';
import CopyRecipeButton from './components/CopyRecipeButton.svelte';
Expand All @@ -10,7 +11,6 @@ import Icon from './components/Icon.svelte';
import ImageUploadInput from './components/ImageUploadInput.svelte';
import Navbar from './components/Navbar.svelte';
import Pagination from './components/Pagination.svelte';
import PrimaryButton from './components/PrimaryButton.svelte';
import RecipeCard from './components/RecipeCard.svelte';
import RecipeForm from './components/RecipeForm.svelte';
import RecipesSearchForm from './components/RecipesSearchForm.svelte';
Expand All @@ -19,6 +19,7 @@ import TextInput from './components/TextInput.svelte';

export {
BurgerMenu,
Button,
ChipTextInput,
CircularLoading,
CopyRecipeButton,
Expand All @@ -29,7 +30,6 @@ export {
ImageUploadInput,
Navbar,
Pagination,
PrimaryButton,
RecipeCard,
RecipeForm,
RecipesSearchForm,
Expand Down
5 changes: 2 additions & 3 deletions src/routes/recetas/[name]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import type { Recipe } from '$lib/types/Recipe';
import placeholder from '$lib/assets/recipe_image_placeholder.png';
import placeholder from '$lib/assets/recipe_image_placeholder.svg';
import {
CopyRecipeButton,
DownloadRecipeButton,
Expand Down Expand Up @@ -40,7 +40,7 @@
<div class="recipe-first-content">
<img
alt={`Photo of the recipe ${data.name}`}
class="image-container rounded-img recipe-image"
class="image-container rounded-img recipe-image {data.pictures[0] ? 'object-fit-cover' : ''}"
crossorigin="anonymous"
src={data.pictures[0] ? data.pictures[0] : placeholder}
/>
Expand Down Expand Up @@ -183,7 +183,6 @@
.recipe-image {
max-height: 374px;
margin-right: 20px;
object-fit: cover;
width: 100%;
@media (max-width: $tabletBreakpoint) {
Expand Down
4 changes: 4 additions & 0 deletions src/sass/utilities.scss
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,7 @@
color: $grey900;
text-decoration: none;
}

.object-fit-cover {
object-fit: cover;
}
9 changes: 9 additions & 0 deletions tests/homepageTests.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { expect, test } from '@playwright/test';

test('user can see list of recipes in homepage', async ({ page }) => {
await page.goto('/');

const recipeCardsCount = await page.getByTestId('recipe-card').count();

expect(recipeCardsCount).toEqual(4);
});
6 changes: 0 additions & 6 deletions tests/test.ts

This file was deleted.

0 comments on commit 9beaed6

Please sign in to comment.