Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@
</button>
</ng-template>

<button type="button" class="m-actionBarItem" (click)="handleCopyPublicURL()">
<span class="m-actionBarItem-x-icon">
<svg class="t-icon" aria-hidden="true">
<use [attr.xlink:href]="duplicateIcon"></use>
</svg>
</span>
<span class="m-actionBarItem-x-text">Copy Public URL</span>
<label>
<textarea class="t-visuallyHidden" #fullPath>{{skillPublicUrl}}</textarea>
</label>
</button>

<button type="button" class="m-actionBarItemHorizontal m-actionBarItemHorizontal" [disabled]="!canSkillCreate">
<svg class="m-actionBarItemHorizontal-x-icon t-icon">
<use [attr.xlink:href]="dismissIcon"></use>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ import { ManageSkillActionBarHorizontalComponent } from "./manage-skill-action-b
<app-manage-skill-action-bar-horizontal
[skillUuid]="mySkillUuid"
[skillName]="mySkillName"
[skillPublicUrl]="mySkillPublicUrl"
[archived]="myArchived"
[published]="myPublished">
</app-manage-skill-action-bar-horizontal>`
})
class TestHostComponent {
mySkillUuid = "1234"
mySkillName = "my skill name"
mySkillPublicUrl = "mockUrl"
myArchived = false
myPublished = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class ManageSkillActionBarHorizontalComponent extends ManageRichSkillActi

@Input() skillUuid = ""
@Input() skillName = ""
@Input() skillPublicUrl = ""
@Input() archived = undefined
@Input() published = undefined

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,17 @@
</button>

</ng-template>

<button type="button" class="m-actionBarItem" (click)="handleCopyPublicURL()">
<span class="m-actionBarItem-x-icon">
<svg class="t-icon" aria-hidden="true">
<use [attr.xlink:href]="duplicateIcon"></use>
</svg>
</span>
<span class="m-actionBarItem-x-text">Copy Public URL</span>
<label>
<textarea class="t-visuallyHidden" #fullPath>{{skillPublicUrl}}</textarea>
</label>
</button>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import any = jasmine.any
<app-manage-skill-action-bar-vertical
[skillUuid]="mySkillUuid"
[skillName]="mySkillName"
[skillPublicUrl]="mySkillPublicUrl"
[archived]="myArchived"
[published]="myPublished">
</app-manage-skill-action-bar-vertical>`
})
class TestHostComponent {
mySkillUuid = "1234"
mySkillName = "my skill name"
mySkillPublicUrl = "mockUrl"
myArchived = false
myPublished = false
}
Expand Down Expand Up @@ -56,6 +58,8 @@ let childComponent: ManageSkillActionBarVerticalComponent


describe("ManageSkillActionBarVerticalComponent", () => {
let toastService: ToastService

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
Expand All @@ -80,6 +84,8 @@ describe("ManageSkillActionBarVerticalComponent", () => {
const appConfig = TestBed.inject(AppConfig)
AppConfig.settings = appConfig.defaultConfig() // This avoids the race condition on reading the config's whitelabel.toolName

toastService = TestBed.inject(ToastService)

createComponent(TestHostComponent)
}))

Expand Down Expand Up @@ -155,6 +161,7 @@ describe("ManageSkillActionBarVerticalComponent", () => {
childComponent.reloadSkill.pipe(first()).subscribe(
() => { clicked = true; return }
)

spyOn(window, "confirm").and.returnValue(true)

// Act
Expand All @@ -163,4 +170,19 @@ describe("ManageSkillActionBarVerticalComponent", () => {
// Assert
expect(clicked).toBeTruthy()
})

it("handleCopyPublicUrl should return", async (done) => {
// Arrange
let clipboardWriteTextSpy = spyOn(navigator.clipboard, "writeText").and.returnValue(Promise.resolve())
let showToastSpy = spyOn(toastService, "showToast").and.callFake(() => { done() })

// Act
childComponent.handleCopyPublicURL()

await clipboardWriteTextSpy

// Assert
expect(clipboardWriteTextSpy).toHaveBeenCalledWith("mockUrl")
expect(showToastSpy).toHaveBeenCalledWith("Success!", "URL copied to clipboard")
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class ManageSkillActionBarVerticalComponent extends ManageRichSkillAction

@Input() skillUuid = ""
@Input() skillName = ""
@Input() skillPublicUrl = ""
@Input() archived = undefined
@Input() published = undefined

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export abstract class ManageRichSkillActionBarComponent implements OnInit {

abstract skillUuid: string
abstract skillName: string
abstract skillPublicUrl: string
abstract archived: string | undefined
abstract published: string | undefined

Expand Down Expand Up @@ -127,6 +128,16 @@ export abstract class ManageRichSkillActionBarComponent implements OnInit {
}
}

handleCopyPublicURL(): void {
navigator.clipboard.writeText(this.skillPublicUrl)
.then(
() => this.toastService.showToast("Success!", "URL copied to clipboard")
)
.catch(
() => this.toastService.showToast("Error", "Could not copy to clipboard")
)
}

setEnableFlags(): void {
this.canSkillUpdate = this.authService.isEnabledByRoles(ButtonAction.SkillUpdate);
this.canSkillCreate = this.authService.isEnabledByRoles(ButtonAction.SkillCreate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<app-manage-skill-action-bar-vertical
[skillUuid]="getSkillUuid()"
[skillName]="getSkillName()"
[skillPublicUrl]="getSkillUrl()"
[archived]="getArchivedDate()"
[published]="getPublishedDate()"
(reloadSkill)="loadSkill()"
Expand All @@ -47,6 +48,7 @@ <h3 class="t-visuallyHidden" id="save-quicklinks">Quick Links</h3>
<app-manage-skill-action-bar-horizontal
[skillUuid]="getSkillUuid()"
[skillName]="getSkillName()"
[skillPublicUrl]="getSkillUrl()"
[archived]="getArchivedDate()"
[published]="getPublishedDate()"
(reloadSkill)="loadSkill()"
Expand Down