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

Jcscottiii sidebar tests #72

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 3 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,7 @@ jobs:
steps:
- name: Checkout (GitHub)
uses: actions/checkout@v3
- name: Install skaffold
run: |
curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 && \
sudo install skaffold /usr/local/bin/
echo "Skaffold Version: $(skaffold version)"
- name: Start minikube
uses: medyagh/setup-minikube@4f680380adb365368edacbb09d9ac531070c53e6
with:
start-args: '--profile webstatus-dev'
- uses: actions/setup-go@v5
with:
go-version: '1.22.0' # matches the version in .devcontainer/devcontainer.json
- uses: actions/setup-node@v4
- name: Run precommit target for CI
uses: devcontainers/[email protected]
with:
node-version: 20 # matches the version in .devcontainer/devcontainer.json
- name: Run post_create.sh to finish setting up.
run: MINIKUBE_PROFILE=webstatus-dev ./.devcontainer/post_create.sh
- name: Run playwright tests
run: CI=true MINIKUBE_PROFILE=webstatus-dev make playwright-test
runCmd: CI=true make playwright-test
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 6 additions & 4 deletions e2e/tests/sidebar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import {test, expect} from '@playwright/test';
test('matches the screenshot', async ({page}) => {
await page.goto('http://localhost:5555/');

// Show the sidebar menu
const menuButton = page.locator('#menu-button');
await menuButton.click();
// The sidebar menu should be shown by default.

const sidebar = page.locator('webstatus-sidebar');
await expect(sidebar).toHaveScreenshot('sidebar.png');
await expect(sidebar).toHaveScreenshot('sidebar.png', {
// Temporarily allow a higher diff ratio as these tests become more stable
maxDiffPixelRatio: 0.3,
threshold: 0.3,
});
});
Binary file modified e2e/tests/sidebar.spec.ts-snapshots/sidebar-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/tests/sidebar.spec.ts-snapshots/sidebar-firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/tests/sidebar.spec.ts-snapshots/sidebar-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/src/static/js/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

export const DRAWER_WIDTH_PX = 390; // TODO: Should be relative to screenwidth.
export const DRAWER_WIDTH_PX = 390;

// Determine if the browser looks like the user is on a mobile device.
// We assume that a small enough window width implies a mobile device.
Expand Down
1 change: 0 additions & 1 deletion frontend/src/static/js/components/webstatus-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export class WebstatusHeader extends LitElement {
}

_fireEvent(eventName: string, detail: CustomEventInit | undefined): void {
console.info(`Firing event: ${eventName}`);
const event = new CustomEvent(eventName, {
bubbles: true,
composed: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class WebstatusOverviewContent extends LitElement {
return html`
<div class="main">
<div class="hbox halign-items-space-between header-line">
<h1 class="halig-stretch">Features overview</h1>
<h1 class="halign-stretch">Features overview</h1>
<sl-button
><sl-icon
slot="prefix"
Expand Down
27 changes: 14 additions & 13 deletions frontend/src/static/js/components/webstatus-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,26 @@ export class WebstatusPage extends LitElement {
}

firstUpdated(): void {
const sidebarDrawer = this.shadowRoot?.querySelector(
'#sidebar-drawer'
) as SlDrawer | null;
if (!sidebarDrawer) {
throw new Error('Sidebar Drawer is missing');
}

const showSidebarDrawer = () => {
void sidebarDrawer!.show();
};

if (!IS_MOBILE) {
// TODO: Hide the sidebar by default
showSidebarDrawer();
}

document.addEventListener('toggle-menu', () => {
console.info('got toggle-menu event');
const sidebarDrawer = this.shadowRoot?.querySelector(
'#sidebar-drawer'
) as SlDrawer | null;
console.info('sidebarDrawer', sidebarDrawer);
if (!sidebarDrawer) {
throw new Error('Unable to addEventListener');
}
if (sidebarDrawer!.open === true) {
if (sidebarDrawer.open === true) {
void sidebarDrawer.hide();
} else {
if (sidebarDrawer !== null && sidebarDrawer !== undefined) {
void sidebarDrawer!.show();
}
showSidebarDrawer();
}
});
}
Expand Down
45 changes: 38 additions & 7 deletions frontend/src/static/js/components/webstatus-sidebar-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ import {
} from 'lit';
import {customElement} from 'lit/decorators.js';

// Map from sl-tree-item id to path, and vice versa.
const idPathMap: {[id: string]: string} = {
'features-item': '/',
'statistics-item': '/stats',
};
const pathIdMap: {[path: string]: string} = {};
for (const [id, path] of Object.entries(idPathMap)) {
pathIdMap[path] = id;
}

@customElement('webstatus-sidebar-menu')
export class WebstatusSidebarMenu extends LitElement {
static get styles(): CSSResultGroup {
Expand All @@ -38,12 +48,33 @@ export class WebstatusSidebarMenu extends LitElement {
}

firstUpdated(): void {
// Handle click on features-item
const featuresItem = this.shadowRoot?.querySelector('#features-item');
featuresItem?.addEventListener('click', () => {
// Visit Featurs overview page
// console.info('clicked on features-item')
// window.location.href = '/features'
const tree = this.shadowRoot?.querySelector('sl-tree');
if (!tree) {
throw new Error('No tree found');
}

// Reselect the sl-tree-item corresponding to the current page.
const path = window.location.pathname;
const id = pathIdMap[path];
const item = tree?.querySelector(`#${id}`);
if (item) {
item.setAttribute('selected', '');
}

tree!.addEventListener('sl-selection-change', () => {
const selectedItem = tree!.querySelector('[selected]');
const id = selectedItem?.id;
if (id) {
const path = idPathMap[id];
if (path) {
// If the path is different from the current path, update the URL.
const currentUrl = new URL(window.location.href);
currentUrl.pathname = path; // Update only the path
if (currentUrl.href !== window.location.href) {
window.location.href = currentUrl.href;
}
}
}
});
}

Expand All @@ -63,7 +94,7 @@ export class WebstatusSidebarMenu extends LitElement {
</sl-tree-item>
<sl-tree-item> <sl-icon name="star"></sl-icon> Starred </sl-tree-item>
</sl-tree-item>
<sl-tree-item>
<sl-tree-item id="statistics-item">
<sl-icon name="heart-pulse"></sl-icon> Statistics
</sl-tree-item>
<sl-tree-item> <sl-icon name="bell"></sl-icon> Updates </sl-tree-item>
Expand Down
Loading