Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/2856/action icon #2857

Merged
merged 10 commits into from Jun 24, 2022
5 changes: 4 additions & 1 deletion visualization/app/app.module.ts
Expand Up @@ -58,6 +58,7 @@ import { UpdateEdgePreviewsEffect } from "./codeCharta/state/effects/updateEdgeP
import { ChangelogDialogModule } from "./codeCharta/ui/dialogs/changelogDialog/changelogDialog.module"
import { VersionService } from "./codeCharta/services/version/version.service"
import { HoveredNodePathPanelModule } from "./codeCharta/ui/toolBar/hoveredNodePathPanel/hoveredNodePathPanel.module"
import { ActionIconModule } from "./codeCharta/ui/actionIcon/actionIcon.module"

@NgModule({
imports: [
Expand Down Expand Up @@ -98,7 +99,9 @@ import { HoveredNodePathPanelModule } from "./codeCharta/ui/toolBar/hoveredNodeP
MetricChooserModule,
RibbonBarModule,
ChangelogDialogModule,
HoveredNodePathPanelModule
HoveredNodePathPanelModule,
ChangelogDialogModule,
ActionIconModule
],
providers: [
threeSceneServiceProvider,
Expand Down
@@ -0,0 +1 @@
<i role="button" [class]="icon"></i>
@@ -0,0 +1,23 @@
@use "../../../material/theme";

cc-action-icon {
display: inline-flex;
align-items: center;
cursor: pointer;
width: 24px;
height: 24px;
border-radius: 100%;
background-color: theme.$cc-primary-color;
font-size: 16px;
shaman-apprentice marked this conversation as resolved.
Show resolved Hide resolved

&:hover {
background-color: rgb(0, 124, 112);
shaman-apprentice marked this conversation as resolved.
Show resolved Hide resolved
}

i,
i.fa {
margin: auto;
line-height: 1.5;
color: white;
}
}
10 changes: 10 additions & 0 deletions visualization/app/codeCharta/ui/actionIcon/actionIcon.component.ts
@@ -0,0 +1,10 @@
import "./actionIcon.component.scss"
import { Component, Input } from "@angular/core"

@Component({
selector: "cc-action-icon",
template: require("./actionIcon.component.html")
})
export class ActionIconComponent {
@Input() icon: string
}
11 changes: 11 additions & 0 deletions visualization/app/codeCharta/ui/actionIcon/actionIcon.module.ts
@@ -0,0 +1,11 @@
import { CommonModule } from "@angular/common"
import { NgModule } from "@angular/core"
import { ActionIconComponent } from "./actionIcon.component"

@NgModule({
imports: [CommonModule],
declarations: [ActionIconComponent],
exports: [ActionIconComponent],
entryComponents: [ActionIconComponent]
})
export class ActionIconModule {}
@@ -1,9 +1 @@
<button
mat-mini-fab
class="export-3d-button"
aria-label="3d print map"
(click)="downloadStlFile()"
title="Download stl file for 3D printing"
>
<mat-icon class="button-icon">view_in_ar</mat-icon>
</button>
<cc-action-icon icon="fa fa-cube" title="Download stl file for 3D printing" (click)="downloadStlFile()"></cc-action-icon>
@@ -1,20 +1,3 @@
cc-export-threed-map-button {
margin-left: 8px;
.button-icon {
font-size: 16px;
line-height: 1.3;
}
span {
padding: 0;
margin: 0;
}
.mat-mini-fab {
height: 25px;
width: 25px;

.mat-button-wrapper {
display: block;
padding: 0;
}
}
}
@@ -1,6 +1,6 @@
import { TestBed } from "@angular/core/testing"
import { Export3DMapButtonComponent } from "./export3DMapButton.component"
import { fireEvent, render } from "@testing-library/angular"
import { fireEvent, render, screen } from "@testing-library/angular"
import { Export3DMapButtonModule } from "./export3DMapButton.module"
import { FileDownloader } from "../../util/fileDownloader"
import { ThreeSceneService } from "../codeMap/threeViewer/threeSceneService"
Expand Down Expand Up @@ -35,24 +35,23 @@ describe("Export3DMapButtonComponent", () => {
})

it("should start download on click", async function () {
const { container } = await render(Export3DMapButtonComponent, { excludeComponentDeclaration: true })
const { fixture } = await render(Export3DMapButtonComponent, { excludeComponentDeclaration: true })
// mock download and therefore only verify the Angular binding.
// A better approach would be, if the component would only fire an action
// and an https://ngrx.io/guide/effects would do the side effect and logic.
// Then we could test the logic in the effect without mocking a lot
// and the component wouldn't need to know anything about store values
// @ts-ignore
const mockedDownload = jest.spyOn(ng.probe(container).componentInstance, "downloadStlFile").mockImplementation(() => null)
const mockedDownload = jest.spyOn(fixture.componentInstance, "downloadStlFile").mockImplementation(() => null)

const downloadButton = container.querySelector(".export-3d-button")
const downloadButton = screen.getByRole("button")
expect(downloadButton).not.toBe(null)

fireEvent.click(downloadButton)
expect(mockedDownload).toHaveBeenCalledTimes(1)
})
it("should download STL file with the right file name", async function () {
const { container } = await render(Export3DMapButtonComponent, { excludeComponentDeclaration: true })
const downloadButton = container.querySelector(".export-3d-button")
await render(Export3DMapButtonComponent, { excludeComponentDeclaration: true })
const downloadButton = screen.getByRole("button")

const downloadData = jest.spyOn(FileDownloader, "downloadData").mockImplementation(() => null)
ThreeSceneService.mapMeshInstance = { getThreeMesh: jest.fn() } as unknown as CodeMapMesh
Expand Down
@@ -1,10 +1,10 @@
import { CommonModule } from "@angular/common"
import { NgModule } from "@angular/core"
import { Export3DMapButtonComponent } from "./export3DMapButton.component"
import { MaterialModule } from "../../../material/material.module"
import { ActionIconModule } from "../actionIcon/actionIcon.module"

@NgModule({
imports: [CommonModule, MaterialModule],
imports: [CommonModule, ActionIconModule],
declarations: [Export3DMapButtonComponent],
exports: [Export3DMapButtonComponent]
})
Expand Down
@@ -1,3 +1,3 @@
<button (click)="showGlobalConfiguration()" title="Global Configuration">
<span>Global Configuration</span> <i class="fa fa-cog cc-shadow"></i>
<span>Global Configuration</span> <cc-action-icon icon="fa fa-cog"></cc-action-icon>
</button>
@@ -1,16 +1,13 @@
@use "../../../../material/theme";

cc-global-configuration-button button {
display: inline-flex;
align-items: center;
margin: 0;

i {
background-color: theme.$cc-primary-color;
color: white;
border-radius: 100%;
padding: 5px;
font-size: 14px;
&:hover cc-action-icon {
background-color: rgb(0, 124, 112);
shaman-apprentice marked this conversation as resolved.
Show resolved Hide resolved
}

cc-action-icon {
margin-left: 4px;
}
}
Expand Down
@@ -1,13 +1,14 @@
import { NgModule } from "@angular/core"
import { MaterialModule } from "../../../../material/material.module"
import { ActionIconModule } from "../../actionIcon/actionIcon.module"
import { ResetSettingsButtonModule } from "../../resetSettingsButton/resetSettingsButton.module"
import { GlobalConfigurationButtonComponent } from "./globalConfigurationButton.component"
import { DisplayQualitySelectionModule } from "./globalConfigurationDialog/displayQualitySelection/displayQualitySelection.module"
import { GlobalConfigurationDialogComponent } from "./globalConfigurationDialog/globalConfigurationDialog.component"
import { MapLayoutSelectionModule } from "./globalConfigurationDialog/mapLayoutSelection/mapLayoutSelection.module"

@NgModule({
imports: [MaterialModule, ResetSettingsButtonModule, MapLayoutSelectionModule, DisplayQualitySelectionModule],
imports: [MaterialModule, ResetSettingsButtonModule, MapLayoutSelectionModule, DisplayQualitySelectionModule, ActionIconModule],
declarations: [GlobalConfigurationButtonComponent, GlobalConfigurationDialogComponent],
exports: [GlobalConfigurationButtonComponent],
entryComponents: [GlobalConfigurationButtonComponent, GlobalConfigurationDialogComponent]
Expand Down
2 changes: 0 additions & 2 deletions visualization/app/material/material.module.ts
Expand Up @@ -5,7 +5,6 @@ import { MatMenuModule } from "@angular/material/menu"
import { MatButtonModule } from "@angular/material/button"
import { MatDividerModule } from "@angular/material/divider"
import { MatTooltipModule } from "@angular/material/tooltip"
import { MatIconModule } from "@angular/material/icon"
import { MatButtonToggleModule } from "@angular/material/button-toggle"
import { MatDialogModule } from "@angular/material/dialog"
import { MatCardModule } from "@angular/material/card"
Expand All @@ -25,7 +24,6 @@ const materialModules = [
MatButtonModule,
MatDividerModule,
MatTooltipModule,
MatIconModule,
MatDialogModule,
MatCardModule,
MatButtonToggleModule,
Expand Down
1 change: 0 additions & 1 deletion visualization/app/material/material.scss
Expand Up @@ -10,7 +10,6 @@
@include mat.menu-theme(theme.$cc-theme);
@include mat.dialog-theme(theme.$cc-theme);
@include mat.tooltip-theme(theme.$cc-theme);
@include mat.icon-theme(theme.$cc-theme);
@include mat.checkbox-theme(theme.$cc-theme);
@include mat.toolbar-theme(theme.$cc-theme);
@include mat.input-theme(theme.$cc-theme);
Expand Down