Skip to content

Commit

Permalink
Add more tests and increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
elchininet committed Apr 4, 2024
1 parent a46c43c commit 5b6c3b6
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ profiles:
- triple-tap
- tap
action: navigate
navigation_path: /config/dashboard
navigation_path: /config/dashboard
- taps:
- triple-tap
- tap
- triple-tap
action: navigate
navigation_path: /media-browser/browser
navigation_replace: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
enabled: true
notification: false
profiles:
- user: Test
secrets:
- taps:
- tap
- double-tap
- tap
action: call-service
service: input_boolean.toggle
data:
entity_id: input_boolean.my_switch
- taps:
- double-tap
- tap
- double-tap
action: call-service
service: input_boolean.toggle
- taps:
- double-tap
- double-tap
action: unknown-action
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
enabled: true
notification: true
profiles:
- user: Test
secrets:
- taps:
- tap
- double-tap
- tap
action: call-service
service: input_boolean.toggle
data:
entity_id: input_boolean.my_switch
- taps:
- double-tap
- tap
- double-tap
action: call-service
service: input_boolean.toggle
- taps:
- double-tap
- double-tap
action: unknown-action
19 changes: 7 additions & 12 deletions src/home-assistant-secret-taps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,15 @@ class HomeAssistantSecretTaps {

private _navigate(secret: NavigateSecret): void {
const { navigation_path, navigation_replace = false } = secret;
const params: Parameters<typeof window.history.replaceState> = [
null,
'',
navigation_path
];
if (navigation_replace) {
window.history.replaceState(
window.history.state?.root
? { root: true }
: null,
'',
navigation_path
);
window.history.replaceState(...params);
} else {
window.history.pushState(
null,
'',
navigation_path
);
window.history.pushState(...params);
}
window.dispatchEvent(
new CustomEvent(
Expand Down
24 changes: 23 additions & 1 deletion tests/01 - actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ test('Navigate to a panel', async ({ page }) => {
await tap(page);
await page.waitForTimeout(1500);

await expect(page.url()).toBe(`${BASE_URL}/config/dashboard`);
expect(page.url()).toBe(`${BASE_URL}/config/dashboard`);

await page.goBack();

expect(page.url()).toBe(`${BASE_URL}/lovelace/home`);

});

test('Navigate to a panel replacing history', async ({ page }) => {

await pageVisit(page);

await moveToHeader(page);
await tripleTap(page);
await tap(page);
await tripleTap(page);
await page.waitForTimeout(1500);

expect(page.url()).toBe(`${BASE_URL}/media-browser/browser`);

await page.goBack();

expect(page.url()).not.toBe(`${BASE_URL}/lovelace/home`);

});
144 changes: 144 additions & 0 deletions tests/03 - notifications.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import { test, expect } from 'playwright-test-coverage';
import { CONFIG_FILES, SELECTORS } from './constants';
import {
pageVisit,
haConfigRequest,
moveToHeader,
tap,
doubleTap
} from './utilities';

const TOAST_FAILURE = 'Failed to call service input_boolean/toggle';
const VISIBILITY_OPTIONS = { timeout: 0 };

test.describe('Notifications disabled', () => {

test.beforeAll(async () => {
await haConfigRequest(CONFIG_FILES.NOTIFICATIONS_DISABLED);
});

test('Successful action', async ({ page }) => {

await pageVisit(page);

await moveToHeader(page);
await tap(page);
await doubleTap(page);
await tap(page);
await page.waitForTimeout(1500);

const toast = page.locator(SELECTORS.TOAST);

await expect(toast).not.toBeVisible(VISIBILITY_OPTIONS);

await moveToHeader(page);
await tap(page);
await doubleTap(page);
await tap(page);
await page.waitForTimeout(1500);

await expect(toast).not.toBeVisible(VISIBILITY_OPTIONS);

});

test('Unsuccessful action', async ({ page }) => {

await pageVisit(page);

await moveToHeader(page);
await doubleTap(page);
await tap(page);
await doubleTap(page);
await page.waitForTimeout(1500);

const toast = page.locator(SELECTORS.TOAST);

await expect(toast).toBeVisible();
await expect(toast).toContainText(TOAST_FAILURE);

});

test('Non-existent action', async ({ page }) => {

await pageVisit(page);

await moveToHeader(page);
await doubleTap(page);
await doubleTap(page);
await page.waitForTimeout(1500);

await expect(
page.locator(SELECTORS.TOAST)
).not.toBeVisible(VISIBILITY_OPTIONS);

});

});

test.describe('Notifications enabled', () => {

test.beforeAll(async () => {
await haConfigRequest(CONFIG_FILES.NOTIFICATIONS_ENABLED);
});

test('Successful action', async ({ page }) => {

await pageVisit(page);

await moveToHeader(page);
await tap(page);
await doubleTap(page);
await tap(page);
await page.waitForTimeout(1500);

const toast = page.locator(SELECTORS.TOAST);

await expect(toast).toBeVisible();
await expect(toast).toContainText('secret taps successfully executed!');
await expect(toast).not.toBeVisible();

await moveToHeader(page);
await tap(page);
await doubleTap(page);
await tap(page);
await page.waitForTimeout(1500);

await expect(toast).toBeVisible();
await expect(toast).toContainText('secret taps successfully executed!');

});

test('Unsuccessful action', async ({ page }) => {

await pageVisit(page);

await moveToHeader(page);
await doubleTap(page);
await tap(page);
await doubleTap(page);
await page.waitForTimeout(1500);

const toast = page.locator(SELECTORS.TOAST);

await expect(toast).toBeVisible();
await expect(toast).toContainText(TOAST_FAILURE);

});

test('Non-existent action', async ({ page }) => {

await pageVisit(page);

await moveToHeader(page);
await doubleTap(page);
await doubleTap(page);
await page.waitForTimeout(1500);

const toast = page.locator(SELECTORS.TOAST);

await expect(toast).toBeVisible();
await expect(toast).toContainText('secret taps failed! Review your secret config!');

});

});
File renamed without changes.
7 changes: 5 additions & 2 deletions tests/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ export const CONFIG_FILES = {
BASIC: 'basic',
NON_MATCHING_USERS: 'non-matching-users',
MATCHING_USERS: 'matching-users',
NOT_ENABLED: 'not-enabled'
NOT_ENABLED: 'not-enabled',
NOTIFICATIONS_DISABLED: 'notifications-disabled',
NOTIFICATIONS_ENABLED: 'notifications-enabled'
};

export const SELECTORS = {
HUI_VIEW: 'hui-view',
MY_SWITCH: '#basic-switch',
MORE_INFO_DIALOG: 'ha-dialog',
DIALOG_HEADER_TITLE: 'ha-dialog-header span[slot="title"]',
SIDEBAR: 'ha-sidebar'
SIDEBAR: 'ha-sidebar',
TOAST: 'ha-toast'
};

0 comments on commit 5b6c3b6

Please sign in to comment.