Skip to content

Commit

Permalink
FIX: oppia#16119 Added a copy tooltip + corrected the save progress c…
Browse files Browse the repository at this point in the history
…ard indentation and padding (oppia#15989)

* save progress button behaviour

* added copy tooltip + card indentation

* added copy tooltip + card indentation

* improved copy-tooltip

* improved copy-tooltip

* improved copy-tooltip

* Update core/templates/pages/exploration-player-page/templates/lesson-information-card-modal.component.html

Co-authored-by: Rijuta Singh <[email protected]>

* Update core/templates/pages/exploration-player-page/templates/lesson-information-card-modal.component.css

Co-authored-by: Rijuta Singh <[email protected]>

* copy-tooltip

* front-end tests passed

* front-end tests passed

* used I18N translation and ngIf

* tooltip modification

* I18N translation

* new component

* declaration for component

* component changes

* component using ngbModal

* component

* component

* unit tests

* unit tests

* unit tests

* unit tests

* unit tests

* unit tests

* unit tests

* unit tests

* unit tests

* unit tests

* retrigger checks

* retrigger checks

* tests

* typescript tests

* generalizing copy-url component

* generalizing copy-url component

* generalizing copy-url component

* generalizing copy-url component

* generalizing copy-url component

* fixed typescript tests

* fixed typescript tests

* fixed typescript tests

* minor nits

* minor nits

* minor nits

Co-authored-by: Rijuta Singh <[email protected]>
  • Loading branch information
Shivkant-Chauhan and Rijuta-s authored Oct 15, 2022
1 parent 73f47c4 commit cf30a8d
Show file tree
Hide file tree
Showing 17 changed files with 251 additions and 146 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@
/core/templates/services/staleness-detection.service*.ts @oppia/lace-frontend-reviewers
/core/templates/services/validators.service*.ts @oppia/lace-frontend-reviewers
/core/templates/services/yaml.service*.ts @oppia/lace-frontend-reviewers
/core/templates/components/copy-url/ @oppia/lace-frontend-reviewers


# Forms pages.
Expand Down
2 changes: 2 additions & 0 deletions assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,8 @@
"I18N_SAVE_EXPLORATION_PROGRESS_TEXT_4": "You may lose your progress after 72 hours.",
"I18N_SAVE_EXPLORATION_PROGRESS_TEXT_5": "Write or copy the link below",
"I18N_SAVE_PROGRESS": "Log in or sign up to save your progress and play through the next lesson.",
"I18N_SAVE_PROGRESS_BUTTON_TEXT": "Copy",
"I18N_SAVE_PROGRESS_COPY_TOOLTIP": "Copied!",
"I18N_SAVE_PROGRESS_TEXT": "Save Progress",
"I18N_SHARE_LESSON": "Share this lesson",
"I18N_SHOW_LESS": "Show Less",
Expand Down
2 changes: 2 additions & 0 deletions assets/i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,8 @@
"I18N_SAVE_EXPLORATION_PROGRESS_TEXT_4": "Text displayed on the save progress menu of exploration lesson info modal telling the users that the progress URL generated will save their progress for the next 72 hours only.",
"I18N_SAVE_EXPLORATION_PROGRESS_TEXT_5": "Text displayed on the save progress menu of exploration lesson info modal prompting the users to write or copy the genrated URL.",
"I18N_SAVE_PROGRESS": "Text displayed at the end of a chapter to prompt the user to login or signup to save chapter progress.",
"I18N_SAVE_PROGRESS_BUTTON_TEXT": "Text displayed on the button in the Save progress card for copying the unique URL of the progress.",
"I18N_SAVE_PROGRESS_COPY_TOOLTIP": "Text that will be display in a tooltip for a second when the user clicks the copy button.",
"I18N_SAVE_PROGRESS_TEXT": "Text which appears on the save progress button and the save progress menu in the exploration lesson info modal.",
"I18N_SHARE_LESSON": "Text displayed before the buttons to share an exploration.",
"I18N_SHOW_LESS": "Text, which when clicked on, contracts the section it is a part of.",
Expand Down
75 changes: 75 additions & 0 deletions core/templates/components/copy-url/copy-url.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<div class="uid-copy">
<span class="unique-progress-id">{{ urlToCopy }}</span>
<span class="uid-btn-container" [ngClass]="{ 'copy-tooltip-margin' : showTooltip }">
<span class="uid-btn-message-box" *ngIf="showTooltip">{{ 'I18N_SAVE_PROGRESS_COPY_TOOLTIP' | translate }}</span>
<div class="uid-btn-message-arrow" *ngIf="showTooltip"></div>
<button type="button" class="btn btn-secondary uid-copy-btn" (click)="copyUrlButton()">{{ 'I18N_SAVE_PROGRESS_BUTTON_TEXT' | translate }}</button>
</span>
</div>


<style>
.uid-copy {
align-items: flex-end;
display: flex;
flex-direction: row;
justify-content: center;
margin-bottom: 30px;
width: 100%;
}

.unique-progress-id {
align-items: center;
border: 1px solid black;
border-radius: 5px;
display: flex;
flex-direction: row;
height: 100%;
padding: 5px;
word-break: break-word;
}

.uid-btn-container {
margin-left: 2%;
position: relative;
width: 20%;
}

.copy-tooltip-margin {
margin-top: -33px;
}

.uid-btn-message-box {
background-color: #00645c;
border-radius: 4px;
color: #fff;
cursor: default;
font-size: 14px;
font-style: Roboto, Arial, sans-serif;
padding: 8px 10px;
position: relative;
top: -5px;
}

.uid-btn-message-arrow {
background-color: #00645c;
color: #fff;
cursor: default;
height: 10px;
position: relative;
right: -45px;
top: -7px;
transform: rotate(45deg);
width: 10px;
}

.uid-copy-btn {
box-shadow: 1px 1px 2px 0 rgba(0, 100, 92, 0.8);
color: #00645c;
font-family: Roboto, sans-serif;
font-size: 14px;
font-weight: 700;
margin: 0 auto;
width: 100px;
}
</style>
75 changes: 75 additions & 0 deletions core/templates/components/copy-url/copy-url.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright 2022 The Oppia Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


/**
* @fileoverview Unit tests for Copy Exploration URL component
*/

import { Clipboard } from '@angular/cdk/clipboard';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ComponentOverviewComponent } from './copy-url.component';
import { I18nLanguageCodeService } from 'services/i18n-language-code.service';
import { MockTranslatePipe } from 'tests/unit-test-utils';

class MockI18nLanguageCodeService {
isCurrentLanguageRTL() {
return true;
}
}

describe('Copy Exploration URL component', function() {
let clipboard: Clipboard;
let component: ComponentOverviewComponent;
let fixture: ComponentFixture<ComponentOverviewComponent>;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
HttpClientTestingModule,
],
declarations: [
ComponentOverviewComponent,
MockTranslatePipe
],
providers: [
{
provide: I18nLanguageCodeService,
useClass: MockI18nLanguageCodeService
}
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ComponentOverviewComponent);
component = fixture.componentInstance;
fixture.detectChanges();
clipboard = TestBed.inject(Clipboard);
});

it('should correctly copy progress URL', () => {
spyOn(clipboard, 'copy').and.callThrough();
let explorationURL = 'https://oppia.org/progress/abcdef';
component.urlToCopy = explorationURL;

component.copyUrlButton();

expect(clipboard.copy).toHaveBeenCalledWith(
explorationURL);
});
});
43 changes: 43 additions & 0 deletions core/templates/components/copy-url/copy-url.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2022 The Oppia Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @fileoverview Component for the copy message tooltip.
*/

import { Component, Input } from '@angular/core';
import { Clipboard } from '@angular/cdk/clipboard';
import { I18nLanguageCodeService } from 'services/i18n-language-code.service';

@Component({
selector: 'copy-url',
templateUrl: './copy-url.component.html'
})

export class ComponentOverviewComponent {
@Input() urlToCopy !: string;
showTooltip: boolean = false;

constructor(
private clipboard: Clipboard,
private i18nLanguageCodeService: I18nLanguageCodeService) {}

copyUrlButton(): void {
this.clipboard.copy(this.urlToCopy);
this.showTooltip = true;
setTimeout(() => {
this.showTooltip = false;
}, 1000);
}
}
9 changes: 8 additions & 1 deletion core/templates/components/shared-component.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ import { SmartRouterModule } from 'hybrid-router-module-provider';
import { StaleTabInfoModalComponent } from './stale-tab-info/stale-tab-info-modal.component';
import { UnsavedChangesStatusInfoModalComponent } from './unsaved-changes-status-info/unsaved-changes-status-info-modal.component';
import { NgbModalModule } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule } from '@ngx-translate/core';
import { ComponentOverviewComponent } from './copy-url/copy-url.component';

@NgModule({
imports: [
Expand Down Expand Up @@ -202,7 +204,8 @@ import { NgbModalModule } from '@ng-bootstrap/ng-bootstrap';
AngularFireModule.initializeApp(AuthService.firebaseConfig),
AngularFireAuthModule,
MatProgressSpinnerModule,
NgbModalModule
NgbModalModule,
TranslateModule,
],

providers: [
Expand Down Expand Up @@ -336,6 +339,7 @@ import { NgbModalModule } from '@ng-bootstrap/ng-bootstrap';
OppiaVisualizationEnumeratedFrequencyTableComponent,
OppiaVisualizationFrequencyTableComponent,
ReviewTestPageComponent,
ComponentOverviewComponent,
VisualizationSortedTilesComponent,
],

Expand Down Expand Up @@ -462,6 +466,7 @@ import { NgbModalModule } from '@ng-bootstrap/ng-bootstrap';
OppiaVisualizationEnumeratedFrequencyTableComponent,
OppiaVisualizationFrequencyTableComponent,
ReviewTestPageComponent,
ComponentOverviewComponent,
VisualizationSortedTilesComponent,
],

Expand Down Expand Up @@ -599,6 +604,8 @@ import { NgbModalModule } from '@ng-bootstrap/ng-bootstrap';
OppiaVisualizationEnumeratedFrequencyTableComponent,
OppiaVisualizationFrequencyTableComponent,
ReviewTestPageComponent,
ComponentOverviewComponent,
TranslateModule,
VisualizationSortedTilesComponent,
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ <h3>Awesome!</h3>
Now that you're a published Oppia teacher, you can share your creation.
</p>
<div class="oppia-share-publish-link">
Here's your exploration link: <br>
<div (click)="selectText($event)">{{explorationLink}}</div>
<span *ngIf="explorationLinkCopied">Copied<i class="fa fa-check" aria-hidden="true"></i></span>
<p>Here's your exploration link:</p>
</div>
<copy-url [urlToCopy]="explorationLink"></copy-url>
<sharing-links layoutType="row post-publish-modal-sharing-links"
layoutAlignType="center center"
shareType="exploration"
Expand Down Expand Up @@ -67,30 +66,24 @@ <h3>Awesome!</h3>
display: inline;
}

.oppia-share-publish-body .oppia-share-publish-link .oppia-share-link-container {
align-items: flex-end;
display: flex;
justify-content: space-evenly;
margin: 10px;
}

.oppia-share-publish-body .oppia-share-publish-link div {
background-color: #fcfcfc;
border: 1px solid #d9d9d9;
border-radius: 4px;
cursor: pointer;
display: inline-block;
margin-bottom: 2px;
margin-top: 10px;
max-width: 350px;
overflow: hidden;
padding: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}

.oppia-share-publish-body .oppia-share-publish-link div:hover {
background-color: #f9f9f9;
}

.oppia-share-publish-body .oppia-share-publish-link span {
left: 481px;
position: absolute;
top: 124px;
}
}

.oppia-share-publish-body .oppia-share-publish-link i {
color: #3f9187;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ describe('Post Publish Modal Controller', function() {
}
};
}
const mockWindow = {
document: {
execCommand: (command: string) => {}
}
};

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
Expand Down Expand Up @@ -115,55 +111,4 @@ describe('Post Publish Modal Controller', function() {
component.cancel();
expect(dismissSpy).toHaveBeenCalledWith();
});

it('should add range from a click event', function() {
let removeAllRanges = jasmine.createSpy('removeAllRanges');
let addRange = jasmine.createSpy('addRange');
// This throws "Argument of type '{ removeAllRanges:
// jasmine.Spy<jasmine.Func>; addRange: jasmine.Spy<jasmine.Func>; }'
// is not assignable to parameter of type 'Selection'." This is because
// the type of the actual 'getSelection' function doesn't match the type
// of function we've mocked it to. We need to suppress this error because
// we need to mock 'getSelection' function to our function for testing
// purposes.
// @ts-expect-error
spyOn(window, 'getSelection').and.returnValue({
removeAllRanges: removeAllRanges,
addRange: addRange
});
spyOn(mockWindow.document, 'execCommand');

var firstChild = document.createElement('div');
var lastChild = document.createElement('div');
var element = document.createElement('div');
element.appendChild(firstChild);
element.appendChild(lastChild);

element.onclick = function(event) {
component.selectText(event);
};

element.click();

expect(removeAllRanges).toHaveBeenCalled();
expect(addRange).toHaveBeenCalledWith(document.createRange());
expect(mockWindow.document.execCommand).not.toHaveBeenCalled();
expect(component.explorationLinkCopied).toBe(true);
});

it('should throw error if selection is null', () => {
spyOn(window, 'getSelection').and.returnValue(null);

let firstChild = document.createElement('div');
let lastChild = document.createElement('div');
let element = document.createElement('div');
element.appendChild(firstChild);
element.appendChild(lastChild);

element.onclick = (event) => {
expect(() => component.selectText(event))
.toThrowError('Selection cannot be null');
};
element.click();
});
});
Loading

0 comments on commit cf30a8d

Please sign in to comment.