-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: create
tuiMaxSizeRejectionError
-pipe
- Loading branch information
1 parent
36ac5fc
commit 2cd06ac
Showing
6 changed files
with
78 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export function tuiSetLanguage(language: string): void { | ||
cy.get(`tui-language-switcher`, {log: false}).click(); | ||
cy.get(`tui-dropdown [tuiOption]`).contains(language, {matchCase: false}).click(); | ||
cy.get(`tui-language-switcher`, {log: false}).click({log: false}); | ||
cy.get(`tui-dropdown [tuiOption]`, {log: false}) | ||
.contains(language, {matchCase: false, log: false}) | ||
.click({force: true, log: false}); | ||
} |
76 changes: 39 additions & 37 deletions
76
projects/demo-integrations/cypress/tests/kit/input-files/input-files.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,47 +1,49 @@ | ||
describe(`InputFiles`, () => { | ||
it(`i18n of error "wrong-file-type"`, () => { | ||
cy.viewport(800, 500); | ||
cy.tuiVisit(`/components/input-files/API?accept=application/pdf`, { | ||
skipExpectUrl: true, | ||
hideNavigation: false, | ||
hideLanguageSwitcher: false, | ||
describe(`supports dynamic change of i18n for errors`, () => { | ||
it(`Wrong file type`, () => { | ||
cy.viewport(800, 500); | ||
cy.tuiVisit(`/components/input-files/API?accept=application/pdf`, { | ||
skipExpectUrl: true, | ||
hideNavigation: false, | ||
hideLanguageSwitcher: false, | ||
}); | ||
|
||
cy.get(`#demoContent input[type="file"]`).selectFile( | ||
`cypress/fixtures/stubs/web-api.svg`, | ||
); | ||
|
||
cy.get(`#demoContent tui-file`) | ||
.should(`contain.text`, `Wrong file type`) | ||
.matchImageSnapshot(`01-01-input-files-[english]-wrong-file-type`); | ||
|
||
cy.tuiSetLanguage(`dutch`); | ||
|
||
cy.get(`#demoContent tui-file`) | ||
.should(`contain.text`, `Verkeerd bestandsformaat`) | ||
.matchImageSnapshot(`01-02-input-files-[dutch]-wrong-file-type`); | ||
}); | ||
|
||
cy.get(`#demoContent input[type="file"]`).selectFile( | ||
`cypress/fixtures/stubs/web-api.svg`, | ||
); | ||
it(`File is too large`, () => { | ||
cy.viewport(850, 500); | ||
cy.tuiVisit(`/components/input-files/API?accept=image/*&maxFileSize=2000`, { | ||
skipExpectUrl: true, | ||
hideNavigation: false, | ||
hideLanguageSwitcher: false, | ||
}); | ||
|
||
cy.get(`#demoContent tui-file`) | ||
.should(`contain.text`, `Wrong file type`) | ||
.matchImageSnapshot(`01-01-input-files-[english]-wrong-file-type`); | ||
cy.get(`#demoContent input[type="file"]`).selectFile( | ||
`cypress/fixtures/stubs/web-api.svg`, | ||
); | ||
|
||
cy.tuiSetLanguage(`dutch`); | ||
cy.get(`#demoContent tui-file`) | ||
.should(`contain.text`, `File is too large 2 KB`) | ||
.matchImageSnapshot(`02-01-input-files-[english]-file-too-large`); | ||
|
||
cy.get(`#demoContent tui-file`) | ||
.should(`contain.text`, `Verkeerd bestandsformaat`) | ||
.matchImageSnapshot(`01-02-input-files-[dutch]-wrong-file-type`); | ||
}); | ||
cy.tuiSetLanguage(`dutch`); | ||
|
||
it(`i18n of error "File is too large"`, () => { | ||
cy.viewport(850, 500); | ||
cy.tuiVisit(`/components/input-files/API?accept=image/*&maxFileSize=2000`, { | ||
skipExpectUrl: true, | ||
hideNavigation: false, | ||
hideLanguageSwitcher: false, | ||
cy.get(`#demoContent tui-file`) | ||
.should(`contain.text`, `Bestandsgrootte overschreden 2 KB`) | ||
.matchImageSnapshot(`02-02-input-files-[dutch]-file-too-large`); | ||
}); | ||
|
||
cy.get(`#demoContent input[type="file"]`).selectFile( | ||
`cypress/fixtures/stubs/web-api.svg`, | ||
); | ||
|
||
cy.get(`#demoContent tui-file`) | ||
.should(`contain.text`, `File is too large 2 KB`) | ||
.matchImageSnapshot(`02-01-input-files-[english]-file-too-large`); | ||
|
||
cy.tuiSetLanguage(`dutch`); | ||
|
||
cy.get(`#demoContent tui-file`) | ||
.should(`contain.text`, `Bestandsgrootte overschreden 2 KB`) | ||
.matchImageSnapshot(`02-02-input-files-[dutch]-file-too-large`); | ||
}); | ||
}); |
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
29 changes: 29 additions & 0 deletions
29
projects/kit/components/input-files/max-size-rejection-error.pipe.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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {Inject, Pipe, PipeTransform} from '@angular/core'; | ||
import {TuiInjectionTokenType} from '@taiga-ui/cdk'; | ||
import {TUI_DIGITAL_INFORMATION_UNITS, TUI_INPUT_FILE_TEXTS} from '@taiga-ui/kit/tokens'; | ||
import {tuiFormatSize} from '@taiga-ui/kit/utils'; | ||
import {combineLatest, Observable} from 'rxjs'; | ||
import {map} from 'rxjs/operators'; | ||
|
||
@Pipe({name: `tuiMaxSizeRejectionError`}) | ||
export class TuiMaxSizeRejectionErrorPipe implements PipeTransform { | ||
constructor( | ||
@Inject(TUI_INPUT_FILE_TEXTS) | ||
private readonly inputFileTexts$: TuiInjectionTokenType< | ||
typeof TUI_INPUT_FILE_TEXTS | ||
>, | ||
@Inject(TUI_DIGITAL_INFORMATION_UNITS) | ||
private readonly units$: TuiInjectionTokenType< | ||
typeof TUI_DIGITAL_INFORMATION_UNITS | ||
>, | ||
) {} | ||
|
||
transform(maxFileSize: number): Observable<string> { | ||
return combineLatest([this.inputFileTexts$, this.units$]).pipe( | ||
map( | ||
([{maxSizeRejectionReason}, units]) => | ||
maxSizeRejectionReason + tuiFormatSize(units, maxFileSize), | ||
), | ||
); | ||
} | ||
} |