-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
69 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { InjectionToken } from "@angular/core" | ||
|
||
export const dialogService = new InjectionToken("dialogService") | ||
|
||
export function dialogServiceFactory(index: any) { | ||
return index.get("dialogService") | ||
} | ||
|
||
export const dialogServiceProvider = { | ||
provide: "dialogService", | ||
useFactory: dialogServiceFactory, | ||
deps: ["$injector"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
visualization/app/codeCharta/ui/downloadButton/downloadButton.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<md-button class="toolbar-button" ng-click="$ctrl.downloadFile()" title="Download cc.json"> | ||
<button class="toolbar-button" style="transform: scale(0.93)" (click)="downloadFile()" title="Download cc.json"> | ||
<i class="fa fa-download"></i> | ||
</md-button> | ||
</button> |
6 changes: 2 additions & 4 deletions
6
visualization/app/codeCharta/ui/downloadButton/downloadButton.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
download-button-component { | ||
.small-action-button { | ||
margin-left: 0 !important; | ||
} | ||
.small-action-button { | ||
margin-left: 0; | ||
} |
62 changes: 34 additions & 28 deletions
62
visualization/app/codeCharta/ui/downloadButton/downloadButton.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,45 @@ | ||
import "./downloadButton.module" | ||
import { DownloadButtonController } from "./downloadButton.component" | ||
import { getService, instantiateModule } from "../../../../mocks/ng.mockhelper" | ||
import { Store } from "../../state/store/store" | ||
import { TestBed } from "@angular/core/testing" | ||
import { DownloadButtonComponent } from "./downloadButton.component" | ||
import { dialogServiceProvider } from "../../ajs-upgraded-providers" | ||
import { fireEvent, render, screen } from "@testing-library/angular" | ||
import { DialogService } from "../dialog/dialog.service" | ||
|
||
describe("DownloadButtonController", () => { | ||
let downloadButtonController: DownloadButtonController | ||
let dialogService: DialogService | ||
jest.mock("../dialog/dialog.service") | ||
|
||
beforeEach(() => { | ||
restartSystem() | ||
rebuildController() | ||
withMockedDialogService() | ||
describe("DownloadButtonController", () => { | ||
let _$mdDialog | ||
inject($mdDialog => { | ||
_$mdDialog = $mdDialog | ||
}) | ||
|
||
function restartSystem() { | ||
instantiateModule("app.codeCharta.ui.downloadButton") | ||
|
||
dialogService = getService<DialogService>("dialogService") | ||
} | ||
|
||
function rebuildController() { | ||
downloadButtonController = new DownloadButtonController(dialogService) | ||
} | ||
const dialogService = new DialogService(_$mdDialog) | ||
|
||
function withMockedDialogService() { | ||
dialogService = downloadButtonController["dialogService"] = jest.fn().mockReturnValue({ | ||
showDownloadDialog: jest.fn() | ||
})() | ||
} | ||
beforeEach(() => { | ||
Store["initialize"]() | ||
|
||
TestBed.configureTestingModule({ | ||
declarations: [DownloadButtonComponent], | ||
providers: [ | ||
dialogServiceProvider, | ||
{ | ||
provide: "$injector", | ||
useValue: { | ||
get: () => { | ||
return dialogService | ||
} | ||
} | ||
} | ||
] | ||
}) | ||
}) | ||
|
||
describe("downloadFile", () => { | ||
it("should call showDownloadDialog", () => { | ||
downloadButtonController.downloadFile() | ||
|
||
expect(dialogService.showDownloadDialog).toHaveBeenCalled() | ||
it("should call showDownloadDialog", async () => { | ||
await render(DownloadButtonComponent) | ||
const button = screen.getByRole("button") | ||
fireEvent.click(button) | ||
expect(dialogService.showDownloadDialog).toHaveBeenCalledTimes(1) | ||
}) | ||
}) | ||
}) |
19 changes: 8 additions & 11 deletions
19
visualization/app/codeCharta/ui/downloadButton/downloadButton.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
import "./downloadButton.component.scss" | ||
import { Component, Inject } from "@angular/core" | ||
import { DialogService } from "../dialog/dialog.service" | ||
|
||
export class DownloadButtonController { | ||
constructor(private dialogService: DialogService) { | ||
"ngInject" | ||
} | ||
@Component({ | ||
selector: "cc-download-button", | ||
template: require("./downloadButton.component.html"), | ||
styleUrls: ["/../downloadButton/downloadButton.component.scss"] | ||
}) | ||
export class DownloadButtonComponent { | ||
constructor(@Inject("dialogService") private dialogService: DialogService) {} | ||
|
||
downloadFile() { | ||
this.dialogService.showDownloadDialog() | ||
} | ||
} | ||
|
||
export const downloadButtonComponent = { | ||
selector: "downloadButtonComponent", | ||
template: require("./downloadButton.component.html"), | ||
controller: DownloadButtonController | ||
} |
8 changes: 0 additions & 8 deletions
8
visualization/app/codeCharta/ui/downloadButton/downloadButton.module.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters