@haatlabs-core/templates 0.19.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/starter/apps/api/package.json.tmpl +1 -0
- package/starter/apps/api/src/app.module.ts +36 -0
- package/starter/apps/api/src/notifications.int.test.ts +210 -0
- package/starter/apps/api/src/security-sweep.int.test.ts +81 -12
- package/starter/apps/api/src/seed-plans.int.test.ts +8 -1
- package/starter/apps/api/src/seed.ts +16 -3
- package/starter/apps/shopify-app/index.html +2 -0
- package/starter/apps/shopify-app/public/theme-boot.js +6 -0
- package/starter/apps/web/public/notifications-sw.js +47 -0
- package/starter/apps/worker/package.json.tmpl +2 -0
- package/starter/apps/worker/src/handlers/notifications.handler.ts +63 -0
- package/starter/apps/worker/src/runtime.ts +52 -26
- package/starter/dot-env.example +16 -0
- package/starter/packages/config/src/config.test.ts +26 -0
- package/starter/packages/config/src/config.ts +11 -2
- package/starter/packages/contracts/package.json.tmpl +3 -1
- package/starter/packages/contracts/src/notifications.ts +38 -0
- package/starter/packages/database/drizzle/0009_notifications.sql +87 -0
- package/starter/packages/database/drizzle/0010_platform_vendorhaat.sql +5 -0
- package/starter/packages/database/drizzle/meta/0009_snapshot.json +2446 -0
- package/starter/packages/database/drizzle/meta/0010_snapshot.json +2467 -0
- package/starter/packages/database/drizzle/meta/_journal.json +14 -0
- package/starter/packages/database/package.json.tmpl +1 -0
- package/starter/packages/database/src/index.ts +1 -0
- package/starter/packages/database/src/repositories/billing.int.test.ts +5 -4
- package/starter/packages/database/src/repositories/notification.repository.ts +65 -0
- package/starter/packages/database/src/schema/index.ts +1 -0
- package/starter/packages/database/src/schema/notifications.ts +37 -0
- package/starter/packages/database/src/schema-tables.int.test.ts +10 -0
- package/starter/packages/queue/src/topology.test.ts +1 -0
- package/starter/packages/queue/src/topology.ts +3 -0
- package/starter/packages/web-ui/package.json.tmpl +1 -0
- package/starter/packages/web-ui/src/App.test.tsx +140 -6
- package/starter/packages/web-ui/src/App.tsx +129 -27
- package/starter/packages/web-ui/src/api-client.test.ts +204 -1
- package/starter/packages/web-ui/src/api-client.ts +207 -1
- package/starter/packages/web-ui/src/components/Logo.tsx +11 -3
- package/starter/packages/web-ui/src/pages/HomePage.tsx +3 -3
- package/starter/packages/web-ui/src/pages/LoginPage.tsx +3 -1
- package/starter/packages/web-ui/src/pages/NotificationSettingsPage.tsx +24 -0
- package/starter/packages/web-ui/src/pages/NotificationsPage.tsx +19 -0
- package/starter/packages/web-ui/src/styles.css +73 -37
- package/starter/packages/web-ui/src/testing/fake-client.ts +16 -0
|
@@ -64,6 +64,20 @@
|
|
|
64
64
|
"when": 1794501701224,
|
|
65
65
|
"tag": "0008_product_and_disposable",
|
|
66
66
|
"breakpoints": true
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"idx": 9,
|
|
70
|
+
"version": "7",
|
|
71
|
+
"when": 1795292234975,
|
|
72
|
+
"tag": "0009_notifications",
|
|
73
|
+
"breakpoints": true
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"idx": 10,
|
|
77
|
+
"version": "7",
|
|
78
|
+
"when": 1795407128717,
|
|
79
|
+
"tag": "0010_platform_vendorhaat",
|
|
80
|
+
"breakpoints": true
|
|
67
81
|
}
|
|
68
82
|
]
|
|
69
83
|
}
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"@@@name@@/observability": "workspace:*",
|
|
20
20
|
"@haatlabs-core/db-core": "^@@platformVersion@@",
|
|
21
21
|
"@haatlabs-core/nest-billing": "^@@platformVersion@@",
|
|
22
|
+
"@haatlabs-core/notifications": "^@@platformVersion@@",
|
|
22
23
|
"drizzle-orm": "^0.45.3",
|
|
23
24
|
"pg": "^8.23.1",
|
|
24
25
|
"tsx": "^4.23.15"
|
|
@@ -319,8 +319,8 @@ describe('billing repository', () => {
|
|
|
319
319
|
});
|
|
320
320
|
const pro = (await billing.listPlans()).find((plan) => plan.code === 'pro');
|
|
321
321
|
expect(pro?.prices).toEqual([
|
|
322
|
-
{ provider: 'razorpay', currency: 'INR', amountMinor: 399900 },
|
|
323
|
-
{ provider: 'stripe', currency: 'USD', amountMinor: 4900 },
|
|
322
|
+
{ provider: 'razorpay', currency: 'INR', amountMinor: 399900, interval: 'MONTH' },
|
|
323
|
+
{ provider: 'stripe', currency: 'USD', amountMinor: 4900, interval: 'MONTH' },
|
|
324
324
|
]);
|
|
325
325
|
await expect(
|
|
326
326
|
systemBilling.setPrice('platinum', 'stripe', {
|
|
@@ -622,8 +622,8 @@ describe('billing repository', () => {
|
|
|
622
622
|
});
|
|
623
623
|
const pro = (await billing.listPlans()).find((plan) => plan.code === 'pro');
|
|
624
624
|
expect(pro?.prices).toEqual([
|
|
625
|
-
{ provider: 'razorpay', currency: 'INR', amountMinor: 449900 },
|
|
626
|
-
{ provider: 'stripe', currency: 'USD', amountMinor: 4900 },
|
|
625
|
+
{ provider: 'razorpay', currency: 'INR', amountMinor: 449900, interval: 'MONTH' },
|
|
626
|
+
{ provider: 'stripe', currency: 'USD', amountMinor: 4900, interval: 'MONTH' },
|
|
627
627
|
]);
|
|
628
628
|
});
|
|
629
629
|
|
|
@@ -722,6 +722,7 @@ describe('billing repository', () => {
|
|
|
722
722
|
priceRef: 'shopify_starter_monthly',
|
|
723
723
|
currency: 'USD',
|
|
724
724
|
amountMinor: 1900,
|
|
725
|
+
interval: 'MONTH',
|
|
725
726
|
planName: 'Starter',
|
|
726
727
|
});
|
|
727
728
|
expect(await firstPrice(systemBilling, 'free', 'shopify')).toBeNull();
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { notificationEvents } from '@@@name@@/contracts/notifications';
|
|
2
|
+
import {
|
|
3
|
+
NotificationRepository as SharedNotificationRepository,
|
|
4
|
+
SystemNotificationRepository as SharedSystemNotificationRepository,
|
|
5
|
+
createNotifier,
|
|
6
|
+
} from '@haatlabs-core/notifications';
|
|
7
|
+
import type { Recipient } from '@haatlabs-core/notifications';
|
|
8
|
+
import { and, eq } from 'drizzle-orm';
|
|
9
|
+
import type { Database } from '../client';
|
|
10
|
+
import {
|
|
11
|
+
memberships,
|
|
12
|
+
notificationDefaults,
|
|
13
|
+
notificationPreferences,
|
|
14
|
+
notifications,
|
|
15
|
+
pushSubscriptions,
|
|
16
|
+
users,
|
|
17
|
+
} from '../schema';
|
|
18
|
+
import { insertOutbox } from './shared';
|
|
19
|
+
|
|
20
|
+
// The platform's notifications (@haatlabs-core/notifications), bound to this app's tables and events.
|
|
21
|
+
|
|
22
|
+
export const notificationTables = {
|
|
23
|
+
notifications,
|
|
24
|
+
notificationPreferences,
|
|
25
|
+
notificationDefaults,
|
|
26
|
+
pushSubscriptions,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* `notify(tx, …)`: writes the inbox rows and their delivery in the caller's transaction, so
|
|
33
|
+
* they commit with the change they tell of, or not at all.
|
|
34
|
+
*/
|
|
35
|
+
export const notifier = createNotifier({
|
|
36
|
+
tables: notificationTables,
|
|
37
|
+
events: notificationEvents,
|
|
38
|
+
outbox: insertOutbox,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/** One tenant's inbox, choices and devices, through the runtime role (row-level security). */
|
|
42
|
+
export class NotificationRepository extends SharedNotificationRepository {
|
|
43
|
+
constructor(appDb: Database) {
|
|
44
|
+
super(appDb, notificationTables);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** What the worker delivers and prunes with, on the system connection. */
|
|
49
|
+
export class SystemNotificationRepository extends SharedSystemNotificationRepository {
|
|
50
|
+
constructor(systemDb: Database) {
|
|
51
|
+
super(systemDb, notificationTables);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** A person's email, while they are a member of the organization; null for anyone else. */
|
|
55
|
+
async emailOf(organizationId: string, recipient: Recipient): Promise<string | null> {
|
|
56
|
+
if (recipient.type !== 'user' || !UUID.test(recipient.id)) return null;
|
|
57
|
+
const [row] = await this.systemDb
|
|
58
|
+
.select({ email: users.email })
|
|
59
|
+
.from(users)
|
|
60
|
+
.innerJoin(memberships, eq(memberships.userId, users.id))
|
|
61
|
+
.where(and(eq(users.id, recipient.id), eq(memberships.organizationId, organizationId)))
|
|
62
|
+
.limit(1);
|
|
63
|
+
return row?.email ?? null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { pgTable } from 'drizzle-orm/pg-core';
|
|
2
|
+
import {
|
|
3
|
+
notificationColumns,
|
|
4
|
+
notificationDefaultColumns,
|
|
5
|
+
notificationDefaultIndexes,
|
|
6
|
+
notificationIndexes,
|
|
7
|
+
notificationPreferenceColumns,
|
|
8
|
+
notificationPreferenceIndexes,
|
|
9
|
+
pushSubscriptionColumns,
|
|
10
|
+
pushSubscriptionIndexes,
|
|
11
|
+
} from '@haatlabs-core/db-core';
|
|
12
|
+
import { organizations } from './identity';
|
|
13
|
+
|
|
14
|
+
// The inbox, each person's choices, the organization's defaults and the devices push goes to
|
|
15
|
+
// (@haatlabs-core/notifications). Every row is one organization's, behind row-level security.
|
|
16
|
+
|
|
17
|
+
export const notifications = pgTable('notifications', notificationColumns({ organizations }), (t) =>
|
|
18
|
+
notificationIndexes(t),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const notificationPreferences = pgTable(
|
|
22
|
+
'notification_preferences',
|
|
23
|
+
notificationPreferenceColumns({ organizations }),
|
|
24
|
+
(t) => notificationPreferenceIndexes(t),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export const notificationDefaults = pgTable(
|
|
28
|
+
'notification_defaults',
|
|
29
|
+
notificationDefaultColumns({ organizations }),
|
|
30
|
+
(t) => notificationDefaultIndexes(t),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export const pushSubscriptions = pgTable(
|
|
34
|
+
'push_subscriptions',
|
|
35
|
+
pushSubscriptionColumns({ organizations }),
|
|
36
|
+
(t) => pushSubscriptionIndexes(t),
|
|
37
|
+
);
|
|
@@ -8,8 +8,12 @@ const EXPECTED = [
|
|
|
8
8
|
'allowance_grants',
|
|
9
9
|
'api_keys',
|
|
10
10
|
'audit_logs',
|
|
11
|
+
'disposable_email_domains',
|
|
11
12
|
'extension_keys',
|
|
12
13
|
'memberships',
|
|
14
|
+
'notification_defaults',
|
|
15
|
+
'notification_preferences',
|
|
16
|
+
'notifications',
|
|
13
17
|
'organization_features',
|
|
14
18
|
'organizations',
|
|
15
19
|
'outbox_messages',
|
|
@@ -18,10 +22,12 @@ const EXPECTED = [
|
|
|
18
22
|
'plan_prices',
|
|
19
23
|
'plans',
|
|
20
24
|
'platform_admins',
|
|
25
|
+
'push_subscriptions',
|
|
21
26
|
'shopify_installations',
|
|
22
27
|
'stores',
|
|
23
28
|
'subscriptions',
|
|
24
29
|
'usage_records',
|
|
30
|
+
'user_identities',
|
|
25
31
|
'users',
|
|
26
32
|
'webhook_events',
|
|
27
33
|
];
|
|
@@ -88,7 +94,11 @@ describe('database tables', () => {
|
|
|
88
94
|
'api_keys',
|
|
89
95
|
'extension_keys',
|
|
90
96
|
'memberships',
|
|
97
|
+
'notification_defaults',
|
|
98
|
+
'notification_preferences',
|
|
99
|
+
'notifications',
|
|
91
100
|
'organization_features',
|
|
101
|
+
'push_subscriptions',
|
|
92
102
|
'stores',
|
|
93
103
|
'subscriptions',
|
|
94
104
|
'usage_records',
|
|
@@ -4,6 +4,7 @@ import { DEFAULT_KEY_PREFIX, QueueName, allQueueNames, queueFor } from './index'
|
|
|
4
4
|
describe('this project’s topology', () => {
|
|
5
5
|
it('routes Shopify work to its queue, and refuses a key no queue takes', () => {
|
|
6
6
|
expect(queueFor('shopify.product.upsert')).toBe(QueueName.ShopifySync);
|
|
7
|
+
expect(queueFor('notifications.deliver')).toBe(QueueName.Notifications);
|
|
7
8
|
expect(queueFor('nothing.here')).toBeNull();
|
|
8
9
|
});
|
|
9
10
|
|
|
@@ -8,12 +8,15 @@ import type { QueueConnection } from '@haatlabs-core/queue';
|
|
|
8
8
|
|
|
9
9
|
export const QueueName = {
|
|
10
10
|
ShopifySync: 'shopify-sync',
|
|
11
|
+
/** Delivering notifications: live, push and email (@haatlabs-core/notifications). */
|
|
12
|
+
Notifications: 'notifications',
|
|
11
13
|
} as const;
|
|
12
14
|
export type QueueName = (typeof QueueName)[keyof typeof QueueName];
|
|
13
15
|
|
|
14
16
|
/** What a routing key starts with, for each kind of work. */
|
|
15
17
|
const route = routeByPrefix<QueueName>({
|
|
16
18
|
'shopify-sync': ['shopify.'],
|
|
19
|
+
notifications: ['notifications.'],
|
|
17
20
|
});
|
|
18
21
|
|
|
19
22
|
/** The kind of work a routing key is, or null when nothing handles it. */
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"@fontsource/jetbrains-mono": "^5.3.0",
|
|
18
18
|
"@fontsource/instrument-sans": "^5.3.0",
|
|
19
19
|
"@haatlabs-core/auth-contracts": "^@@platformVersion@@",
|
|
20
|
+
"@haatlabs-core/notifications": "^@@platformVersion@@",
|
|
20
21
|
"@haatlabs-core/ui": "^@@platformVersion@@",
|
|
21
22
|
"@tanstack/react-query": "^5.104.1",
|
|
22
23
|
"react": "^19.3.0",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
|
-
import { act, cleanup, render, screen } from '@testing-library/react';
|
|
2
|
+
import { act, cleanup, render, screen, within } from '@testing-library/react';
|
|
3
3
|
import userEvent from '@testing-library/user-event';
|
|
4
4
|
import { ALL_FEATURES_ON } from '@@@name@@/contracts';
|
|
5
5
|
import type { MeResponse } from '@@@name@@/contracts';
|
|
@@ -11,10 +11,15 @@ import type { AppMode } from './App';
|
|
|
11
11
|
import { ApiError } from './api-client';
|
|
12
12
|
import type { ApiClient } from './api-client';
|
|
13
13
|
#@if kindShopify
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
SHOP_STORE_ID,
|
|
16
|
+
fakeNotifications,
|
|
17
|
+
fakeClient as fullFakeClient,
|
|
18
|
+
shopStore,
|
|
19
|
+
} from './testing/fake-client';
|
|
15
20
|
#@end
|
|
16
21
|
#@if !kindShopify
|
|
17
|
-
import { fakeClient as fullFakeClient } from './testing/fake-client';
|
|
22
|
+
import { fakeNotifications, fakeClient as fullFakeClient } from './testing/fake-client';
|
|
18
23
|
#@end
|
|
19
24
|
|
|
20
25
|
const ORG_ID = '11111111-1111-4111-8111-111111111111';
|
|
@@ -27,6 +32,7 @@ const me: MeResponse = {
|
|
|
27
32
|
via: 'session',
|
|
28
33
|
csrfToken: 'csrf',
|
|
29
34
|
storeOnly: false,
|
|
35
|
+
organizationCount: 1,
|
|
30
36
|
features: ALL_FEATURES_ON,
|
|
31
37
|
};
|
|
32
38
|
#@if kindShopify
|
|
@@ -61,12 +67,28 @@ const renderApp = (client: ApiClient, url = '/'): void => {
|
|
|
61
67
|
};
|
|
62
68
|
#@end
|
|
63
69
|
|
|
70
|
+
/** Sign out from the sidebar's account menu, as on a computer. */
|
|
71
|
+
const signOut = async (user: ReturnType<typeof userEvent.setup>): Promise<void> => {
|
|
72
|
+
await user.click(await screen.findByRole('button', { name: /^Account: / }));
|
|
73
|
+
await user.click(screen.getByRole('menuitem', { name: 'Sign out' }));
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/** A phone or tablet: below the platform's 1024px breakpoint. */
|
|
77
|
+
const phoneWidth = (): void => {
|
|
78
|
+
window.matchMedia = vi.fn().mockImplementation((query: string) => ({
|
|
79
|
+
matches: query === '(max-width: 1023px)',
|
|
80
|
+
addEventListener: vi.fn(),
|
|
81
|
+
removeEventListener: vi.fn(),
|
|
82
|
+
}));
|
|
83
|
+
};
|
|
84
|
+
|
|
64
85
|
beforeEach(() => {
|
|
65
86
|
vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
66
87
|
});
|
|
67
88
|
afterEach(() => {
|
|
68
89
|
cleanup();
|
|
69
90
|
vi.restoreAllMocks();
|
|
91
|
+
Reflect.deleteProperty(window, 'matchMedia');
|
|
70
92
|
});
|
|
71
93
|
|
|
72
94
|
describe('standalone app', () => {
|
|
@@ -183,11 +205,35 @@ describe('standalone app', () => {
|
|
|
183
205
|
const client = fakeClient({ me: meFn });
|
|
184
206
|
renderApp(client);
|
|
185
207
|
const user = userEvent.setup();
|
|
186
|
-
await user
|
|
208
|
+
await signOut(user);
|
|
187
209
|
expect(client.logout).toHaveBeenCalledTimes(1);
|
|
188
210
|
expect(await screen.findByRole('button', { name: 'Send me a code' })).toBeTruthy();
|
|
189
211
|
});
|
|
190
212
|
|
|
213
|
+
it('turns push off on this device before Sign out, and signs out when that fails', async () => {
|
|
214
|
+
const meFn = vi.fn().mockResolvedValueOnce(me).mockRejectedValue(unauthorized());
|
|
215
|
+
const disable = vi.fn().mockRejectedValue(new Error('no service worker'));
|
|
216
|
+
const client = fakeClient({
|
|
217
|
+
me: meFn,
|
|
218
|
+
notifications: fakeNotifications({
|
|
219
|
+
push: {
|
|
220
|
+
support: () => 'supported',
|
|
221
|
+
enable: vi.fn().mockResolvedValue('subscribed'),
|
|
222
|
+
disable,
|
|
223
|
+
},
|
|
224
|
+
}),
|
|
225
|
+
});
|
|
226
|
+
renderApp(client);
|
|
227
|
+
const user = userEvent.setup();
|
|
228
|
+
await signOut(user);
|
|
229
|
+
expect(await screen.findByRole('button', { name: 'Send me a code' })).toBeTruthy();
|
|
230
|
+
expect(disable).toHaveBeenCalledTimes(1);
|
|
231
|
+
expect(client.logout).toHaveBeenCalledTimes(1);
|
|
232
|
+
const [disabledAt] = disable.mock.invocationCallOrder;
|
|
233
|
+
const [loggedOutAt] = vi.mocked(client.logout).mock.invocationCallOrder;
|
|
234
|
+
expect(disabledAt).toBeLessThan(loggedOutAt ?? 0);
|
|
235
|
+
});
|
|
236
|
+
|
|
191
237
|
it('shows the sign-in form when the session expires mid-use', async () => {
|
|
192
238
|
const meFn = vi.fn().mockResolvedValueOnce(me).mockRejectedValue(unauthorized());
|
|
193
239
|
const client = fakeClient({
|
|
@@ -204,7 +250,7 @@ describe('standalone app', () => {
|
|
|
204
250
|
const client = fakeClient({ me: meFn, logout: vi.fn().mockRejectedValue(unauthorized()) });
|
|
205
251
|
renderApp(client);
|
|
206
252
|
const user = userEvent.setup();
|
|
207
|
-
await user
|
|
253
|
+
await signOut(user);
|
|
208
254
|
expect(await screen.findByRole('button', { name: 'Send me a code' })).toBeTruthy();
|
|
209
255
|
});
|
|
210
256
|
|
|
@@ -214,7 +260,7 @@ describe('standalone app', () => {
|
|
|
214
260
|
});
|
|
215
261
|
renderApp(client);
|
|
216
262
|
const user = userEvent.setup();
|
|
217
|
-
await user
|
|
263
|
+
await signOut(user);
|
|
218
264
|
expect((await screen.findByRole('alert')).textContent).toBe('Boom');
|
|
219
265
|
});
|
|
220
266
|
|
|
@@ -253,6 +299,39 @@ describe('standalone app', () => {
|
|
|
253
299
|
}
|
|
254
300
|
});
|
|
255
301
|
|
|
302
|
+
it('shows the unread count on the bell in the top bar, and the inbox and its settings on their pages', async () => {
|
|
303
|
+
const client = fakeClient();
|
|
304
|
+
vi.mocked(client.notifications.unreadCount).mockResolvedValue(3);
|
|
305
|
+
renderApp(client, '/home');
|
|
306
|
+
expect(await screen.findByRole('button', { name: 'Notifications, 3 unread' })).toBeTruthy();
|
|
307
|
+
cleanup();
|
|
308
|
+
renderApp(fakeClient(), '/notifications');
|
|
309
|
+
expect(await screen.findByRole('heading', { name: 'Notifications' })).toBeTruthy();
|
|
310
|
+
expect(screen.getByRole('link', { name: 'Choose what you get' }).getAttribute('href')).toBe(
|
|
311
|
+
'/settings/notifications',
|
|
312
|
+
);
|
|
313
|
+
cleanup();
|
|
314
|
+
const settings = fakeClient();
|
|
315
|
+
renderApp(settings, '/settings/notifications');
|
|
316
|
+
expect(await screen.findByRole('heading', { name: 'Notification settings' })).toBeTruthy();
|
|
317
|
+
expect(settings.notifications.preferences).toHaveBeenCalled();
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('has the bottom bar and Sign out under More below 1024px', async () => {
|
|
321
|
+
phoneWidth();
|
|
322
|
+
const client = fakeClient();
|
|
323
|
+
renderApp(client, '/home');
|
|
324
|
+
await screen.findByRole('heading', { name: 'Home' });
|
|
325
|
+
expect(document.querySelector('.hl-sidebar')).toBeNull();
|
|
326
|
+
const bar = screen.getByRole('navigation', { name: 'Main' });
|
|
327
|
+
expect(within(bar).getByRole('link', { name: 'Home' }).getAttribute('aria-current')).toBe(
|
|
328
|
+
'page',
|
|
329
|
+
);
|
|
330
|
+
await userEvent.click(within(bar).getByRole('button', { name: 'More' }));
|
|
331
|
+
await userEvent.click(screen.getByRole('button', { name: 'Sign out' }));
|
|
332
|
+
expect(client.logout).toHaveBeenCalled();
|
|
333
|
+
});
|
|
334
|
+
|
|
256
335
|
it('sends an address of a removed page to Home', async () => {
|
|
257
336
|
renderApp(fakeClient(), '/stores/7f2c1d5e-8a43-4b6f-9c1d-2e3f4a5b6c7d/products');
|
|
258
337
|
expect(await screen.findByRole('heading', { name: 'Home' })).toBeTruthy();
|
|
@@ -305,6 +384,61 @@ describe('embedded app', () => {
|
|
|
305
384
|
expect(screen.queryByRole('banner')).toBeNull();
|
|
306
385
|
expect(screen.queryByText('Acme Org')).toBeNull();
|
|
307
386
|
expect(screen.queryByRole('button', { name: 'Sign out' })).toBeNull();
|
|
387
|
+
// The bell sits beside the navigation.
|
|
388
|
+
expect(await screen.findByRole('button', { name: 'Notifications' })).toBeTruthy();
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it('has the bottom bar below 1024px, its links keeping Shopify’s query string', async () => {
|
|
392
|
+
phoneWidth();
|
|
393
|
+
// A page's own parameter (tab) stays behind; Shopify's go along.
|
|
394
|
+
embedded({}, '/home?host=abc&tab=x&shop=acme.myshopify.com&embedded=1');
|
|
395
|
+
await screen.findByRole('heading', { name: 'Home' });
|
|
396
|
+
const bar = screen.getByRole('navigation', { name: 'Main' });
|
|
397
|
+
expect(bar.classList.contains('hl-bottom-nav')).toBe(true);
|
|
398
|
+
const links = [...bar.querySelectorAll('a')];
|
|
399
|
+
const query = '?host=abc&shop=acme.myshopify.com&embedded=1';
|
|
400
|
+
expect(links.map((link) => link.getAttribute('href'))).toEqual([
|
|
401
|
+
`/home${query}`,
|
|
402
|
+
`/stores${query}`,
|
|
403
|
+
`/usage${query}`,
|
|
404
|
+
]);
|
|
405
|
+
expect(links[0]?.getAttribute('aria-current')).toBe('page');
|
|
406
|
+
// The bell stays; More has the theme switch and no Sign out.
|
|
407
|
+
expect(await screen.findByRole('button', { name: 'Notifications' })).toBeTruthy();
|
|
408
|
+
await userEvent.click(screen.getByRole('button', { name: 'More' }));
|
|
409
|
+
const sheet = screen.getByRole('dialog', { name: 'More' });
|
|
410
|
+
expect(within(sheet).getByRole('group', { name: 'Theme' })).toBeTruthy();
|
|
411
|
+
expect(within(sheet).queryByRole('button', { name: 'Sign out' })).toBeNull();
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
it('keeps Shopify’s parameters, and only those, on the tabs too', async () => {
|
|
415
|
+
embedded({}, '/home?host=abc&tab=x&shop=acme.myshopify.com');
|
|
416
|
+
await screen.findByRole('heading', { name: 'Home' });
|
|
417
|
+
const links = [...screen.getByRole('navigation', { name: 'Main' }).querySelectorAll('a')];
|
|
418
|
+
expect(links.map((link) => link.getAttribute('href'))).toEqual([
|
|
419
|
+
'/home?host=abc&shop=acme.myshopify.com',
|
|
420
|
+
'/stores?host=abc&shop=acme.myshopify.com',
|
|
421
|
+
'/usage?host=abc&shop=acme.myshopify.com',
|
|
422
|
+
]);
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it('switches to the dark theme from More, the bar and the sheet on the dark tokens', async () => {
|
|
426
|
+
phoneWidth();
|
|
427
|
+
embedded({}, '/home?host=abc');
|
|
428
|
+
await screen.findByRole('heading', { name: 'Home' });
|
|
429
|
+
const bar = screen.getByRole('navigation', { name: 'Main' });
|
|
430
|
+
expect(getComputedStyle(bar).getPropertyValue('--hl-surface')).toBe('#FFFFFF');
|
|
431
|
+
await userEvent.click(within(bar).getByRole('button', { name: 'More' }));
|
|
432
|
+
const sheet = screen.getByRole('dialog', { name: 'More' });
|
|
433
|
+
await userEvent.click(within(sheet).getByRole('button', { name: 'Dark theme' }));
|
|
434
|
+
try {
|
|
435
|
+
expect(document.documentElement.getAttribute('data-theme')).toBe('dark');
|
|
436
|
+
expect(getComputedStyle(bar).getPropertyValue('--hl-surface')).toBe('#1C1C21');
|
|
437
|
+
expect(getComputedStyle(sheet).getPropertyValue('--hl-text')).toBe('#F2F2F5');
|
|
438
|
+
} finally {
|
|
439
|
+
document.documentElement.removeAttribute('data-theme');
|
|
440
|
+
localStorage.clear();
|
|
441
|
+
}
|
|
308
442
|
});
|
|
309
443
|
|
|
310
444
|
it('marks the page so it is styled like Shopify admin, and the standalone one is not', async () => {
|