Skip to content

Commit

Permalink
Update naming from notification to notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
cRui861 authored and gingi committed Sep 7, 2023
1 parent a905a0b commit a210bf9
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 63 deletions.
4 changes: 2 additions & 2 deletions desktop/src/app/environment/desktop-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@azure/bonito-core";
import { StandardClock } from "@azure/bonito-core/lib/datetime";
import { createConsoleLogger } from "@azure/bonito-core/lib/logging";
import { MockNotifier } from "@azure/bonito-core/lib/notification/mock-notification";
import { AlertNotifier } from "@azure/bonito-core/lib/notification/alert-notifier";
import { DefaultFormLayoutProvider } from "@azure/bonito-ui/lib/components/form";
import { BrowserDependencyName, BrowserEnvironmentConfig, DefaultBrowserEnvironment } from "@azure/bonito-ui/lib/environment";
import BatchExplorerHttpClient from "@batch-flask/core/batch-explorer-http-client";
Expand Down Expand Up @@ -45,7 +45,7 @@ export function initDesktopEnvironment(
[BatchDependencyName.PoolService]: () =>
new LivePoolService(),
[DependencyName.Notifier]: () =>
new MockNotifier(), // TODO: update with real notification implementation
new AlertNotifier(), // TODO: update with real notification implementation
[DependencyName.ResourceGroupService]: () =>
new LiveResourceGroupService(),
[DependencyName.StorageAccountService]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createMockLogger } from "../../logging";
import { FakeResourceGroupService } from "../../resource-group";
import { FakeStorageAccountService } from "../../storage";
import { FakeSubscriptionService } from "../../subscription";
import { MockNotifier } from "../../notification/mock-notification";
import { AlertNotifier } from "../../notification/alert-notifier";
import { AbstractEnvironment } from "../abstract-environment";
import {
DependencyFactories,
Expand Down Expand Up @@ -160,7 +160,7 @@ describe("Environment tests", () => {
locationService: () => new FakeLocationService(),
loggerFactory: () => createMockLogger,
localizer: () => new FakeLocalizer(),
notifier: () => new MockNotifier(),
notifier: () => new AlertNotifier(),
resourceGroupService: () => new FakeResourceGroupService(),
storageAccountService: () => new FakeStorageAccountService(),
subscriptionService: () => new FakeSubscriptionService(),
Expand Down Expand Up @@ -190,7 +190,7 @@ describe("Environment tests", () => {
locationService: () => new FakeLocationService(),
loggerFactory: () => createMockLogger,
localizer: () => new FakeLocalizer(),
notifier: () => new MockNotifier(),
notifier: () => new AlertNotifier(),
resourceGroupService: () => new FakeResourceGroupService(),
storageAccountService: () => new FakeStorageAccountService(),
subscriptionService: () => new FakeSubscriptionService(),
Expand Down
2 changes: 1 addition & 1 deletion packages/bonito-core/src/environment/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Logger, LoggerFactory, LoggingContext } from "../logging";
import { ResourceGroupService } from "../resource-group";
import { StorageAccountService } from "../storage";
import { SubscriptionService } from "../subscription";
import { Notification as Notifier } from "../notification";
import { Notifier } from "../notification";

/**
* Represents the execution environment of the application. Acts as a
Expand Down
4 changes: 2 additions & 2 deletions packages/bonito-core/src/environment/mock-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createMockLogger } from "../logging";
import { FakeResourceGroupService } from "../resource-group";
import { FakeStorageAccountService } from "../storage";
import { FakeSubscriptionService } from "../subscription";
import { MockNotifier } from "../notification/mock-notification";
import { AlertNotifier } from "../notification/alert-notifier";
import { AbstractEnvironment } from "./abstract-environment";
import {
EnvironmentName,
Expand All @@ -30,7 +30,7 @@ export const mockDependencyFactories: DependencyFactories = {
resourceGroupService: () => new FakeResourceGroupService(),
storageAccountService: () => new FakeStorageAccountService(),
subscriptionService: () => new FakeSubscriptionService(),
notifier: () => new MockNotifier(),
notifier: () => new AlertNotifier(),
};

export class MockEnvironment<
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { initMockEnvironment } from "../../environment";
import { FakeNotifier } from "../fake-notifier";

describe("Fake notification tests", () => {
let notifier: FakeNotifier;

beforeEach(() => {
initMockEnvironment();
notifier = new FakeNotifier();
});

afterEach(() => {
jest.restoreAllMocks();
});

test("Each notifier function works as expected", () => {
notifier.expectInfo("Info Notification : This is an info", {});
notifier.info("Info Notification", "This is an info");

notifier.expectWarn("Warn Notification : This is a warning", {});
notifier.warn("Warn Notification", "This is a warning");

notifier.expectInProgress(
"In Progress Notification : Action in progress",
{}
);
notifier.inProgress("In Progress Notification", "Action in progress");

notifier.expectSuccess("Success Notification : This is a success", {});
notifier.success("Success Notification", "This is a success");

notifier.expectError("Error Notification : This is an error", {});
notifier.error("Error Notification", "This is an error");
});
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
Notification,
NotificationConfig,
LinkToReference,
PendingNotification,
} from "./notification";
Notifier,
} from "./notifier";

export class MockNotifier implements Notification {
export class AlertNotifier implements Notifier {
info(
title: string,
description: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {
Notification,
Notifier,
NotificationConfig,
NotificationLevel,
PendingNotification,
} from "./notification";
} from "./notifier";

export interface ExpectedNotification {
level: NotificationLevel;
notification: string;
config: NotificationConfig;
}

export class FakeNotification implements Notification {
export class FakeNotifier implements Notifier {
expectedNotifications: ExpectedNotification[] = [];

expectInfo(notification: string, config: NotificationConfig): void {
Expand Down Expand Up @@ -96,10 +96,10 @@ export class FakeNotification implements Notification {
expected.notification !== formattedNotification
) {
throw new Error(
`Expected message did not match actual.\n\nExpected:\n${FakeNotification._formatSummary(
`Expected message did not match actual.\n\nExpected:\n${FakeNotifier._formatSummary(
expected.level,
expected.notification
)}\n\nActual:\n${FakeNotification._formatSummary(
)}\n\nActual:\n${FakeNotifier._formatSummary(
level,
formattedNotification
)}`
Expand Down
2 changes: 1 addition & 1 deletion packages/bonito-core/src/notification/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./notification";
export * from "./notifier";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type NotificationLevel =

export type NotificationStatus = "success" | "error";

export interface Notification {
export interface Notifier {
info(
title: string,
description: string,
Expand Down
4 changes: 2 additions & 2 deletions packages/playground/src/demo/form/notification-demo.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { DemoPane } from "../../layout/demo-pane";
import { DefaultButton } from "@fluentui/react/lib/Button";
import * as React from "react";
import { Notification } from "@azure/bonito-core/lib/notification";
import { Notifier } from "@azure/bonito-core/lib/notification";
import { DependencyName } from "@azure/bonito-core";
import { inject } from "@azure/bonito-core/lib/environment";

export const NotificationDemo: React.FC = () => {
const notifier = inject<Notification>(DependencyName.Notifier);
const notifier = inject<Notifier>(DependencyName.Notifier);

return (
<DemoPane title="Notification">
Expand Down
4 changes: 2 additions & 2 deletions web/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { DependencyName } from "@azure/bonito-core/lib/environment";
import { MockHttpClient } from "@azure/bonito-core/lib/http";
import { HttpLocalizer } from "@azure/bonito-core/lib/localization";
import { createConsoleLogger } from "@azure/bonito-core/lib/logging";
import { MockNotifier } from "@azure/bonito-core/lib/notification/mock-notification";
import { AlertNotifier } from "@azure/bonito-core/lib/notification/alert-notifier";
import { DefaultBrowserEnvironment } from "@azure/bonito-ui";
import { DefaultFormLayoutProvider } from "@azure/bonito-ui/lib/components/form";
import {
Expand Down Expand Up @@ -61,7 +61,7 @@ export async function init(rootEl: HTMLElement): Promise<void> {
[DependencyName.HttpClient]: () => new MockHttpClient(),
[DependencyName.LocationService]: () =>
new FakeLocationService(),
[DependencyName.Notifier]: () => new MockNotifier(), // TODO: update with real notification implementation
[DependencyName.Notifier]: () => new AlertNotifier(), // TODO: update with real notification implementation
[BatchDependencyName.PoolService]: () => new FakePoolService(),
[DependencyName.ResourceGroupService]: () =>
new FakeResourceGroupService(),
Expand Down

0 comments on commit a210bf9

Please sign in to comment.