-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save history command in local storage. Some refactor to make the flow more reactive
- Loading branch information
Showing
10 changed files
with
348 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { browser, logging } from 'protractor'; | ||
|
||
import { AppPage } from '../app.po'; | ||
import { CommandLineComponent } from './command-line.po'; | ||
|
||
const command = "set test test" | ||
const command1 = "set test1 test1" | ||
const command2 = "set test2 test2" | ||
const commands = [command, command1, command2] | ||
|
||
describe('Command line', () => { | ||
let page: AppPage; | ||
let commandLine: CommandLineComponent | ||
|
||
beforeEach(() => { | ||
page = new AppPage(); | ||
commandLine = new CommandLineComponent() | ||
}); | ||
|
||
afterEach(() => { | ||
browser.executeScript('window.localStorage.clear();'); | ||
}) | ||
|
||
it('should check that history is correct [1]', async () => { | ||
await page.navigateTo() | ||
|
||
|
||
commands.forEach((val) => commandLine.sendCommand(val)) | ||
commandLine.upKey() | ||
commandLine.upKey() | ||
|
||
const value = await commandLine.getValue() | ||
return expect(value).toEqual(command1) | ||
|
||
}); | ||
|
||
it('should check that history is correct [2]', async () => { | ||
await page.navigateTo() | ||
|
||
|
||
commands.forEach((val) => commandLine.sendCommand(val)) | ||
commandLine.upKey() | ||
commandLine.downKey() | ||
|
||
const value = await commandLine.getValue() | ||
return expect(value).toEqual(command2) | ||
}); | ||
|
||
it('should check that history is correct [3]', async () => { | ||
await page.navigateTo() | ||
|
||
const array = new Array(50) | ||
|
||
commands.forEach((val) => commandLine.sendCommand(val)) | ||
array.forEach(() => commandLine.downKey()) | ||
|
||
|
||
const value = await commandLine.getValue() | ||
return expect(value).toEqual("") | ||
}); | ||
}) |
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,28 @@ | ||
import { browser, by, element, ElementFinder, Key, WebElement, WebElementPromise } from 'protractor'; | ||
|
||
export class CommandLineComponent { | ||
element: ElementFinder | ||
constructor() { | ||
this.element = element(by.tagName('tr-command-line')) | ||
} | ||
|
||
async sendCommand(command: string) { | ||
const input = this.element.$("input") | ||
await input.sendKeys(command) | ||
await input.sendKeys(Key.ENTER) | ||
} | ||
|
||
upKey() { | ||
const input = this.element.$("input") | ||
input.sendKeys(Key.ARROW_UP) | ||
} | ||
|
||
downKey() { | ||
const input = this.element.$("input") | ||
input.sendKeys(Key.ARROW_DOWN) | ||
} | ||
|
||
getValue() { | ||
return this.element.$("input").getAttribute('value') | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export enum SESSIONSTORAGEKEYS { | ||
HISTORYCOMMAND = 'HistoryCommand', | ||
} | ||
export const getFromLocalStorage = (key: SESSIONSTORAGEKEYS) => | ||
sessionStorage.getItem(key); | ||
|
||
export const setToLocalStorage = (key: SESSIONSTORAGEKEYS, value: string) => | ||
sessionStorage.setItem(key, value); |
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,2 @@ | ||
export const isNil = <T>(value: T): value is null => value === null; | ||
export const isNotNil = <T>(value: T): value is T => value !== null; |
30 changes: 13 additions & 17 deletions
30
src/app/features/command/command-line/command-line.component.html
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,22 +1,18 @@ | ||
<div class="command-line-container"> | ||
<input type="text" | ||
class="form-control" | ||
placeholder="Insert command" | ||
[formControl]="commandLine" | ||
(keyup.enter)="executeCommand(commandLine.value)" | ||
(keydown)="getHistory($event)"> | ||
<input #input type="text" class="form-control" placeholder="Insert command" [formControl]="commandLine" | ||
(keyup.enter)="executeCommandSubj$.next(commandLine.value)" (keydown.arrowup)="arrowUpClickSubj$.next($event)" | ||
(keydown.arrowdown)="arrowDownClickSubj$.next($event)" /> | ||
|
||
<div class="font-italic text-muted suggestions pl-2 mb-0 h-auto"> | ||
<small *ngIf="!commandLine.dirty || commandLine.value.length < 3">no command enter (min. 3 char)</small> | ||
<small *ngIf="commandLine.valid" class="suggestion"> {{ activeCommand?.suggestion }}</small> | ||
<small | ||
class="text-danger" | ||
*ngIf="!commandLine.valid | ||
&& commandLine.errors | ||
&& commandLine.errors.allowedCommand | ||
&& commandLine.errors.allowedCommand.value | ||
&& commandLine.errors.allowedCommand.value.length >= 3"> | ||
command not found | ||
<small *ngIf=" | ||
!commandLine.dirty || commandLine.value.length < commandLineMinLetter | ||
"> | ||
no command enter (min. 3 char) | ||
</small> | ||
<small *ngIf="commandLine.valid" class="suggestion"> | ||
{{ activeCommand?.suggestion }}</small> | ||
<small class="text-danger" *ngIf="isValidCommand()"> | ||
command not found | ||
</small> | ||
</div> | ||
</div> | ||
</div> |
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
4 changes: 4 additions & 0 deletions
4
src/app/features/command/command-line/command-line.interface.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,4 @@ | ||
export interface CommandsHistory { | ||
commandsHistory: Array<string>; | ||
commandsHistoryCursor: number; | ||
} |
Oops, something went wrong.