Skip to content

Commit

Permalink
add MSW crud domains
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly-akamai committed Dec 16, 2024
1 parent 456b923 commit 9334909
Show file tree
Hide file tree
Showing 12 changed files with 352 additions and 47 deletions.
49 changes: 12 additions & 37 deletions packages/manager/src/dev-tools/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export async function loadDevTools(
seedContext[key] = seeds[key];
};

const seeds = await populateSeeds(emptyStore);
const seeds = await populateSeeds(seedContext);

const seedPromises = (Object.keys(
seedContext
Expand All @@ -84,44 +84,19 @@ export async function loadDevTools(

await mswDB.saveStore(seedContext ?? emptyStore, 'seedState');

// Merge the contexts
const stateKeys: (keyof MockState)[] = Object.keys(
emptyStore
) as (keyof MockState)[];

const mergedContext: MockState = {
...initialContext,
eventQueue: [
...initialContext.eventQueue,
...(seedContext?.eventQueue || []),
],
firewalls: [
...initialContext.firewalls,
...(seedContext?.firewalls || []),
],
linodeConfigs: [
...initialContext.linodeConfigs,
...(seedContext?.linodeConfigs || []),
],
linodes: [...initialContext.linodes, ...(seedContext?.linodes || [])],
notificationQueue: [
...initialContext.notificationQueue,
...(seedContext?.notificationQueue || []),
],
placementGroups: [
...initialContext.placementGroups,
...(seedContext?.placementGroups || []),
],
regionAvailability: [
...initialContext.regionAvailability,
...(seedContext?.regionAvailability || []),
],
regions: [...initialContext.regions, ...(seedContext?.regions || [])],
supportReplies: [
...initialContext.supportReplies,
...(seedContext?.supportReplies || []),
],
supportTickets: [
...initialContext.supportTickets,
...(seedContext?.supportTickets || []),
],
volumes: [...initialContext.volumes, ...(seedContext?.volumes || [])],
...stateKeys.reduce(
(acc, key) => ({
...acc,
[key]: [...initialContext[key], ...(seedContext?.[key] || [])],
}),
{}
),
};

const extraHandlers = extraMswPresets.reduce(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as React from 'react';
import { SupportLink } from 'src/components/SupportLink';

interface MessageLinkEntity {
fallback?: string;
message: null | string;
}

Expand All @@ -15,10 +16,10 @@ interface MessageLinkEntity {
* - render "contact support" strings as <Link>.
*/
export const FormattedEventMessage = (props: MessageLinkEntity) => {
const { message } = props;
const { fallback, message } = props;

if (!message) {
return null;
return fallback ? fallback : null;
}

return formatMessage(message);
Expand Down
14 changes: 8 additions & 6 deletions packages/manager/src/features/Events/factories/domain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ export const domain: PartialEventMap<'domain'> = {
),
},
domain_record_create: {
notification: (e) => (
<>
<FormattedEventMessage message={e.message} /> has been{' '}
<strong>added</strong> to <EventLink event={e} to="entity" />.
</>
),
notification: (e) => {
return (
<>
<FormattedEventMessage fallback="A record" message={e.message} /> has
been <strong>added</strong> to <EventLink event={e} to="entity" />.
</>
);
},
},
domain_record_delete: {
notification: (e) => (
Expand Down
2 changes: 2 additions & 0 deletions packages/manager/src/mocks/mockState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const getStateSeederGroups = (
};

export const emptyStore: MockState = {
domainRecords: [],
domains: [],
eventQueue: [],
firewalls: [],
linodeConfigs: [],
Expand Down
2 changes: 2 additions & 0 deletions packages/manager/src/mocks/presets/baseline/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from 'src/mocks/presets/crud/handlers/events';
import { linodeCrudPreset } from 'src/mocks/presets/crud/linodes';

import { domainCrudPreset } from '../crud/domains';
import { placementGroupsCrudPreset } from '../crud/placementGroups';
import { supportTicketCrudPreset } from '../crud/supportTickets';
import { volumeCrudPreset } from '../crud/volumes';
Expand All @@ -17,6 +18,7 @@ export const baselineCrudPreset: MockPresetBaseline = {
...placementGroupsCrudPreset.handlers,
...supportTicketCrudPreset.handlers,
...volumeCrudPreset.handlers,
...domainCrudPreset.handlers,

// Events.
getEvents,
Expand Down
24 changes: 24 additions & 0 deletions packages/manager/src/mocks/presets/crud/domains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
cloneDomain,
createDomain,
deleteDomains,
getDomains,
importDomain,
updateDomain,
} from 'src/mocks/presets/crud/handlers/domains';

import type { MockPresetCrud } from 'src/mocks/types';

export const domainCrudPreset: MockPresetCrud = {
group: { id: 'Domains' },
handlers: [
createDomain,
deleteDomains,
updateDomain,
getDomains,
cloneDomain,
importDomain,
],
id: 'domains:crud',
label: 'Domains CRUD',
};
Loading

0 comments on commit 9334909

Please sign in to comment.