| 1 | //go:build browser |
| 2 | |
| 3 | // The editor's chrome against the suite's: the header is estilo's stacked |
| 4 | // bar, "Saved" does not stay on screen, and the strip's ⋮ has no outline. |
| 5 | package slidestest |
| 6 | |
| 7 | import ( |
| 8 | "testing" |
| 9 | "time" |
| 10 | |
| 11 | "github.com/chromedp/chromedp" |
| 12 | "github.com/chromedp/chromedp/kb" |
| 13 | ) |
| 14 | |
| 15 | func TestEditorHeaderIsTheSuites(t *testing.T) { |
| 16 | te := openTidyEditor(t, 3, 1440, 900) |
| 17 | var got string |
| 18 | te.rig.Run(evalInto(&got, `(() => { |
| 19 | const q = s => document.querySelector(s), out = [] |
| 20 | const want = (name, have, is) => { if (have !== is) out.push(name + ' is ' + have + ', want ' + is) } |
| 21 | want('the bar', q('[slides-head]').getBoundingClientRect().height, 56) |
| 22 | want('the title', getComputedStyle(q('[slides-head-title]')).fontSize, '16px') |
| 23 | want('a menu', getComputedStyle(q('[estilo-menubar-title]')).fontSize, '13px') |
| 24 | want('the icon', q('[slides-head-brand] img').getBoundingClientRect().width, 32) |
| 25 | want('the history pill', q('[slides-history]').getBoundingClientRect().height, 28) |
| 26 | want('the history outline', getComputedStyle(q('[slides-history]')).outlineStyle, 'none') |
| 27 | return out.join('; ') |
| 28 | })()`)) |
| 29 | if got != "" { |
| 30 | t.Error(got) |
| 31 | } |
| 32 | for _, width := range []int64{390, 320} { |
| 33 | te.size(width, 800) |
| 34 | var over float64 |
| 35 | te.rig.Run(chromedp.Sleep(200*time.Millisecond), evalInto(&over, `document.documentElement.scrollWidth - innerWidth`)) |
| 36 | if over > 0 { |
| 37 | t.Errorf("at %dpx the page is %vpx wider than the window", width, over) |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func TestEditorSavedFadesAfterASave(t *testing.T) { |
| 43 | te := openTidyEditor(t, 3, 1440, 900) |
| 44 | const opacity = `getComputedStyle(document.querySelector('[estilo-save-status]')).opacity` |
| 45 | var rest string |
| 46 | te.rig.Run(evalInto(&rest, opacity)) |
| 47 | if rest != "0" { |
| 48 | t.Errorf("a page that has just opened shows its save line: opacity %s", rest) |
| 49 | } |
| 50 | te.rig.Run( |
| 51 | chromedp.Evaluate[chromedp.Void](`(() => { |
| 52 | const i = document.querySelector('[slides-head-title]') |
| 53 | i.value = 'Renamed' |
| 54 | i.dispatchEvent(new Event('change', { bubbles: true })) |
| 55 | })()`), |
| 56 | waitFor(`document.querySelector('[estilo-save-status]').dataset.state === 'saved' && `+opacity+` === '1'`), |
| 57 | waitFor(opacity+` === '0'`), |
| 58 | ) |
| 59 | } |
| 60 | |
| 61 | // Escape in the title goes back to the deck's current title, not the one |
| 62 | // the page opened with: estilo's bar restores the field's default value. |
| 63 | func TestEditorTitleEscapeKeepsTheLastRename(t *testing.T) { |
| 64 | te := openTidyEditor(t, 3, 1440, 900) |
| 65 | const field = `document.querySelector('[slides-head-title]')` |
| 66 | te.rig.Run( |
| 67 | chromedp.Evaluate[chromedp.Void](field+`.select()`), |
| 68 | chromedp.SendKeys(chromedp.CSS(`[slides-head-title]`), "Second title"+kb.Enter), |
| 69 | waitFor(`document.title.includes('Second title') && document.querySelector('[estilo-save-status]').dataset.state === 'saved'`), |
| 70 | chromedp.Evaluate[chromedp.Void](field+`.select()`), |
| 71 | chromedp.SendKeys(chromedp.CSS(`[slides-head-title]`), "Abandoned"+kb.Escape), |
| 72 | waitFor(field+`.value === 'Second title' && document.activeElement !== `+field), |
| 73 | chromedp.Sleep(500*time.Millisecond), |
| 74 | waitFor(`document.querySelector('[estilo-save-status]').dataset.state === 'saved'`), |
| 75 | chromedp.Reload(), |
| 76 | chromedp.WaitVisible(chromedp.CSS(`[slides-editor]`)), |
| 77 | waitFor(editorBound), |
| 78 | waitFor(field+`.value === 'Second title'`), |
| 79 | ) |
| 80 | } |
| 81 | |
| 82 | func TestEditorStripMenuHasNoOutline(t *testing.T) { |
| 83 | te := openTidyEditor(t, 3, 1440, 900) |
| 84 | var got string |
| 85 | te.rig.Run(evalInto(&got, `(() => { |
| 86 | const s = getComputedStyle(document.querySelector('[slides-strip-item] [slides-strip-menu] > summary')) |
| 87 | return s.borderTopColor + ' ' + s.width |
| 88 | })()`)) |
| 89 | if got != "rgba(0, 0, 0, 0) 24px" { |
| 90 | t.Errorf("the strip's menu button: %s", got) |
| 91 | } |
| 92 | } |
| 93 | |