-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
160 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.marked { | ||
color: #efc14e; | ||
} |
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,52 @@ | ||
import { computed, defineComponent, ref } from 'vue' | ||
|
||
// Значения взяты из https://jsonplaceholder.typicode.com/comments | ||
export const emails = [ | ||
'Eliseo@gardner.biz', | ||
'Jayne_Kuhic@sydney.com', | ||
'Nikita@garfield.biz', | ||
'Lew@alysha.tv', | ||
'Hayden@althea.biz', | ||
'Presley.Mueller@myrl.com', | ||
'Dallas@ole.me', | ||
'Mallory_Kunze@marie.org', | ||
'Meghan_Littel@rene.us', | ||
'Carmen_Keeling@caroline.name', | ||
'Veronica_Goodwin@timmothy.net', | ||
'Oswald.Vandervort@leanne.org', | ||
'Kariane@jadyn.tv', | ||
'Nathan@solon.io', | ||
'Maynard.Hodkiewicz@roberta.com', | ||
'Christine@ayana.info', | ||
'Preston_Hudson@blaise.tv', | ||
'Vincenza_Klocko@albertha.name', | ||
'Madelynn.Gorczany@darion.biz', | ||
'Mariana_Orn@preston.org', | ||
'Noemie@marques.me', | ||
'Khalil@emile.co.uk', | ||
'Sophia@arianna.co.uk', | ||
'Jeffery@juwan.us', | ||
'Isaias_Kuhic@jarrett.net', | ||
] | ||
|
||
export default defineComponent({ | ||
name: 'MarkedEmailsApp', | ||
|
||
setup() {}, | ||
|
||
template: ` | ||
<div> | ||
<div class="form-group"> | ||
<input type="search" aria-label="Search" /> | ||
</div> | ||
<ul aria-label="Emails"> | ||
<li> | ||
Eliseo@gardner.biz | ||
</li> | ||
<li class="marked"> | ||
Jayne_Kuhic@sydney.com | ||
</li> | ||
</ul> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Отмеченные Email-ы | ||
|
||
👷🏻 _Задача нормальной сложности_\ | ||
📚 _Закрепление материала_ | ||
|
||
<!--start_statement--> | ||
|
||
Требуется создать Vue приложение, которое выводит список Email-ов из массива `emails` и позволяет выполнять поиск по | ||
этому списку. Адреса в списке, содержащие строку поиска, должны выделяться классом `.marked`. | ||
|
||
_**Примечание:** задачу можно решить, проверяя Email прямо в шаблоне. Но в этом случае решение получается менее декларативным, возможно, с перегруженным шаблоном. Попробуйте | ||
использовать **вычисляемое свойство** `computed` так, чтобы в шаблоне можно было сразу вывести Email и знать, требуется ли ему маркировка._ | ||
|
||
### Результат | ||
|
||
<img src="https://i.imgur.com/DA8l8pP.gif" alt="Example"> | ||
|
||
<!--end_statement--> | ||
|
||
--- | ||
|
||
### Инструкция | ||
|
||
📝 Для решения задачи отредактируйте файл: `MarkedEmailsApp.js`. | ||
|
||
🚀 Команда запуска для ручного тестирования: `npm run dev`\ | ||
Приложение будет доступно на [http://localhost:5173/02-basics-2/40-marked-emails/](http://localhost:5173/02-basics-2/40-marked-emails/). | ||
|
||
✅ Доступно автоматическое тестирование: `npm test marked-emails` |
43 changes: 43 additions & 0 deletions
43
02-basics-2/40-marked-emails/__tests__/marked-emails.test.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,43 @@ | ||
import { describe, it, expect, beforeEach } from 'vitest' | ||
import { mount } from '@vue/test-utils' | ||
import type { VueWrapper, DOMWrapper } from '@vue/test-utils' | ||
import MarkedEmailsApp, { emails } from '@/MarkedEmailsApp.js' | ||
|
||
describe('MarkedEmailsApp', () => { | ||
let wrapper: VueWrapper | ||
let input: DOMWrapper<HTMLInputElement> | ||
let list: DOMWrapper<HTMLElement>[] | ||
|
||
beforeEach(() => { | ||
wrapper = mount(MarkedEmailsApp) | ||
input = wrapper.find('input[aria-label="Search"]') | ||
list = wrapper.findAll('ul[aria-label="Emails"] li') | ||
}) | ||
|
||
it('должно рендерить поле поиска и список Email-ов', () => { | ||
expect(wrapper.exists()).toBe(true) | ||
expect(list).toHaveLength(emails.length) | ||
for (let i = 0; i < emails.length; i++) { | ||
expect(list[i].text()).toBe(emails[i]) | ||
} | ||
}) | ||
|
||
it('не должно отмечать ни один email классом маркировки .marked, когда запрос поиска пустой', async () => { | ||
expect(list.every(item => item.classes('marked'))).toBeFalsy() | ||
}) | ||
|
||
it('должно отмечать Dallas@ole.me и Mallory_Kunze@marie.org классом маркировки .marked при поиске "all"', async () => { | ||
await input.setValue('all') | ||
expect(list).toHaveLength(emails.length) | ||
for (let i = 0; i < emails.length; i++) { | ||
const shouldMark = emails[i].includes('all') | ||
expect(list[i].classes('marked')).toBe(shouldMark) | ||
} | ||
}) | ||
|
||
it('должно отметить все email-ы классом маркировки .marked, когда запрос поиска "@"', async () => { | ||
await input.setValue('@') | ||
expect(list).toHaveLength(emails.length) | ||
expect(list.every(item => item.classes('marked'))).toBeTruthy() | ||
}) | ||
}) |
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,16 @@ | ||
<!doctype html> | ||
<html lang="ru"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>marked-emails</title> | ||
</head> | ||
<body> | ||
<div class="wrapper"> | ||
<div class="container"> | ||
<h1>Отмеченные Email-ы</h1> | ||
<div id="app"></div> | ||
</div> | ||
</div> | ||
<script type="module" src="./main.js"></script> | ||
</body> | ||
</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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import '@shgk/vue-course-ui/meetups/style.css' | ||
import { createApp } from 'vue' | ||
import MarkedEmailsApp from './MarkedEmailsApp.js' | ||
import './MarkedEmailsApp.css' | ||
|
||
createApp(MarkedEmailsApp).mount('#app') |
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,11 @@ | ||
{ | ||
"extends": "@shgk/vue-course-taskbook/configs/tsconfig.json", | ||
"include": ["**/*", "**/*.vue"], | ||
"files": [], | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"paths": { | ||
"@/*": ["./*"] | ||
} | ||
} | ||
} |