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

PER-9807-Design changes to archive invite #456

Merged
merged 7 commits into from
Oct 18, 2024
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 @@ -102,6 +102,10 @@
}

ngOnInit(): void {
if (this.pendingArchives.length && !this.pendingArchive) {
this.screen = 'create';

Check warning on line 106 in src/app/onboarding/components/create-new-archive/create-new-archive.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/onboarding/components/create-new-archive/create-new-archive.component.ts#L106

Added line #L106 was not covered by tests
}

if (this.pendingArchive) {
this.screen = 'goals';
this.progress.emit(1);
Expand Down Expand Up @@ -130,8 +134,8 @@

public setScreen(screen: NewArchiveScreen): void {
if (
this.pendingArchive &&
(screen === 'create' || screen === 'name-archive')
(this.pendingArchive || this.pendingArchives.length) &&
(screen === 'create' || screen === 'name-archive' || screen === 'start')
) {
this.goToInvitations();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="pending-archives">
<div class="text-container">
<p class="greeting">
Hello <b>{{ accountName }}</b
Hello <b class="bold">{{ accountName }}</b
>. Welcome to Permanent!
</p>
<p class="text">
Expand All @@ -13,15 +13,15 @@
</p>
</div>
<div class="pending-archives-container">
@for (archive of pendingArchives; track archive.archiveId) {
<pr-pending-archive
[archive]="archive"
(acceptArchiveOutput)="selectArchive(archive)"
[isSelected]="
selectedArchive && selectedArchive.archiveId === archive.archiveId
"
></pr-pending-archive>
}
<div class="pending-info">
@for (archive of pendingArchives; track archive.archiveId) {
<pr-pending-archive
[archive]="archive"
(acceptArchiveOutput)="selectArchive(archive)"
[isSelected]="isSelected(archive.archiveId)"
></pr-pending-archive>
}
</div>

<div class="buttons">
<div class="create-button">
Expand All @@ -44,6 +44,7 @@
(buttonClick)="next()"
[size]="'fill'"
[disabled]="!selectedArchive"
[style]="{ justifyContent: 'center' }"
>
Next</pr-button
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ p {

.greeting {
font-size: 56px;
font-family: 'UsualRegular', sans-serif;
font-family: 'UsualLight', sans-serif;
letter-spacing: -2px;
}

.bold {
font-family: 'UsualMedium', sans-serif;
}

.text {
font-size: 16px;
font-size: 0.6rem;
font-family: 'UsualRegular', sans-serif;
}

Expand All @@ -22,6 +27,7 @@ p {

.pending-archives {
display: flex;
justify-content: space-between;
gap: 64px;

@media screen and (max-width: 900px) {
Expand All @@ -30,7 +36,7 @@ p {
}

.pending-archives-container {
width: 500px;
width: 50%;
display: flex;
flex-direction: column;
justify-content: space-between;
Expand All @@ -48,7 +54,7 @@ p {
.buttons {
display: flex;
justify-content: space-between;
gap: 32px;
gap: 16px;
}

.next-button {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Shallow } from 'shallow-render';
import { AccountService } from '@shared/services/account/account.service';
import { ArchiveVO } from '@models/index';
import { ApiService } from '@shared/services/api/api.service';
import { OnboardingModule } from '../../onboarding.module';
import { GlamPendingArchivesComponent } from './glam-pending-archives.component';

Expand All @@ -17,10 +18,13 @@ describe('GlamPendingArchivesComponent', () => {
let shallow: Shallow<GlamPendingArchivesComponent>;

beforeEach(async () => {
shallow = new Shallow(GlamPendingArchivesComponent, OnboardingModule).mock(
AccountService,
mockAccountService,
);
shallow = new Shallow(GlamPendingArchivesComponent, OnboardingModule)
.mock(AccountService, mockAccountService)
.mock(ApiService, {
archive: {
accept: (archive: ArchiveVO) => Promise.resolve(),
},
});
});

it('should create the component', async () => {
Expand Down Expand Up @@ -50,18 +54,6 @@ describe('GlamPendingArchivesComponent', () => {
expect(archiveElements.length).toBe(2);
});

it('should update selectedArchive when selectArchive is called', async () => {
const { instance } = await shallow.render();
const archive: ArchiveVO = new ArchiveVO({
archiveId: 1,
fullName: 'Test Archive',
});

instance.selectArchive(archive);

expect(instance.selectedArchive).toBe(archive);
});

it('should emit createNewArchiveOutput when createNewArchive is called', async () => {
const { instance, outputs } = await shallow.render();
instance.createNewArchive();
Expand All @@ -81,4 +73,67 @@ describe('GlamPendingArchivesComponent', () => {

expect(outputs.nextOutput.emit).toHaveBeenCalledWith(selectedArchive);
});

it('should call api.archive.accept when selectArchive is called', async () => {
const { instance, inject } = await shallow.render();
const apiService = inject(ApiService);
spyOn(apiService.archive, 'accept').and.callThrough();

const archive: ArchiveVO = new ArchiveVO({
archiveId: 1,
fullName: 'Test Archive',
});

await instance.selectArchive(archive);

expect(apiService.archive.accept).toHaveBeenCalledWith(archive);
});

it('should add archive to acceptedArchives when selectArchive is called', async () => {
const { instance } = await shallow.render();
const archive: ArchiveVO = new ArchiveVO({
archiveId: 1,
fullName: 'Test Archive',
});

await instance.selectArchive(archive);

expect(instance.acceptedArchives.length).toBe(1);
expect(instance.acceptedArchives[0].archiveId).toBe(1);
});

it('should set selectedArchive if no archive was previously selected', async () => {
const { instance } = await shallow.render();
const archive: ArchiveVO = new ArchiveVO({
archiveId: 1,
fullName: 'Test Archive',
});

expect(instance.selectedArchive).toBeNull();
await instance.selectArchive(archive);

expect(instance.selectedArchive.archiveId).toBe(archive.archiveId);
});

it('should return true when isSelected is called for an accepted archive', async () => {
const { instance } = await shallow.render();
const archive: ArchiveVO = new ArchiveVO({
archiveId: 1,
fullName: 'Test Archive',
});

await instance.selectArchive(archive);

expect(instance.isSelected(1)).toBeTrue();
});

it('should return false when isSelected is called for a non-accepted archive', async () => {
const { instance } = await shallow.render();
const archive: ArchiveVO = new ArchiveVO({
archiveId: 1,
fullName: 'Test Archive',
});

expect(instance.isSelected(1)).toBeFalse();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { ArchiveVO } from '@models/index';
import { AccountService } from '@shared/services/account/account.service';
import { ApiService } from '@shared/services/api/api.service';

@Component({
selector: 'pr-glam-pending-archives',
Expand All @@ -16,8 +17,12 @@

public accountName: string = '';
public selectedArchive: ArchiveVO = null;
public acceptedArchives: ArchiveVO[] = [];

constructor(private account: AccountService) {
constructor(
private account: AccountService,
private api: ApiService,
) {
this.accountName = this.account.getAccount().fullName;
}

Expand All @@ -29,7 +34,19 @@
this.nextOutput.emit(this.selectedArchive);
}

selectArchive(archive: ArchiveVO): void {
this.selectedArchive = archive;
async selectArchive(archive: ArchiveVO) {
try {
await this.api.archive.accept(archive);
this.acceptedArchives.push(archive);
if (!this.selectedArchive) {
this.selectedArchive = archive;
}
} catch (error) {
console.error(error.message);

Check warning on line 45 in src/app/onboarding/components/glam-pending-archives/glam-pending-archives.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/onboarding/components/glam-pending-archives/glam-pending-archives.component.ts#L45

Added line #L45 was not covered by tests
}
}

isSelected(archiveId: string | number): boolean {
return !!this.acceptedArchives.find((a) => a.archiveId === archiveId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
[icon]="isSelected ? '/accept-green' : ''"
[color]="isSelected ? '#32D583' : ''"
>
Accept
{{ isSelected ? 'Accepted' : 'Accept' }}
</pr-button>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
.pending-archive {
display: flex;
justify-content: space-between;
margin-bottom: 1rem;
}

.accept-button {
Expand Down