Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for context button #477

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c0061c3
test(component-library): add tests for the context menu
Haberkamp Jan 23, 2025
7db484b
fix(component-library): open context menu when pressing space or enter
Haberkamp Jan 23, 2025
88b1978
test(component-library): allow setting a custom button for the contex…
Haberkamp Jan 23, 2025
c6d3ab9
test(component-library): allow setting a custom icon
Haberkamp Jan 23, 2025
eb5805d
test(component-library): simplify rendering of components
Haberkamp Jan 23, 2025
e30aefc
test(component-library): allow setting a custom text for the button
Haberkamp Jan 23, 2025
9efe78f
refactor(component-library): remove dead code from context button
Haberkamp Jan 23, 2025
c8e8c0c
refactor(component-library): migrate mt-context-button to the composi…
Haberkamp Jan 23, 2025
68729e5
refactor(component-library): migrate mt-context-button to css
Haberkamp Jan 23, 2025
47497cf
chore(component-library): adjust styles of mt-context-button
Haberkamp Jan 23, 2025
631a059
refactor(component-library): enable scoped styling for mt-context-button
Haberkamp Jan 23, 2025
d7c4c11
chore(component-library): transition background color when hovering o…
Haberkamp Jan 23, 2025
6c12433
fix(component-library): adjust font-size layout with icon for mt-cont…
Haberkamp Jan 23, 2025
cea7ed2
fix(component-library): center icon of context button when it has no …
Haberkamp Jan 23, 2025
83e4d5a
ci: completely disable caching for visual tests
Haberkamp Jan 23, 2025
837f4ab
fix(component-library): remove unnecessary aria role on context menu …
Haberkamp Jan 23, 2025
9e84a39
refactor(component-library): use migrate mt-context-divider to plain CSS
Haberkamp Jan 23, 2025
a3513bc
test(component-library): check opening an closing of context menu works
Haberkamp Jan 23, 2025
e407e06
test(component-library): pressing the context menu button a second ti…
Haberkamp Jan 23, 2025
f52e3de
test(component-library): do nothing when clicking on a disabled conte…
Haberkamp Jan 23, 2025
95d086b
refactor(component-library): move mt-context-menu-item to composition…
Haberkamp Jan 23, 2025
0430908
refactor(component-library): remove mt-context-menu-divider
Haberkamp Jan 23, 2025
590dd81
refactor(component-library): remove unnecessary props in mt-context-b…
Haberkamp Jan 23, 2025
53dcd06
Apply code formatting and fixable ESLint issues
Haberkamp Jan 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/spotty-singers-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopware-ag/meteor-component-library": patch
---

Open the context menu when pressing space or enter
9 changes: 3 additions & 6 deletions .github/workflows/visual-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: write
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -46,21 +43,21 @@ jobs:
run: pnpm dlx [email protected] install

- name: Build storybook
run: pnpx turbo run build:storybook --filter=@shopware-ag/meteor-component-library -- --test
run: pnpm --filter @shopware-ag/meteor-component-library run build:storybook --test

- name: Run Tests
if: ${{ github.event_name != 'workflow_dispatch' }}
run: |
npx concurrently --kill-others --success first --names "SB,TEST" --hide "SB" --prefix-colors "magenta,blue" \
"http-server ./packages/component-library/storybook-static -a 127.0.0.1 --port 6006" \
"wait-on http://127.0.0.1:6006 && pnpx turbo run test:storybook --force --filter=@shopware-ag/meteor-component-library"
"wait-on http://127.0.0.1:6006 && pnpm --filter=@shopware-ag/meteor-component-library run test:storybook"

- name: Run tests and update snapshots
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
npx concurrently --kill-others --success first --names "SB,TEST" --hide "SB" --prefix-colors "magenta,blue" \
"http-server ./packages/component-library/storybook-static -a 127.0.0.1 --port 6006" \
"wait-on http://127.0.0.1:6006 && pnpx turbo run test:storybook --force --filter=@shopware-ag/meteor-component-library -- -u"
"wait-on http://127.0.0.1:6006 && pnpm --filter=@shopware-ag/meteor-component-library run test:storybook -u"

- name: Archive visual test diffs
uses: actions/upload-artifact@v4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
<template #trigger="{ toggleFloatingUi }">
<slot name="button">
<button
role="button"
aria-haspopup="menu"
aria-label="Context menu"
class="mt-context-button__button"
@click="toggleFloatingUi"
@keyup.enter="toggleFloatingUi"
>
<mt-icon :name="icon" small decorative />

Expand All @@ -23,164 +21,53 @@
</mt-popover>
</template>

<script lang="ts">
import type { PropType } from "vue";

import { defineComponent } from "vue";
<script setup lang="ts">
import MtIcon from "../../icons-media/mt-icon/mt-icon.vue";
import type { View } from "../../overlay/mt-popover/mt-popover.interfaces";
import MtPopover from "../../overlay/mt-popover/mt-popover.vue";

export default defineComponent({
name: "MtContextButtonVue",

components: {
"mt-icon": MtIcon,
"mt-popover": MtPopover,
},

props: {
menuWidth: {
type: Number,
required: false,
default: 220,
},

menuHorizontalAlign: {
type: String as PropType<"right" | "left">,
required: false,
default: "right",
validator(value: string) {
if (!value.length) {
return true;
}
return ["right", "left"].includes(value);
},
},

menuVerticalAlign: {
type: String,
required: false,
default: "bottom",
validator(value: string) {
if (!value.length) {
return true;
}
return ["bottom", "top"].includes(value);
},
},

icon: {
type: String,
required: false,
default: "solid-ellipsis-h-s",
},

disabled: {
type: Boolean,
required: false,
default: false,
},

hasError: {
type: Boolean,
required: false,
default: false,
},

autoClose: {
type: Boolean,
required: false,
default: true,
},

title: {
type: String,
required: false,
default: "",
},

childViews: {
type: Array as PropType<View[]>,
required: false,
default: () => [],
},
},

data() {
return {};
withDefaults(
defineProps<{
menuWidth?: number;
menuHorizontalAlign?: "right" | "left";
menuVerticalAlign?: "bottom" | "top";
icon?: string;
title?: string;
childViews?: View[];
}>(),
{
menuWidth: 220,
menuHorizontalAlign: "right",
menuVerticalAlign: "bottom",
icon: "solid-ellipsis-h-s",
title: "",
default: [],
},

computed: {
contextClass(): {
"is--disabled": boolean;
"has--error": boolean;
} {
return {
"is--disabled": this.disabled,
"has--error": this.hasError,
};
},
},

methods: {},
});
);
</script>

<style lang="scss">
$mt-context-button-color-text: var(--color-icon-primary-default);
$mt-context-button-border-radius: var(--border-radius-xs);
$mt-context-button-color-border: var(--color-border-primary-default);
$mt-context-button-color-disabled: var(--color-icon-primary-disabled);

.mt-context-button {
&.is--disabled {
.mt-context-button__button {
color: var(--color-icon-primary-disabled);
cursor: initial;

&:hover {
border: none;
}
}
}

&.is--disabled.is--open {
.mt-context-button__button {
border: none;
}
<style scoped>
.mt-context-button__button {
color: var(--color-icon-primary-default);
display: flex;
align-items: center;
border-radius: var(--border-radius-xs);
height: var(--scale-size-24);
gap: var(--scale-size-8);
padding-inline: var(--scale-size-10);
line-height: var(--font-line-height-xs);
font-size: var(--font-size-xs);
font-family: var(--font-family-body);
transition: background-color 0.15s ease-out;

&:focus-visible {
outline: 2px solid var(--color-border-brand-selected);
outline-offset: 2px;
}

&.is--open .mt-context-button__button {
border-color: $mt-context-button-color-border;
}

.mt-context-button__button {
position: relative;
color: $mt-context-button-color-text;
background: 0 none;
border: 1px solid transparent;
border-radius: $mt-context-button-border-radius;
cursor: pointer;
height: var(--scale-size-24);
line-height: 20px;
padding: 0 var(--scale-size-8);
outline: none;
font-family: var(--font-family-body);

&:hover {
border-color: $mt-context-button-color-border;
}
}

&.has--error {
.mt-context-button__button {
color: $color-crimson-300;

.mt-icon {
color: $mt-context-button-color-text;
}
}
&:hover,
&:focus-visible {
background-color: var(--color-interaction-secondary-hover);
}
}
</style>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,35 @@
:label="label"
:icon="icon"
:disabled="disabled"
:on-label-click="handleLableClick"
:on-label-click="
() => {
if (disabled) return;

$emit('click');
}
"
:type="type"
:role="role"
/>
</template>

<script lang="ts">
<script setup lang="ts">
import MtPopoverItem from "../../overlay/mt-popover-item/mt-popover-item.vue";
import type { PropType } from "vue";
import { defineComponent } from "vue";
import { type TranslateResult } from "vue-i18n";

export default defineComponent({
name: "MtContextMenuItem",

components: {
"mt-popover-item": MtPopoverItem,
},

props: {
label: {
type: String as PropType<string | TranslateResult>,
required: true,
},

icon: {
type: String,
required: false,
default: null,
},

disabled: {
type: Boolean,
required: false,
default: false,
},

type: {
type: String as PropType<"default" | "active" | "critical">,
required: false,
default: "default",
},

role: {
type: String,
required: false,
default: "menuitem",
},
withDefaults(
defineProps<{
label: string | TranslateResult;
icon?: string;
disabled?: boolean;
type?: "default" | "active" | "critical";
role?: string;
}>(),
{
type: "default",
role: "menuitem",
},
emits: ["click"],
setup(props, { emit }) {
const handleLableClick = () => {
if (props.disabled) {
return;
}

emit("click");
};
);

return {
handleLableClick,
};
},
});
defineEmits<{ click: [] }>();
</script>
Loading