oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser
2
3package thintest
4
5import (
6 "testing"
7
8 "amadan.net/oficina/equipo/internal/wire"
9)
10
11// TestBrowserShipsButtons: on the project page a tap on "Yes, it ships"
12// applies at once with no reload: the button shows pressed, the sentence
13// changes, "Saved" shows with Undo, and Undo puts back the unanswered
14// state. Switching to the other answer and back works the same, and the
15// Change form, opened with an edit in it, keeps the edit and saves over
16// the new revision.
17func TestBrowserShipsButtons(t *testing.T) {
18 r := newToolRigAt(t, wire.ProtocolInjectionDefences)
19 project := r.project()
20 p := openInner(t, r.inst.URL, r.inst.Cookie(), 1280, 900, false, "light", "reduce")
21 defer p.stop()
22 p.open("/projects/" + project)
23 p.wait(`document.querySelector('[data-merge-ships] [data-merge-ships-choice]')`, "the ship buttons")
24 choice := func(v string) string { return `document.querySelector('[data-merge-ships-choice="` + v + `"]')` }
25 p.check(`document.querySelectorAll('[data-merge-ships-choice]').length===2 && !document.querySelector('select[name=main_ships]') && !document.querySelector('[data-merge-ships] [aria-pressed="true"]')`, "two unpressed buttons and no select")
26 p.check(`document.querySelector('[data-merge-sentences]').textContent.includes("I don't know yet whether merging")`, "the unanswered sentence")
27 // An edit waiting in the Change form survives the taps.
28 p.check(`(()=>{document.querySelector('[data-merge-policy-edit]').open=true;document.querySelector('[data-merge-policy-form] [name=words]').value='only small ones';return true})()`, "type in the form")
29
30 p.check(`(()=>{`+choice("yes")+`.click();return true})()`, "tap yes")
31 p.wait(choice("yes")+`.getAttribute('aria-pressed')==='true' && `+choice("no")+`.getAttribute('aria-pressed')==='false'`, "yes pressed")
32 p.wait(`!!document.querySelector('[data-merge-ships-done] [equipo-saved-tick][data-shown]') && !!document.querySelector('[data-merge-ships-done] [data-merge-ships-undo]')`, "Saved and Undo")
33 p.check(`document.querySelector('[data-merge-sentences]').textContent.includes('Merging to main ships to users')`, "the sentence did not change")
34 if got, _ := r.client.MergePolicy(r.ctx, project); got.MainShips != "yes" {
35 t.Fatalf("after tap: %+v", got)
36 }
37 p.stayed("tap")
38 p.fits("the ship buttons")
39 p.shot("ships-buttons-1280")
40
41 p.check(`(()=>{document.querySelector('[data-merge-ships-undo]').click();return true})()`, "Undo")
42 p.wait(`!document.querySelector('[data-merge-ships] [aria-pressed="true"]') && !document.querySelector('[data-merge-ships-undo]') && !!document.querySelector('[data-merge-ships-done] [equipo-saved-tick]')`, "back to unanswered, Saved, no second Undo")
43 p.check(`document.querySelector('[data-merge-sentences]').textContent.includes("I don't know yet whether merging")`, "the unanswered sentence after Undo")
44 if got, _ := r.client.MergePolicy(r.ctx, project); got.MainShips != "unknown" {
45 t.Fatalf("after Undo: %+v", got)
46 }
47
48 // No, then yes, then Undo: back to no.
49 p.check(`(()=>{`+choice("no")+`.click();return true})()`, "tap no")
50 p.wait(choice("no")+`.getAttribute('aria-pressed')==='true' && !document.querySelector('[data-merge-ships]').hasAttribute('aria-busy')`, "no pressed")
51 p.check(`(()=>{`+choice("yes")+`.click();return true})()`, "tap yes")
52 p.wait(choice("yes")+`.getAttribute('aria-pressed')==='true' && !!document.querySelector('[data-merge-ships-undo]')`, "yes pressed")
53 p.check(`(()=>{document.querySelector('[data-merge-ships-undo]').click();return true})()`, "Undo")
54 p.wait(choice("no")+`.getAttribute('aria-pressed')==='true' && !document.querySelector('[data-merge-ships-undo]')`, "back to no")
55 if got, _ := r.client.MergePolicy(r.ctx, project); got.MainShips != "no" {
56 t.Fatalf("after the second Undo: %+v", got)
57 }
58 p.stayed("taps and Undo")
59
60 // The form kept its edit and saves over the moved revision.
61 p.check(`document.querySelector('[data-merge-policy-edit]').open && document.querySelector('[data-merge-policy-form] [name=words]').value==='only small ones'`, "the form lost its edit")
62 p.check(`(()=>{document.querySelector('[data-merge-policy-save]').click();return true})()`, "Save")
63 p.wait(`document.querySelector('[data-merge-words]') && document.querySelector('[data-merge-words]').textContent.includes('only small ones')`, "the form saved")
64 if got, _ := r.client.MergePolicy(r.ctx, project); got.MainShips != "no" || got.Words != "only small ones" {
65 t.Fatalf("after Save: %+v", got)
66 }
67}
68