//go:build browser package thintest import ( "testing" "amadan.net/oficina/equipo/internal/wire" ) // TestBrowserShipsButtons: on the project page a tap on "Yes, it ships" // applies at once with no reload: the button shows pressed, the sentence // changes, "Saved" shows with Undo, and Undo puts back the unanswered // state. Switching to the other answer and back works the same, and the // Change form, opened with an edit in it, keeps the edit and saves over // the new revision. func TestBrowserShipsButtons(t *testing.T) { r := newToolRigAt(t, wire.ProtocolInjectionDefences) project := r.project() p := openInner(t, r.inst.URL, r.inst.Cookie(), 1280, 900, false, "light", "reduce") defer p.stop() p.open("/projects/" + project) p.wait(`document.querySelector('[data-merge-ships] [data-merge-ships-choice]')`, "the ship buttons") choice := func(v string) string { return `document.querySelector('[data-merge-ships-choice="` + v + `"]')` } 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") p.check(`document.querySelector('[data-merge-sentences]').textContent.includes("I don't know yet whether merging")`, "the unanswered sentence") // An edit waiting in the Change form survives the taps. 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") p.check(`(()=>{`+choice("yes")+`.click();return true})()`, "tap yes") p.wait(choice("yes")+`.getAttribute('aria-pressed')==='true' && `+choice("no")+`.getAttribute('aria-pressed')==='false'`, "yes pressed") 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") p.check(`document.querySelector('[data-merge-sentences]').textContent.includes('Merging to main ships to users')`, "the sentence did not change") if got, _ := r.client.MergePolicy(r.ctx, project); got.MainShips != "yes" { t.Fatalf("after tap: %+v", got) } p.stayed("tap") p.fits("the ship buttons") p.shot("ships-buttons-1280") p.check(`(()=>{document.querySelector('[data-merge-ships-undo]').click();return true})()`, "Undo") 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") p.check(`document.querySelector('[data-merge-sentences]').textContent.includes("I don't know yet whether merging")`, "the unanswered sentence after Undo") if got, _ := r.client.MergePolicy(r.ctx, project); got.MainShips != "unknown" { t.Fatalf("after Undo: %+v", got) } // No, then yes, then Undo: back to no. p.check(`(()=>{`+choice("no")+`.click();return true})()`, "tap no") p.wait(choice("no")+`.getAttribute('aria-pressed')==='true' && !document.querySelector('[data-merge-ships]').hasAttribute('aria-busy')`, "no pressed") p.check(`(()=>{`+choice("yes")+`.click();return true})()`, "tap yes") p.wait(choice("yes")+`.getAttribute('aria-pressed')==='true' && !!document.querySelector('[data-merge-ships-undo]')`, "yes pressed") p.check(`(()=>{document.querySelector('[data-merge-ships-undo]').click();return true})()`, "Undo") p.wait(choice("no")+`.getAttribute('aria-pressed')==='true' && !document.querySelector('[data-merge-ships-undo]')`, "back to no") if got, _ := r.client.MergePolicy(r.ctx, project); got.MainShips != "no" { t.Fatalf("after the second Undo: %+v", got) } p.stayed("taps and Undo") // The form kept its edit and saves over the moved revision. 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") p.check(`(()=>{document.querySelector('[data-merge-policy-save]').click();return true})()`, "Save") p.wait(`document.querySelector('[data-merge-words]') && document.querySelector('[data-merge-words]').textContent.includes('only small ones')`, "the form saved") if got, _ := r.client.MergePolicy(r.ctx, project); got.MainShips != "no" || got.Words != "only small ones" { t.Fatalf("after Save: %+v", got) } }