Skip to content

Commit

Permalink
tests: added test to ensure images scrollable left and right on card
Browse files Browse the repository at this point in the history
  • Loading branch information
mwargan committed Mar 7, 2024
1 parent 712b1d1 commit d55338b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/assets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ article>:first-child:is(footer) {
/* make a simple slider with flex */
.images {
width: 100%;
overflow-y: scroll;
display: flex;
max-height: 400px;

Expand Down
2 changes: 1 addition & 1 deletion src/components/CardElement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defineProps({
:to="to ? to : undefined"
>
<article>
<div class="images" v-if="images" tabindex="0">
<div class="images overflow-auto" v-if="images" tabindex="0">
<img
v-for="image in images"
:src="image.src"
Expand Down
25 changes: 25 additions & 0 deletions src/stories/CardElement.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,33 @@ export const ImagesOnly: Story = {
src: "https://via.placeholder.com/150",
alt: "Placeholder Image",
},
{
src: "http://placekitten.com/200/300",
alt: "Placeholder Image",
},
],
},

play: async ({ canvasElement }: any) => {
const canvas = canvasElement;
// Get the card, which is an `article` tag
const article = canvas.querySelector("article");
const imagesSelector = canvas.querySelector(".images");

// Wait for each image to load
await new Promise((resolve) => {
canvas.querySelectorAll("img").forEach((img: HTMLImageElement) => {
img.onload = resolve;
});
});

// Ensure that it is possible to scroll left and right in the article
expect(getComputedStyle(imagesSelector).overflowX).not.toBe("hidden");
expect(imagesSelector.scrollWidth).toBeGreaterThan(article.clientWidth);

// Ensure it is not possible to scroll up and down in the article
expect(imagesSelector.scrollHeight).toBe(article.clientHeight);
},
};

export const BodyOnly: Story = {
Expand Down

0 comments on commit d55338b

Please sign in to comment.