-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/8178 update UI country field to country location (#1660)
* chore: Add removed script * style: Update UI country labels, placeholders and button in countries modal * chore: Update english script * test: Add missing modal country test suite * 🤖 GITHUB ACTIONS * chore: Fix typo
- Loading branch information
1 parent
0e3c10b
commit 5b22136
Showing
56 changed files
with
221 additions
and
143 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
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
161 changes: 152 additions & 9 deletions
161
src/app/cdk/side-bar/modals/modal-country/modal-country.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,26 +1,169 @@ | ||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing' | ||
import { ComponentFixture, TestBed } from '@angular/core/testing' | ||
|
||
import { ModalCountryComponent } from './modal-country.component' | ||
import { HttpClientTestingModule } from '@angular/common/http/testing' | ||
import { RouterTestingModule } from '@angular/router/testing' | ||
import { WINDOW_PROVIDERS } from '../../../window' | ||
import { PlatformInfoService } from '../../../platform-info' | ||
import { ErrorHandlerService } from '../../../../core/error-handler/error-handler.service' | ||
import { SnackbarService } from '../../../snackbar/snackbar.service' | ||
import { MatSnackBar } from '@angular/material/snack-bar' | ||
import { | ||
MAT_DIALOG_DATA, | ||
MatDialog, | ||
MatDialogRef, | ||
} from '@angular/material/dialog' | ||
import { Overlay } from '@angular/cdk/overlay' | ||
import { RecordCountriesService } from '../../../../core/record-countries/record-countries.service' | ||
import { HarnessLoader, parallel } from '@angular/cdk/testing' | ||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed' | ||
import { ModalModule } from '../../../modal/modal.module' | ||
import { MatIconModule } from '@angular/material/icon' | ||
import { FormsModule, ReactiveFormsModule } from '@angular/forms' | ||
import { By } from '@angular/platform-browser' | ||
import { MatSelectModule } from '@angular/material/select' | ||
import { NoopAnimationsModule } from '@angular/platform-browser/animations' | ||
import { Address, CountriesEndpoint } from '../../../../types' | ||
import { PrivacySelectorModule } from '../../../privacy-selector/privacy-selector.module' | ||
import { SideBarModule } from '../../side-bar.module' | ||
import { MatButtonModule } from '@angular/material/button' | ||
import { Observable, of } from 'rxjs' | ||
import { ChangeDetectorRef } from '@angular/core' | ||
import { MatSelectHarness } from '@angular/material/select/testing' | ||
|
||
describe('ModalCountryComponent', () => { | ||
let component: ModalCountryComponent | ||
let fixture: ComponentFixture<ModalCountryComponent> | ||
let recordCountriesService: RecordCountriesService | ||
let loader: HarnessLoader | ||
|
||
beforeEach( | ||
waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ModalCountryComponent], | ||
}).compileComponents() | ||
}) | ||
) | ||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ | ||
FormsModule, | ||
HttpClientTestingModule, | ||
MatButtonModule, | ||
MatIconModule, | ||
MatSelectModule, | ||
ModalModule, | ||
NoopAnimationsModule, | ||
PrivacySelectorModule, | ||
ReactiveFormsModule, | ||
RouterTestingModule, | ||
SideBarModule, | ||
], | ||
declarations: [ModalCountryComponent], | ||
providers: [ | ||
{ provide: MatDialogRef, useValue: {} }, | ||
{ provide: MAT_DIALOG_DATA, useValue: {} }, | ||
WINDOW_PROVIDERS, | ||
ChangeDetectorRef, | ||
RecordCountriesService, | ||
PlatformInfoService, | ||
ErrorHandlerService, | ||
SnackbarService, | ||
MatSnackBar, | ||
MatDialog, | ||
Overlay, | ||
], | ||
}).compileComponents() | ||
}) | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ModalCountryComponent) | ||
component = fixture.componentInstance | ||
|
||
recordCountriesService = TestBed.inject(RecordCountriesService) | ||
const adressesResponse: Observable<CountriesEndpoint> = of({ | ||
errors: [], | ||
addresses: [], | ||
visibility: { visibility: 'PUBLIC' }, | ||
}) | ||
spyOn(recordCountriesService, 'getAddresses').and.returnValue( | ||
adressesResponse | ||
) | ||
loader = TestbedHarnessEnvironment.loader(fixture) | ||
|
||
fixture.detectChanges() | ||
}) | ||
|
||
it('should create', () => { | ||
it('should create country modal with title and button with text `Add a country or location`', () => { | ||
expect(component).toBeTruthy() | ||
expect( | ||
fixture.debugElement.nativeElement.querySelector('p').textContent | ||
).not.toBeNull() | ||
expect( | ||
fixture.debugElement.query(By.css('#add-link')).childNodes[1].nativeNode | ||
.textContent | ||
).toBe('Add a country or location') | ||
}) | ||
|
||
it('should add a country and the button text must update', () => { | ||
const addCountryButton = fixture.debugElement.query(By.css('#add-link')) | ||
addCountryButton.nativeElement.click() | ||
|
||
fixture.detectChanges() | ||
|
||
expect( | ||
fixture.debugElement.query(By.css('#add-link')).childNodes[1].nativeNode | ||
.textContent | ||
).toBe('Add another country or location') | ||
}) | ||
|
||
it('should display three countries with the next status disabled (source is not user), enabled and enabled', async () => { | ||
const adressesResponse: Observable<CountriesEndpoint> = of({ | ||
errors: [], | ||
addresses: getAddresses(), | ||
visibility: { visibility: 'PUBLIC' }, | ||
}) | ||
recordCountriesService.getAddresses = jasmine | ||
.createSpy() | ||
.and.returnValue(adressesResponse) | ||
|
||
component.id = '0000-0000-0000-000X' | ||
component.ngOnInit() | ||
|
||
const countriesForm = component.countryForm | ||
|
||
const addCountryButton = fixture.debugElement.query(By.css('#add-link')) | ||
await addCountryButton.nativeElement.click() | ||
|
||
fixture.detectChanges() | ||
|
||
const countriesSelects = await loader.getAllHarnesses(MatSelectHarness) | ||
await countriesSelects[2].open() | ||
await countriesSelects[2].clickOptions({ text: 'Mexico' }) | ||
|
||
const disabledStates = await parallel(() => | ||
countriesSelects.map((select) => select.isDisabled()) | ||
) | ||
|
||
expect(countriesForm.controls[1].value.country).toBe('Albania') | ||
expect(countriesForm.controls['new-0'].value.country).toBe('Mexico') | ||
expect(disabledStates.filter((value) => value).length).toBe(1) | ||
expect(countriesSelects.length).toBe(3) | ||
}) | ||
}) | ||
|
||
function getAddresses(): Address[] { | ||
return [ | ||
{ | ||
putCode: '1', | ||
countryName: 'Albania', | ||
source: '0000-0000-0000-000X', | ||
sourceName: 'Test Record', | ||
visibility: { | ||
visibility: 'PUBLIC', | ||
}, | ||
} as Address, | ||
{ | ||
putCode: '2', | ||
countryName: 'United States', | ||
source: '0000-0000-0000-000Z', | ||
sourceName: 'ORCID', | ||
visibility: { | ||
visibility: 'PRIVATE', | ||
}, | ||
} as Address, | ||
] | ||
} |
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
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
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
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
Oops, something went wrong.