/* LICENSE BEGIN This file is part of the SixtyFPS Project -- https://sixtyfps.io Copyright (c) 2021 Olivier Goffart Copyright (c) 2021 Simon Hausmann SPDX-License-Identifier: GPL-3.0-only This file is also available under commercial licensing terms. Please contact info@sixtyfps.io for more information. LICENSE END */ TestCase := Rectangle { width: 300phx; height: 300phx; property<[{name: string, account: string, score: float}]> model: [ { name: "Olivier", account: "ogoffart", score: 456, }, { name: "Simon", account: "tronical", score: 789, } ]; property clicked_score; for person[i] in model: TouchArea { x: i*10phx; width: 10phx; height: 10phx; property score: person.score; clicked => { person.score += 1; person.score = person.score + 1; person.score += 1; clicked_score = score; } } } /* ```rust use sixtyfps::Model; let instance = TestCase::new(); sixtyfps::testing::send_mouse_click(&instance, 15., 5.); assert_eq!(instance.get_clicked_score(), 792); type ModelData = (sixtyfps::SharedString, sixtyfps::SharedString, f32); let another_model = std::rc::Rc::new(sixtyfps::VecModel::::from( vec![ ("a1".into(), "hello".into(), 111.), ("a2".into(), "cruel".into(), 222.), ("a3".into(), "world".into(), 333.), ])); instance.set_model(sixtyfps::ModelHandle::new(another_model.clone())); sixtyfps::testing::send_mouse_click(&instance, 25., 5.); assert_eq!(instance.get_clicked_score(), 336); assert_eq!(another_model.row_data(2).2, 336.); sixtyfps::testing::send_mouse_click(&instance, 25., 5.); assert_eq!(instance.get_clicked_score(), 339); assert_eq!(another_model.row_data(2).2, 339.); assert_eq!(another_model.row_data(2).1, sixtyfps::SharedString::from("world")); ``` ```cpp auto handle = TestCase::create(); const TestCase &instance = *handle; sixtyfps::testing::send_mouse_click(&instance, 15., 5.); assert_eq(instance.get_clicked_score(), 792); using ModelData = std::tuple; std::vector array; array.push_back(ModelData{"a1", "hello", 111.}); array.push_back(ModelData{"a2", "cruel", 222.}); array.push_back(ModelData{"a3", "world", 333.}); auto another_model = std::make_shared>(std::move(array)); instance.set_model(another_model); sixtyfps::testing::send_mouse_click(&instance, 25., 5.); assert_eq(instance.get_clicked_score(), 336); assert_eq(std::get<2>(another_model->row_data(2)), 336.); sixtyfps::testing::send_mouse_click(&instance, 25., 5.); assert_eq(instance.get_clicked_score(), 339); assert_eq(std::get<2>(another_model->row_data(2)), 339.); assert_eq(std::get<1>(another_model->row_data(2)), "world"); ``` ```js var instance = new sixtyfps.TestCase({}); instance.send_mouse_click(15., 5.); assert.equal(instance.clicked_score, 792); let another_model = new sixtyfpslib.ArrayModel([ {account: "a1", name: "hello", score: 111.}, {account: "a2", name: "cruel", score: 222.}, {account: "a3", name: "world", score: 333.}, ]); instance.model = another_model; instance.send_mouse_click(25., 5.); assert.equal(instance.clicked_score, 336); assert.equal(another_model.rowData(2).score, 336.); instance.send_mouse_click(25., 5.); assert.equal(instance.clicked_score, 339); assert.equal(another_model.rowData(2).score, 339.); assert.equal(another_model.rowData(2).name, "world"); ``` */