From 223abb1a6b63dfa5ca8c13b4277642278e31f2f4 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Fri, 10 Sep 2021 22:49:37 +0800 Subject: [PATCH] test: update table --- .../__tests__/__snapshots__/demo.test.js.snap | 87 +- .../__snapshots__/index.test.js.snap | 3570 +++++++---------- components/table/Table.tsx | 15 +- .../table/__tests__/SelectionBox.test.js | 129 - .../table/__tests__/Table.pagination.test.js | 50 +- .../__tests__/Table.rowSelection.test.js | 225 +- .../table/__tests__/Table.sorter.test.js | 11 +- components/table/__tests__/Table.test.js | 6 +- .../Table.rowSelection.test.js.snap | 30 +- .../__tests__/__snapshots__/demo.test.js.snap | 42 +- .../__snapshots__/empty.test.js.snap | 12 +- .../__tests__/__snapshots__/demo.test.js.snap | 625 ++- components/vc-table/Table.tsx | 2 +- tests/__snapshots__/index.test.js.snap | 3 + 14 files changed, 2076 insertions(+), 2731 deletions(-) delete mode 100644 components/table/__tests__/SelectionBox.test.js diff --git a/components/empty/__tests__/__snapshots__/demo.test.js.snap b/components/empty/__tests__/__snapshots__/demo.test.js.snap index 68ebaeb98..725ab4afd 100644 --- a/components/empty/__tests__/__snapshots__/demo.test.js.snap +++ b/components/empty/__tests__/__snapshots__/demo.test.js.snap @@ -113,32 +113,47 @@ exports[`renders ./components/empty/demo/config-provider.vue correctly 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - + + + + + + + + + + +
Name -
- -
Age -
+
+ Name + + Age +
+ No data +
+
+
- - - - -
-
+
+
+
+

List

+
+ + +
+ +
+
@@ -153,39 +168,11 @@ exports[`renders ./components/empty/demo/config-provider.vue correctly 1`] = `
-
-
-
-
-

List

-
- - -
-
-
-
-
- - - - - - - -
-

No Data

- -
-
-
+
- - -
`; diff --git a/components/locale-provider/__tests__/__snapshots__/index.test.js.snap b/components/locale-provider/__tests__/__snapshots__/index.test.js.snap index f3964f4b4..7373b3ef9 100644 --- a/components/locale-provider/__tests__/__snapshots__/index.test.js.snap +++ b/components/locale-provider/__tests__/__snapshots__/index.test.js.snap @@ -505,54 +505,44 @@ exports[`Locale Provider should display the text as ar 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

لا توجد بيانات

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -1061,54 +1051,44 @@ exports[`Locale Provider should display the text as bg 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Няма данни

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -1617,54 +1597,44 @@ exports[`Locale Provider should display the text as ca 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Sense dades

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -2173,54 +2143,44 @@ exports[`Locale Provider should display the text as cs 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Žádná data

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -2729,54 +2689,44 @@ exports[`Locale Provider should display the text as da 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Ingen data

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -3285,54 +3235,44 @@ exports[`Locale Provider should display the text as de 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Keine Daten

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -3841,54 +3781,44 @@ exports[`Locale Provider should display the text as el 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Δεν υπάρχουν δεδομένα

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -4397,54 +4327,44 @@ exports[`Locale Provider should display the text as en 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

No Data

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -4953,54 +4873,44 @@ exports[`Locale Provider should display the text as en-gb 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

No data

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -5509,54 +5419,44 @@ exports[`Locale Provider should display the text as es 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

No hay datos

- + + +
Name + +
+ + + Age + + + + + + + + Sin datos + + + + + +
+
-
-
- - - + + `; @@ -6065,54 +5965,44 @@ exports[`Locale Provider should display the text as et 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Andmed puuduvad

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -6621,54 +6511,44 @@ exports[`Locale Provider should display the text as fa 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

داده‌ای موجود نیست

- + + +
Name + +
+ + + Age + + + + + + + + بدون داده + + + + + +
+
-
-
- - - + + `; @@ -7177,54 +7057,44 @@ exports[`Locale Provider should display the text as fi 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Ei kohteita

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -7733,54 +7603,44 @@ exports[`Locale Provider should display the text as fr 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Aucune donnée

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -8289,54 +8149,44 @@ exports[`Locale Provider should display the text as fr 2`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Aucune donnée

- + + +
Name + +
+ + + Age + + + + + + + + Aucune donnée + + + + + +
+
-
-
- - - + + `; @@ -8845,54 +8695,44 @@ exports[`Locale Provider should display the text as he 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

אין מידע

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -9401,54 +9241,44 @@ exports[`Locale Provider should display the text as hi 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

कोई आकड़ा उपलब्ध नहीं है

- + + +
Name + +
+ + + Age + + + + + + + + कोई जानकारी नहीं + + + + + +
+
-
-
- - - + + `; @@ -9957,54 +9787,44 @@ exports[`Locale Provider should display the text as hr 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Nema podataka

- + + +
Name + +
+ + + Age + + + + + + + + Nema podataka + + + + + +
+
-
-
- - - + + `; @@ -10513,54 +10333,44 @@ exports[`Locale Provider should display the text as hu 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Nincs adat

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -11069,54 +10879,44 @@ exports[`Locale Provider should display the text as hy-am 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Տվյալներ չկան

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -11625,54 +11425,44 @@ exports[`Locale Provider should display the text as id 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Tidak ada data

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -12181,54 +11971,44 @@ exports[`Locale Provider should display the text as is 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Engin gögn

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -12737,54 +12517,44 @@ exports[`Locale Provider should display the text as it 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Nessun dato

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -13293,54 +13063,44 @@ exports[`Locale Provider should display the text as ja 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

データがありません

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -13849,54 +13609,44 @@ exports[`Locale Provider should display the text as kn 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

No Data

- + + +
Name + +
+ + + Age + + + + + + + + ಮಾಹಿತಿ ಇಲ್ಲ + + + + + +
+
-
-
- - - + + `; @@ -14405,54 +14155,44 @@ exports[`Locale Provider should display the text as ko 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

데이터 없음

- + + +
Name + +
+ + + Age + + + + + + + + 데이터 없음 + + + + + +
+
-
-
- - - + + `; @@ -14961,54 +14701,44 @@ exports[`Locale Provider should display the text as ku-iq 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Agahî tune

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -15517,54 +15247,44 @@ exports[`Locale Provider should display the text as lv 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Nav datu

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -16073,54 +15793,44 @@ exports[`Locale Provider should display the text as mk 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Нема податоци

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -16629,54 +16339,44 @@ exports[`Locale Provider should display the text as mn-mn 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Мэдээлэл байхгүй байна

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -17185,54 +16885,44 @@ exports[`Locale Provider should display the text as ms-my 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Tiada data

- + + +
Name + +
+ + + Age + + + + + + + + Tiada data + + + + + +
+
-
-
- - - + + `; @@ -17741,54 +17431,44 @@ exports[`Locale Provider should display the text as nb 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Ingen data

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -18297,54 +17977,44 @@ exports[`Locale Provider should display the text as ne-np 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

डाटा छैन

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -18853,54 +18523,44 @@ exports[`Locale Provider should display the text as nl 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Geen gegevens

- + + +
Name + +
+ + + Age + + + + + + + + Geen data + + + + + +
+
-
-
- - - + + `; @@ -19409,54 +19069,44 @@ exports[`Locale Provider should display the text as nl-be 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Geen gegevens

- + + +
Name + +
+ + + Age + + + + + + + + Geen data + + + + + +
+
-
-
- - - + + `; @@ -19965,54 +19615,44 @@ exports[`Locale Provider should display the text as pl 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Brak danych

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -20521,54 +20161,44 @@ exports[`Locale Provider should display the text as pt 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Sem resultados

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -21077,54 +20707,44 @@ exports[`Locale Provider should display the text as pt-br 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Não há dados

- + + +
Name + +
+ + + Age + + + + + + + + Sem conteúdo + + + + + +
+
-
-
- - - + + `; @@ -21633,54 +21253,44 @@ exports[`Locale Provider should display the text as ro 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Fără date

- + + +
Name + +
+ + + Age + + + + + + + + Nu există date + + + + + +
+
-
-
- - - + + `; @@ -22189,54 +21799,44 @@ exports[`Locale Provider should display the text as ru 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Нет данных

- + + +
Name + +
+ + + Age + + + + + + + + Нет данных + + + + + +
+
-
-
- - - + + `; @@ -22745,54 +22345,44 @@ exports[`Locale Provider should display the text as sk 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Žiadne dáta

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -23301,54 +22891,44 @@ exports[`Locale Provider should display the text as sl 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Ni podatkov

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -23857,54 +23437,44 @@ exports[`Locale Provider should display the text as sr 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Nema podataka

- + + +
Name + +
+ + + Age + + + + + + + + Nema podataka + + + + + +
+
-
-
- - - + + `; @@ -24413,54 +23983,44 @@ exports[`Locale Provider should display the text as sv 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Ingen data

- + + +
Name + +
+ + + Age + + + + + + + + Ingen data + + + + + +
+
-
-
- - - + + `; @@ -24969,54 +24529,44 @@ exports[`Locale Provider should display the text as ta 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

தகவல் இல்லை

- + + +
Name + +
+ + + Age + + + + + + + + தகவல் இல்லை + + + + + +
+
-
-
- - - + + `; @@ -25525,54 +25075,44 @@ exports[`Locale Provider should display the text as th 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

ไม่มีข้อมูล

- + + +
Name + +
+ + + Age + + + + + + + + ไม่มีข้อมูล + + + + + +
+
-
-
- - - + + `; @@ -26081,54 +25621,44 @@ exports[`Locale Provider should display the text as tr 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Veri Yok

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -26637,54 +26167,44 @@ exports[`Locale Provider should display the text as uk 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Даних немає

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -27193,54 +26713,44 @@ exports[`Locale Provider should display the text as vi 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

Trống

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -27749,54 +27259,44 @@ exports[`Locale Provider should display the text as zh-cn 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

暂无数据

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; @@ -28305,53 +27805,43 @@ exports[`Locale Provider should display the text as zh-tw 1`] = `
-
+
-
- -
- - - - - +
+
+
+ - - - - - -
Name -
- -
Age -
- -
-
-
-
-
- - - - - - - -
-

無此資料

- + + +
Name + +
+ + + Age + + + + + + + + No data + + + + + +
+
-
-
- - - + + `; diff --git a/components/table/Table.tsx b/components/table/Table.tsx index 2462729b5..35261e7e1 100644 --- a/components/table/Table.tsx +++ b/components/table/Table.tsx @@ -35,7 +35,7 @@ import defaultLocale from '../locale/en_US'; import type { SizeType } from '../config-provider'; import devWarning from '../vc-util/devWarning'; import type { PropType } from 'vue'; -import { reactive } from 'vue'; +import { reactive, ref } from 'vue'; import { computed, defineComponent, toRef, watchEffect } from 'vue'; import type { DefaultRecordType } from '../vc-table/interface'; import useBreakpoint from '../_util/hooks/useBreakpoint'; @@ -237,7 +237,7 @@ const InteralTable = defineComponent< 'customFilterIcon', 'customFilterDropdown', ], - setup(props, { attrs, slots }) { + setup(props, { attrs, slots, expose }) { devWarning( !(typeof props.rowKey === 'function' && props.rowKey.length > 1), 'Table', @@ -497,7 +497,9 @@ const InteralTable = defineComponent< mergedRowClassName, ); }; - + expose({ + selectedKeySet, + }); const expandIconColumnIndex = computed(() => { // Adjust expand icon index, no overwrite expandIconColumnIndex if set. if (expandType.value === 'nest' && props.expandIconColumnIndex === undefined) { @@ -633,11 +635,16 @@ const InteralTable = defineComponent< const Table = defineComponent({ name: 'ATable', inheritAttrs: false, - setup(_props, { attrs, slots }) { + setup(_props, { attrs, slots, expose }) { + const table = ref(); + expose({ + table, + }); return () => { const columns = (attrs.columns || convertChildrenToColumns(slots.default?.())) as ColumnsType; return ( { - return Vue.reactive({ - selectedRowKeys: selectedRowKeys || [], - selectionDirty: false, - }); -}; - -describe('SelectionBox', () => { - it('unchecked by selectedRowKeys ', () => { - const wrapper = mount(SelectionBox, { - props: { - store: getDefaultStore(), - rowIndex: '1', - disabled: false, - onChange: () => {}, - defaultSelection: [], - }, - listeners: { - change: () => {}, - }, - sync: false, - }); - - expect(wrapper.vm.checked).toEqual(false); - }); - - it('checked by selectedRowKeys ', () => { - const wrapper = mount(SelectionBox, { - props: { - store: getDefaultStore(['1']), - rowIndex: '1', - disabled: false, - onChange: () => {}, - defaultSelection: [], - }, - sync: false, - }); - - expect(wrapper.vm.checked).toEqual(true); - }); - - it('checked by defaultSelection', () => { - const wrapper = mount(SelectionBox, { - props: { - store: getDefaultStore(), - rowIndex: '1', - disabled: false, - onChange: () => {}, - defaultSelection: ['1'], - }, - sync: false, - }); - expect(wrapper.vm.checked).toEqual(true); - }); - - it('checked when store change', () => { - const store = getDefaultStore(); - const wrapper = mount(SelectionBox, { - props: { - store, - rowIndex: '1', - disabled: false, - onChange: () => {}, - defaultSelection: [], - }, - sync: false, - }); - - store.selectedRowKeys = ['1']; - store.selectionDirty = true; - - expect(wrapper.vm.checked).toEqual(true); - }); - - it('passes props to Checkbox', done => { - const checkboxProps = { - name: 'testName', - id: 'testId', - }; - const wrapper = mount(SelectionBox, { - props: { - store: getDefaultStore(), - rowIndex: '1', - disabled: false, - onChange: () => {}, - defaultSelection: ['1'], - ...checkboxProps, - }, - sync: false, - }); - Vue.nextTick(() => { - wrapper.findAllComponents({ name: 'ACheckbox' }).forEach(box => { - expect(box.props().name).toEqual(checkboxProps.name); - expect(box.props().id).toEqual(checkboxProps.id); - }); - done(); - }); - }); - - it('passes props to Radios', done => { - const radioProps = { - name: 'testName', - id: 'testId', - }; - const wrapper = mount(SelectionBox, { - props: { - store: getDefaultStore(), - rowIndex: '1', - disabled: false, - onChange: () => {}, - defaultSelection: ['1'], - type: 'radio', - ...radioProps, - }, - sync: false, - }); - Vue.nextTick(() => { - wrapper.findAllComponents({ name: 'ARadio' }).forEach(radio => { - expect(radio.props().name).toEqual(radioProps.name); - expect(radio.props().id).toEqual(radioProps.id); - }); - done(); - }); - }); -}); diff --git a/components/table/__tests__/Table.pagination.test.js b/components/table/__tests__/Table.pagination.test.js index bec108eed..83f10d7d5 100644 --- a/components/table/__tests__/Table.pagination.test.js +++ b/components/table/__tests__/Table.pagination.test.js @@ -2,6 +2,7 @@ import { mount } from '@vue/test-utils'; import Table from '..'; import * as Vue from 'vue'; import { asyncExpect } from '@/tests/utils'; +import { sleep } from '../../../tests/utils'; describe('Table.pagination', () => { const columns = [ @@ -33,7 +34,7 @@ describe('Table.pagination', () => { } function renderedNames(wrapper) { - return wrapper.findAllComponents({ name: 'TableRow' }).map(row => { + return wrapper.findAllComponents({ name: 'BodyRow' }).map(row => { return row.props().record.name; }); } @@ -76,7 +77,7 @@ describe('Table.pagination', () => { }); }); - xit('paginate data', done => { + it('paginate data', done => { const wrapper = mount(Table, getTableOptions()); Vue.nextTick(() => { expect(renderedNames(wrapper)).toEqual(['Jack', 'Lucy']); @@ -89,7 +90,7 @@ describe('Table.pagination', () => { }); }); - xit('repaginates when pageSize change', () => { + it('repaginates when pageSize change', () => { const wrapper = mount(Table, getTableOptions()); wrapper.setProps({ pagination: { pageSize: 1 } }); Vue.nextTick(() => { @@ -97,7 +98,7 @@ describe('Table.pagination', () => { }); }); - xit('fires change event', done => { + it('fires change event', done => { const handleChange = jest.fn(); const handlePaginationChange = jest.fn(); const noop = () => {}; @@ -108,8 +109,8 @@ describe('Table.pagination', () => { ...pagination, onChange: handlePaginationChange, onShowSizeChange: noop, - onChange: handleChange, }, + onChange: handleChange, }), ); Vue.nextTick(() => { @@ -131,6 +132,7 @@ describe('Table.pagination', () => { { key: 2, name: 'Tom' }, { key: 3, name: 'Jerry' }, ], + action: 'paginate', }, ); @@ -156,7 +158,7 @@ describe('Table.pagination', () => { // https://github.com/ant-design/ant-design/issues/4532 // https://codepen.io/afc163/pen/pWVRJV?editors=001 - xit('should display pagination as prop pagination change between true and false', async () => { + it('should display pagination as prop pagination change between true and false', async () => { const wrapper = mount(Table, getTableOptions()); await asyncExpect(() => { expect(wrapper.findAll('.ant-pagination')).toHaveLength(1); @@ -182,8 +184,8 @@ describe('Table.pagination', () => { }); await asyncExpect(() => { expect(wrapper.findAll('.ant-pagination')).toHaveLength(1); - expect(wrapper.findAll('.ant-pagination-item')).toHaveLength(1); // pageSize will be 10 - expect(renderedNames(wrapper)).toHaveLength(4); + expect(wrapper.findAll('.ant-pagination-item')).toHaveLength(2); // pageSize will be 10 + expect(renderedNames(wrapper)).toEqual(['Tom', 'Jerry']); }); }); @@ -202,30 +204,30 @@ describe('Table.pagination', () => { }); }); - xit('specify the position of pagination', async () => { - const wrapper = mount(Table, getTableOptions({ pagination: { position: 'top' } })); + it('specify the position of pagination', async () => { + const wrapper = mount(Table, getTableOptions({ pagination: { position: ['topLeft'] } })); await asyncExpect(() => { expect(wrapper.findAll('.ant-spin-container > *')).toHaveLength(2); - expect(wrapper.findAll('.ant-spin-container > *')[0].findAll('.ant-pagination')).toHaveLength( - 1, - ); - wrapper.setProps({ pagination: { position: 'bottom' } }); + expect(wrapper.findAll('.ant-pagination')).toHaveLength(1); + wrapper.setProps({ pagination: { position: 'bottomRight' } }); }, 0); await asyncExpect(() => { expect(wrapper.findAll('.ant-spin-container > *')).toHaveLength(2); - expect(wrapper.findAll('.ant-spin-container > *')[1].findAll('.ant-pagination')).toHaveLength( - 1, - ); - wrapper.setProps({ pagination: { position: 'both' } }); + expect(wrapper.findAll('.ant-pagination')).toHaveLength(1); + wrapper.setProps({ pagination: { position: ['topLeft', 'bottomRight'] } }); }, 0); await asyncExpect(() => { expect(wrapper.findAll('.ant-spin-container > *')).toHaveLength(3); - expect(wrapper.findAll('.ant-spin-container > *')[0].findAll('.ant-pagination')).toHaveLength( - 1, - ); - expect(wrapper.findAll('.ant-spin-container > *')[2].findAll('.ant-pagination')).toHaveLength( - 1, - ); + expect(wrapper.findAll('.ant-pagination')).toHaveLength(2); }, 0); + wrapper.setProps({ pagination: { position: ['none', 'none'] } }); + await sleep(); + expect(wrapper.findAll('.ant-pagination')).toHaveLength(0); + wrapper.setProps({ pagination: { position: ['invalid'] } }); + await sleep(); + expect(wrapper.findAll('.ant-pagination')).toHaveLength(1); + wrapper.setProps({ pagination: { position: ['invalid', 'invalid'] } }); + await sleep(); + expect(wrapper.findAll('.ant-pagination')).toHaveLength(1); }); }); diff --git a/components/table/__tests__/Table.rowSelection.test.js b/components/table/__tests__/Table.rowSelection.test.js index ac7d39507..b8c8fb449 100644 --- a/components/table/__tests__/Table.rowSelection.test.js +++ b/components/table/__tests__/Table.rowSelection.test.js @@ -4,6 +4,15 @@ import Table from '..'; import { sleep } from '../../../tests/utils'; describe('Table.rowSelection', () => { + const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + + afterEach(() => { + errorSpy.mockReset(); + }); + + afterAll(() => { + errorSpy.mockRestore(); + }); const columns = [ { title: 'Name', @@ -30,13 +39,13 @@ describe('Table.rowSelection', () => { }; } function renderedNames(wrapper) { - return wrapper.findAllComponents({ name: 'TableRow' }).map(row => { + return wrapper.findAllComponents({ name: 'BodyRow' }).map(row => { return row.props().record.name; }); } - function getStore(wrapper) { - return wrapper.vm.$refs.table.store; + function getSelections(wrapper) { + return [...wrapper.vm.table.selectedKeySet].sort(); } it('select by checkbox', async () => { @@ -46,26 +55,17 @@ describe('Table.rowSelection', () => { checkboxAll.element.checked = true; checkboxAll.trigger('change'); await asyncExpect(() => { - expect(getStore(wrapper)).toEqual({ - selectedRowKeys: [0, 1, 2, 3], - selectionDirty: true, - }); + expect(getSelections(wrapper)).toEqual([0, 1, 2, 3]); }); checkboxes[1].element.checked = false; checkboxes[1].trigger('change'); await asyncExpect(() => { - expect(getStore(wrapper)).toEqual({ - selectedRowKeys: [1, 2, 3], - selectionDirty: true, - }); + expect(getSelections(wrapper)).toEqual([1, 2, 3]); }); checkboxes[1].element.checked = true; checkboxes[1].trigger('change'); await asyncExpect(() => { - expect(getStore(wrapper)).toEqual({ - selectedRowKeys: [1, 2, 3, 0], - selectionDirty: true, - }); + expect(getSelections(wrapper)).toEqual([0, 1, 2, 3]); }); }); @@ -77,103 +77,84 @@ describe('Table.rowSelection', () => { radios[0].element.checked = true; radios[0].trigger('change'); await asyncExpect(() => { - expect(getStore(wrapper)).toEqual({ - selectedRowKeys: [0], - selectionDirty: true, - }); + expect(getSelections(wrapper)).toEqual([0]); }); radios[radios.length - 1].element.checked = true; radios[radios.length - 1].trigger('change'); await asyncExpect(() => { - expect(getStore(wrapper)).toEqual({ - selectedRowKeys: [3], - selectionDirty: true, - }); + expect(getSelections(wrapper)).toEqual([3]); }); }); - xit('pass getCheckboxProps to checkbox', async () => { + it('pass getCheckboxProps to checkbox', async () => { const rowSelection = { getCheckboxProps: record => ({ - props: { - disabled: record.name === 'Lucy', - name: record.name, - }, + disabled: record.name === 'Lucy', + name: record.name, }), }; const wrapper = mount(Table, getTableOptions({ rowSelection })); const checkboxes = wrapper.findAll('input'); await sleep(); - expect(checkboxes[1].props.disabled).toBe(false); - expect(checkboxes[1].vnode.data.attrs.name).toEqual(data[0].name); - expect(checkboxes[2].vnode.data.attrs.disabled).toBe(true); - expect(checkboxes[2].vnode.data.attrs.name).toEqual(data[1].name); + expect(checkboxes[1].wrapperElement.disabled).toBe(false); + expect(checkboxes[1].wrapperElement.name).toEqual(data[0].name); + expect(checkboxes[2].wrapperElement.disabled).toBe(true); + expect(checkboxes[2].wrapperElement.name).toEqual(data[1].name); }); - xit('works with pagination', async () => { + it('works with pagination', async () => { const wrapper = mount(Table, getTableOptions({ pagination: { pageSize: 2 } })); - const checkboxAll = wrapper.findAllComponents({ name: 'SelectionCheckboxAll' }); + await sleep(); + const checkboxAll = wrapper.find('input'); + checkboxAll.wrapperElement.checked = true; + checkboxAll.trigger('change'); const pagers = wrapper.findAllComponents({ name: 'Pager' }); - checkboxAll.find('input').element.checked = true; - checkboxAll.find('input').trigger('change'); await asyncExpect(() => { - expect(checkboxAll.vm.$data).toEqual({ checked: true, indeterminate: false }); + expect(wrapper.findComponent({ name: 'ACheckbox' }).props()).toEqual( + expect.objectContaining({ checked: true, indeterminate: false }), + ); }); pagers[1].trigger('click'); await asyncExpect(() => { - expect(checkboxAll.vm.$data).toEqual({ checked: false, indeterminate: false }); + expect(wrapper.findComponent({ name: 'ACheckbox' }).props()).toEqual( + expect.objectContaining({ checked: false, indeterminate: false }), + ); }); pagers[0].trigger('click'); await asyncExpect(() => { - expect(checkboxAll.vm.$data).toEqual({ checked: true, indeterminate: false }); + expect(wrapper.findComponent({ name: 'ACheckbox' }).props()).toEqual( + expect.objectContaining({ checked: true, indeterminate: false }), + ); }); }); // https://github.com/ant-design/ant-design/issues/4020 - xit('handles defaultChecked', async () => { + it('handles defaultChecked', async () => { const rowSelection = { getCheckboxProps: record => { return { - props: { - defaultChecked: record.key === 0, - }, + defaultChecked: record.key === 0, }; }, }; - const wrapper = mount(Table, getTableOptions({ rowSelection })); + mount(Table, getTableOptions({ rowSelection })); - await asyncExpect(() => { - const checkboxs = wrapper.findAll('input'); - expect(checkboxs[1].vnode.data.domProps.checked).toBe(true); - expect(checkboxs.at(2).vnode.data.domProps.checked).toBe(false); - checkboxs.at(2).element.checked = true; - checkboxs.at(2).trigger('change'); - }, 0); - - await asyncExpect(() => { - const checkboxs = wrapper.findAll('input'); - expect(checkboxs[1].vnode.data.domProps.checked).toBe(true); - expect(checkboxs.at(2).vnode.data.domProps.checked).toBe(true); - }, 1000); + expect(errorSpy).toHaveBeenCalledWith( + 'Warning: [ant-design-vue: Table] Do not set `checked` or `defaultChecked` in `getCheckboxProps`. Please use `selectedRowKeys` instead.', + ); }); it('can be controlled', async () => { const wrapper = mount(Table, getTableOptions({ rowSelection: { selectedRowKeys: [0] } })); - expect(getStore(wrapper)).toEqual({ - selectedRowKeys: [0], - selectionDirty: false, - }); + expect(getSelections(wrapper)).toEqual([0]); wrapper.setProps({ rowSelection: { selectedRowKeys: [1] } }); await asyncExpect(() => { - expect(getStore(wrapper)).toEqual({ - selectedRowKeys: [1], - selectionDirty: false, - }); + expect(getSelections(wrapper)).toEqual([1]); }); }); @@ -216,7 +197,7 @@ describe('Table.rowSelection', () => { }); }); - xit('render with default selection correctly', async () => { + it('render with default selection correctly', async () => { const rowSelection = { selections: true, }; @@ -224,7 +205,7 @@ describe('Table.rowSelection', () => { const dropdownWrapper = mount( { render() { - return wrapper.find({ name: 'Trigger' }).vm.getComponent(); + return wrapper.findComponent({ name: 'Trigger' }).vm.getComponent(); }, }, { sync: false }, @@ -232,14 +213,12 @@ describe('Table.rowSelection', () => { await asyncExpect(() => { expect(dropdownWrapper.html()).toMatchSnapshot(); }); - - await asyncExpect(() => {}); }); - xit('click select all selection', () => { - const handleSelectAll = jest.fn(); + it('click select all selection', () => { + const handleChange = jest.fn(); const rowSelection = { - onSelectAll: handleSelectAll, + onChange: handleChange, selections: true, }; const wrapper = mount(Table, getTableOptions({ rowSelection })); @@ -247,17 +226,17 @@ describe('Table.rowSelection', () => { const dropdownWrapper = mount( { render() { - return wrapper.find({ name: 'Trigger' }).vm.getComponent(); + return wrapper.findComponent({ name: 'Trigger' }).vm.getComponent(); }, }, { sync: false }, ); - dropdownWrapper.findAll('.ant-dropdown-menu-item > div')[0].trigger('click'); + dropdownWrapper.findAll('.ant-dropdown-menu-item')[0].trigger('click'); - expect(handleSelectAll).toBeCalledWith(true, data, data); + expect(handleChange.mock.calls[0][0]).toEqual([0, 1, 2, 3]); }); - xit('fires selectInvert event', () => { + it('fires selectInvert event', async () => { const handleSelectInvert = jest.fn(); const rowSelection = { onSelectInvert: handleSelectInvert, @@ -267,25 +246,28 @@ describe('Table.rowSelection', () => { const checkboxes = wrapper.findAll('input'); checkboxes[1].element.checked = true; checkboxes[1].trigger('change'); + await sleep(); const dropdownWrapper = mount( { render() { - return wrapper.find({ name: 'Trigger' }).vm.getComponent(); + return wrapper.findComponent({ name: 'Trigger' }).vm.getComponent(); }, }, { sync: false }, ); - const div = dropdownWrapper.findAll('.ant-dropdown-menu-item > div'); - div.at(div.length - 1).trigger('click'); + const div = dropdownWrapper.findAll('li.ant-dropdown-menu-item'); + div.at(1).trigger('click'); expect(handleSelectInvert).toBeCalledWith([1, 2, 3]); }); - xit('fires selection event', () => { + it('fires selection event', () => { const handleSelectOdd = jest.fn(); const handleSelectEven = jest.fn(); const rowSelection = { selections: [ + Table.SELECTION_ALL, + Table.SELECTION_INVERT, { key: 'odd', text: '奇数项', @@ -303,21 +285,21 @@ describe('Table.rowSelection', () => { const dropdownWrapper = mount( { render() { - return wrapper.find({ name: 'Trigger' }).vm.getComponent(); + return wrapper.findComponent({ name: 'Trigger' }).vm.getComponent(); }, }, { sync: false }, ); expect(dropdownWrapper.findAll('.ant-dropdown-menu-item').length).toBe(4); - dropdownWrapper.findAll('.ant-dropdown-menu-item > div').at(2).trigger('click'); + dropdownWrapper.findAll('.ant-dropdown-menu-item')[2].trigger('click'); expect(handleSelectOdd).toBeCalledWith([0, 1, 2, 3]); - dropdownWrapper.findAll('.ant-dropdown-menu-item > div').at(3).trigger('click'); + dropdownWrapper.findAll('.ant-dropdown-menu-item').at(3).trigger('click'); expect(handleSelectEven).toBeCalledWith([0, 1, 2, 3]); }); - xit('could hide default selection options', () => { + it('could hide default selection options', () => { const rowSelection = { hideDefaultSelections: true, selections: [ @@ -335,7 +317,7 @@ describe('Table.rowSelection', () => { const dropdownWrapper = mount( { render() { - return wrapper.find({ name: 'Trigger' }).vm.getComponent(); + return wrapper.findComponent({ name: 'Trigger' }).vm.getComponent(); }, }, { sync: false }, @@ -343,7 +325,7 @@ describe('Table.rowSelection', () => { expect(dropdownWrapper.findAll('.ant-dropdown-menu-item').length).toBe(2); }); - xit('handle custom selection onSelect correctly when hide default selection options', () => { + it('handle custom selection onSelect correctly when hide default selection options', () => { const handleSelectOdd = jest.fn(); const handleSelectEven = jest.fn(); const rowSelection = { @@ -366,25 +348,25 @@ describe('Table.rowSelection', () => { const dropdownWrapper = mount( { render() { - return wrapper.find({ name: 'Trigger' }).vm.getComponent(); + return wrapper.findComponent({ name: 'Trigger' }).vm.getComponent(); }, }, { sync: false }, ); expect(dropdownWrapper.findAll('.ant-dropdown-menu-item').length).toBe(2); - dropdownWrapper.findAll('.ant-dropdown-menu-item > div')[0].trigger('click'); + dropdownWrapper.findAll('.ant-dropdown-menu-item')[0].trigger('click'); expect(handleSelectOdd).toBeCalledWith([0, 1, 2, 3]); - dropdownWrapper.findAll('.ant-dropdown-menu-item > div')[1].trigger('click'); + dropdownWrapper.findAll('.ant-dropdown-menu-item')[1].trigger('click'); expect(handleSelectEven).toBeCalledWith([0, 1, 2, 3]); }); // https:// github.com/ant-design/ant-design/issues/4245 - xit('handles disabled checkbox correctly when dataSource changes', async () => { + it('handles disabled checkbox correctly when dataSource changes', async () => { const rowSelection = { getCheckboxProps: record => { - return { props: { disabled: record.disabled } }; + return { disabled: record.disabled }; }, }; const wrapper = mount(Table, getTableOptions({ rowSelection })); @@ -396,14 +378,14 @@ describe('Table.rowSelection', () => { wrapper.setProps({ dataSource: newData }); }); await asyncExpect(() => { - wrapper.findAll('input').wrappers.forEach(checkbox => { - expect(checkbox.vnode.data.attrs.disabled).toBe(true); + wrapper.findAll('input').forEach(checkbox => { + expect(checkbox.wrapperElement.disabled).toBe(true); }); }); }); // https://github.com/ant-design/ant-design/issues/4779 - xit('should not switch pagination when select record', async () => { + it('should not switch pagination when select record', async () => { const newData = []; for (let i = 0; i < 20; i += 1) { newData.push({ @@ -418,7 +400,7 @@ describe('Table.rowSelection', () => { dataSource: newData, }), ); - const pager = wrapper.findAll({ name: 'Pager' }); + const pager = wrapper.findAllComponents({ name: 'Pager' }); pager.at(pager.length - 1).trigger('click'); // switch to second page wrapper.findAll('input')[0].element.checked = true; wrapper.findAll('input')[0].trigger('change'); @@ -460,7 +442,7 @@ describe('Table.rowSelection', () => { }); // https://github.com/ant-design/ant-design/issues/10629 - xit('should keep all checked state when remove item from dataSource', async () => { + it('should keep all checked state when remove item from dataSource', async () => { const wrapper = mount(Table, { props: { columns, @@ -510,7 +492,7 @@ describe('Table.rowSelection', () => { sync: false, }); await asyncExpect(() => { - expect(wrapper.findAll('thead tr div')[0].text()).toBe('多选'); + expect(wrapper.findAll('thead tr th')[0].text()).toBe('多选'); }); await asyncExpect(() => { wrapper.setProps({ @@ -521,12 +503,12 @@ describe('Table.rowSelection', () => { }); }); await asyncExpect(() => { - expect(wrapper.findAll('thead tr div')[0].text()).toBe('单选'); + expect(wrapper.findAll('thead tr th')[0].text()).toBe('单选'); }); }); // https://github.com/ant-design/ant-design/issues/11384 - xit('should keep item even if in filter', async () => { + it('should keep item even if in filter', async () => { const filterColumns = [ { title: 'Name', @@ -563,11 +545,21 @@ describe('Table.rowSelection', () => { const dropdownWrapper = mount( { render() { - return wrapper.find({ name: 'Trigger' }).vm.getComponent(); + return wrapper.findComponent({ name: 'Trigger' }).vm.getComponent(); }, }, { sync: false }, ); + await sleep(); + function clickFilter(indexList) { + indexList.forEach(index => { + dropdownWrapper + .findAll('.ant-dropdown-menu-item .ant-checkbox-wrapper') + .at(index) + .trigger('click'); + }); + dropdownWrapper.find('.ant-table-filter-dropdown-btns .ant-btn-primary').trigger('click'); + } function clickItem() { wrapper.findAll( @@ -577,10 +569,7 @@ describe('Table.rowSelection', () => { } // Check Jack - dropdownWrapper.findAll('.ant-dropdown-menu-item .ant-checkbox-wrapper')[0].trigger('click'); - dropdownWrapper - .find('.ant-table-filter-dropdown-btns .ant-table-filter-dropdown-link.confirm') - .trigger('click'); + clickFilter([0]); await asyncExpect(() => { expect(wrapper.findAll('tbody tr').length).toBe(1); }); @@ -592,19 +581,9 @@ describe('Table.rowSelection', () => { expect(onChange.mock.calls[0][1].length).toBe(1); }); - await asyncExpect(() => { - dropdownWrapper.findAll('.ant-dropdown-menu-item .ant-checkbox-wrapper')[0].trigger('click'); - }); + // Check Lucy + clickFilter([0, 1]); - await asyncExpect(() => { - // Check Lucy - dropdownWrapper.findAll('.ant-dropdown-menu-item .ant-checkbox-wrapper')[1].trigger('click'); - }); - await asyncExpect(() => { - dropdownWrapper - .find('.ant-table-filter-dropdown-btns .ant-table-filter-dropdown-link.confirm') - .trigger('click'); - }); await asyncExpect(() => { expect(wrapper.findAll('tbody tr').length).toBe(1); }); @@ -617,7 +596,7 @@ describe('Table.rowSelection', () => { }); }); - xit('render correctly when set childrenColumnName', async () => { + it('render correctly when set childrenColumnName', async () => { const newDatas = [ { key: 1, @@ -652,16 +631,18 @@ describe('Table.rowSelection', () => { }); const checkboxes = wrapper.findAll('input'); - const checkboxAll = wrapper.findAllComponents({ name: 'SelectionCheckboxAll' }); - checkboxes[1].element.checked = true; checkboxes[1].trigger('change'); - expect(checkboxAll.$data).toEqual({ indeterminate: true, checked: false }); - + await sleep(); + expect(wrapper.findComponent({ name: 'ACheckbox' }).props()).toEqual( + expect.objectContaining({ checked: false, indeterminate: true }), + ); checkboxes[2].element.checked = true; checkboxes[2].trigger('change'); await asyncExpect(() => { - expect(checkboxAll.vm.$data).toEqual({ indeterminate: false, checked: true }); + expect(wrapper.findComponent({ name: 'ACheckbox' }).props()).toEqual( + expect.objectContaining({ checked: true, indeterminate: false }), + ); }); }); }); diff --git a/components/table/__tests__/Table.sorter.test.js b/components/table/__tests__/Table.sorter.test.js index e9de43e88..4cb23bc7d 100644 --- a/components/table/__tests__/Table.sorter.test.js +++ b/components/table/__tests__/Table.sorter.test.js @@ -9,6 +9,7 @@ describe('Table.sorter', () => { const column = { title: 'Name', dataIndex: 'name', + key: 'name', sorter: sorterFn, }; @@ -38,7 +39,7 @@ describe('Table.sorter', () => { } function renderedNames(wrapper) { - return wrapper.findAllComponents({ name: 'TableRow' }).wrappers.map(row => { + return wrapper.findAllComponents({ name: 'BodyRow' }).map(row => { return row.props().record.name; }); } @@ -51,7 +52,7 @@ describe('Table.sorter', () => { }); }); - xit('default sort order ascend', done => { + it('default sort order ascend', done => { const wrapper = mount( Table, getTableOptions( @@ -67,7 +68,7 @@ describe('Table.sorter', () => { }); }); - xit('default sort order descend', done => { + it('default sort order descend', done => { const wrapper = mount( Table, getTableOptions( @@ -104,7 +105,7 @@ describe('Table.sorter', () => { }); }); - xit('can be controlled by sortOrder', done => { + it('can be controlled by sortOrder', done => { const wrapper = mount( Table, getTableOptions({ @@ -148,7 +149,7 @@ describe('Table.sorter', () => { }); }); - xit('works with grouping columns in controlled mode', done => { + it('works with grouping columns in controlled mode', done => { const columns = [ { title: 'group', diff --git a/components/table/__tests__/Table.test.js b/components/table/__tests__/Table.test.js index 68596f286..b178eea25 100644 --- a/components/table/__tests__/Table.test.js +++ b/components/table/__tests__/Table.test.js @@ -1,4 +1,4 @@ -import { shallowMount as shallow, mount } from '@vue/test-utils'; +import { mount } from '@vue/test-utils'; import Table from '..'; import * as Vue from 'vue'; import mountTest from '../../../tests/shared/mountTest'; @@ -55,7 +55,7 @@ describe('Table', () => { dataIndex: 'name', }, ]; - const wrapper = shallow(Table, { + const wrapper = mount(Table, { props: { columns, }, @@ -70,7 +70,7 @@ describe('Table', () => { ]; wrapper.setProps({ columns: newColumns }); await sleep(); - expect(wrapper.vm.columns).toStrictEqual(newColumns); + expect(wrapper.find('th').text()).toEqual('Title'); }); it('loading with Spin', async () => { diff --git a/components/table/__tests__/__snapshots__/Table.rowSelection.test.js.snap b/components/table/__tests__/__snapshots__/Table.rowSelection.test.js.snap index 9f6ec5741..e08d77e8e 100644 --- a/components/table/__tests__/__snapshots__/Table.rowSelection.test.js.snap +++ b/components/table/__tests__/__snapshots__/Table.rowSelection.test.js.snap @@ -95,15 +95,27 @@ exports[`Table.rowSelection fix selection column on the left 1`] = ` exports[`Table.rowSelection render with default selection correctly 1`] = `
- `; diff --git a/components/table/__tests__/__snapshots__/demo.test.js.snap b/components/table/__tests__/__snapshots__/demo.test.js.snap index d4ee17997..79479c11a 100644 --- a/components/table/__tests__/__snapshots__/demo.test.js.snap +++ b/components/table/__tests__/__snapshots__/demo.test.js.snap @@ -1093,24 +1093,12 @@ exports[`renders ./components/table/demo/fixed-columns.vue correctly 1`] = `
-
+
-
- - - - - - - - - - - - - - +
+
+ + +
@@ -1148,6 +1136,24 @@ exports[`renders ./components/table/demo/fixed-columns.vue correctly 1`] = `
+
+
+ + + + + + + + + + + + + +
+ +
@@ -4365,7 +4373,7 @@ exports[`renders ./components/table/demo/summary.vue correctly 1`] = `
-
+
diff --git a/components/table/__tests__/__snapshots__/empty.test.js.snap b/components/table/__tests__/__snapshots__/empty.test.js.snap index 408521e0b..851d08f9e 100644 --- a/components/table/__tests__/__snapshots__/empty.test.js.snap +++ b/components/table/__tests__/__snapshots__/empty.test.js.snap @@ -43,8 +43,7 @@ exports[`Table renders empty table 1`] = ` - - + No data @@ -102,8 +101,7 @@ exports[`Table renders empty table with custom emptyText 1`] = ` - - + custom empty text @@ -182,8 +180,7 @@ exports[`Table renders empty table with fixed columns 1`] = ` - - + No data @@ -245,8 +242,7 @@ exports[`Table renders empty table without emptyText when loading 1`] = ` - - + No data diff --git a/components/transfer/__tests__/__snapshots__/demo.test.js.snap b/components/transfer/__tests__/__snapshots__/demo.test.js.snap index 34a9cd8f1..e6071c99c 100644 --- a/components/transfer/__tests__/__snapshots__/demo.test.js.snap +++ b/components/transfer/__tests__/__snapshots__/demo.test.js.snap @@ -421,340 +421,327 @@ exports[`renders ./components/transfer/demo/table-transfer.vue correctly 1`] = `
-
+
-
- -
- +
+
+
- - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
- - - -
Name -
- -
Description -
- -
- - - - - content1 - - - description of content1 -
- - - - - content2 - - - description of content2 -
- - - - - content4 - - - description of content4 -
- - - - - content5 - - - description of content5 -
- - - - - content7 - - - description of content7 -
- - - - - content8 - - - description of content8 -
- - - - - content10 - - - description of content10 -
- - - - - content11 - - - description of content11 -
- - - - - content13 - - - description of content13 -
- - - - - content14 - - - description of content14 -
-
- - -
-
-
    - -
  • -
  • 1
  • -
  • 2
  • -
  • - -
-
-
-
-
-
- - -
-
-
- - 6 items -
-
- -
-
-
- -
-
- -
- -
- - - - - - - - + + + + + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+ Name + + Description +
Name -
- -
+
+ + + content1 + + description of content1 +
+ + + content2 + + description of content2 +
+ + + content4 + + description of content4 +
+ + + content5 + + description of content5 +
+ + + content7 + + description of content7 +
+ + + content8 + + description of content8 +
+ + + content10 + + description of content10 +
+ + + content11 + + description of content11 +
+ + + content13 + + description of content13 +
+ + + content14 + + description of content14 +
+
+
- - - +
+
    - content3 - - - - +
  • +
  • 1
  • +
  • 2
  • +
  • - - - - - content6 - - - - - - - - - - content9 - - - - - - - - - - content12 - - - - - - - - - - content15 - - - - - - - - - - content18 - - - - +
+
+
- -
-
    - -
  • -
  • 1
  • -
  • - -
+
- +
+
+
+ + 6 items +
+
+ +
+
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+
+ Name +
+ + + content3 +
+ + + content6 +
+ + + content9 +
+ + + content12 +
+ + + content15 +
+ + + content18 +
+
+
+ +
+
    + +
  • +
  • 1
  • +
  • + +
+
+
+
+
+
+ +
+ - - - - - `; exports[`renders ./components/transfer/demo/tree-transfer.vue correctly 1`] = ` diff --git a/components/vc-table/Table.tsx b/components/vc-table/Table.tsx index d7b906a69..a0caf98e3 100644 --- a/components/vc-table/Table.tsx +++ b/components/vc-table/Table.tsx @@ -562,7 +562,7 @@ export default defineComponent({ getRowKey={getRowKey.value} customRow={props.customRow} childrenColumnName={mergedChildrenColumnName.value} - v-slots={{ emptyText: emptyNode }} + v-slots={{ emptyNode }} /> ); diff --git a/tests/__snapshots__/index.test.js.snap b/tests/__snapshots__/index.test.js.snap index 76e2d065e..4866b7a64 100644 --- a/tests/__snapshots__/index.test.js.snap +++ b/tests/__snapshots__/index.test.js.snap @@ -106,6 +106,9 @@ Array [ "Table", "TableColumn", "TableColumnGroup", + "TableSummary", + "TableSummaryRow", + "TableSummaryCell", "Transfer", "Tree", "TreeNode",